Recently we had the task of setting the NTP servers on the majority of our internal Linux servers. This wouldn’t be required if they hadn’t been behind a firewall restricting their internet access.
We had an internal time server already set up serving all of our windows machines but Linux is fairly new to the company and it wasn’t part of the build yet, so we had to set it. Here is how we achieved it.
This was done on Ubuntu 18.04
Step 1: Check & Set the timezone
# timedatectl status
You should see a printout similar to the below
This is wrong for me as I am UK based, so next we can set the timezone with the following
# timedatectl set-timezone Europe/London
To find the correct timezone you can list all options out using
# timedatectl list-timezones
Which is quite a long list so you can grep it to your continent
# timedatectl list-timezones | grep Europe
which should be a more manageable list! Now the timezone is set we can move on to the next stage which is syncing the time with an NTP server
Step 2: Set the NTP server
I did this without using any additional packages and just using what is available in systemd, you need to edit the timesyncd.conf file as below
# sudo vi /etc/systemd/timesyncd.conf
It will look something like this:
I am only really interested in the NTP parameter so I set that to be the NTP server we want, for this example we will just use ubuntu’s public timeserver, after uncommenting the NTP field and filling it with our NTP address (you can use domain name or IP address both work) it will look something like this
now we just have to set timesync to on and restart the services using the following commands
# timedatectl set-ntp on
# sudo systemctl restart systemd-timedated.service
# sudo systemctl restart systemd-timesyncd.service
Your server should now be set to the correct timezone and time pulled from the specified NTP server. Like so: