In this post I will demonstrate the required steps that needs to take place in order to configure an Ubuntu server 18.04 machine to synchronized itself with a particular NTP server.
I assume the following:
- You have root access to your Ubuntu machine
- You know in advance the NTP server host name and/or IP address.
- The two machines (Ubuntu server and NTP server) are network reachable.
- Install sntp on the Ubuntu server
Run the command:
In case no output is displayed you need to install the sntp application using the command:
- Disable the timedatectl
By default, Ubuntu 18.04 machines are set to have their timedatectl daemon up and running and used as the “ntp service” of the system. You can check it by running the command:
As you can see in the sample output above, the systemd-timesyncd.service active is yes –> so here, currently, the “ntp” service is the timedatectl. In order to disable that, run the following command:
Here you can see that the systemd-timesyncd.service active: no –> it was disabled correctly.
- Start the ntpd service
Check if it is already up and if it is not use the second command in the following two commands:
- Install the ntpdate utility
This utility will be used to “verify” the proper settings for the ntpd service. It can be installed using the command:
- Check synchronization with the NTP server
Use the ntpdate utility to get the current “diff” between the Ubuntu machine (NTP client) time and the NTP server time. Assuming your NTP server name is my.org.ntp.server, run the following command:
In this case the difference is 8776 seconds — allot.
- Configure the NTP server in the Ubuntu machine
Configure the my.org.ntp.server as the “desired” NTP server in the /etc/ntp.conf file by appending as the last line in the file the following line:
server NTP_SERVER_NAME prefer iburst, which in this case it will be:
server my.org.ntp.server prefer iburst
- Restart the ntp service
- Check the time diff again
Run the same command as in the 7th step –> now the time difference should be very small.
The picture: Avenida 9 de Julio, Buenos Aires, Argentina.