How to setup NTP time synchronisation server on Ubuntu.
Posted in "News"Ubuntu NTP time synchronisation
Note: Although the below guide is still usable, you should be aware that since Ubuntu 18.04LTS, NTP has been replaced by Chrony instead. More on this here: https://ubuntu.com/server/docs/network-ntp
NTP is a TCP/IP protocol for synchronising time over a network. Basically a client requests the current time from a server, and uses it to set its own clock.
By default Ubuntu comes with ntpdate (since Ubuntu 16.04 this is timedatctl), which is a ntp client that runs on boot time to synchronise the machines clock with the Ubuntu NTP server. Normally this will do fine for most of us. However a clock is likely to drift between boot times and for some applications it would be better to always have the correct time in sync.
I needed this feature @ my work since our maintenance department server is connected to the PLC to get the latest alarm logs for our technicians. So here time was critical for the logging, if the time would be able to drift, the logs would not have been synchronous between the server and the PLC!
How do we accomplish this? First we need to install ntpd to the machine that you want to be synchronised, then you setup some time servers to synchronise with. Follow the instructions below.
1. Install NTP.
Open a terminal and install ntp with this command:
sudo apt install ntp
2. Configuring NTP.
In the terminal screen issue this command which will open the config file in nano:
sudo nano /etc/ntp.conf
Go to the line that says "# You do need to talk to an NTP server or two (or three)." Here you will see that the ubuntu ntp server is set as standard.
you can add your own time-servers here to synchronise with, "http://www.pool.ntp.org/zone/europe" or "http://www.pool.ntp.org/zone/north-america" lists good servers to start with! I have commented out the Ubuntu server in this example:
#server ntp.ubuntu.com server server 0.europe.pool.ntp.org server 1.europe.pool.ntp.org server 2.europe.pool.ntp.org server 3.europe.pool.ntp.org
At work I have used the NTP servers given by our network administrator. After configuring you need to restart the ntp service to be able to start the synchronisation with the servers you have given. Use this command to restart the NTP service:
sudo systemctl restart ntp.service
You can check if the service is running with this command:
sudo systemctl status ntp.service
The NTP service should be synchronising right now.
3. Check if NTP is synchronising.
You can check if the NTP service is synchronising with this command: