NTP (Network Time Protocol) is a protocol that synchronizes your system’s time with online NTP servers to an accuracy of just a few milliseconds. NTP listens on UDP port 123. In this article, we are going to see how you can synchronize time using NTP server in Ubuntu 18.04 and same should work on ubuntu 16.04 as well.
Both system time and hardware time can drift apart due to small inconsistencies in clock frequencies. As time goes by, these drifts build up leading to significant time differences which may cause problems with tools such as cron and ‘make’ which examines timestamps on files.
How to install NTP server
To install NTP server on your Ubuntu system, open up your terminal and run the command below:
apt-get install ntp
To verify the installation went on smoothly, run
dpkg -l | grep "ntp"
Output
ii ntp 1:4.2.8p4+dfsg-3ubuntu5.8 amd64 Network Time Protocol daemon and utility programs
Afterward, update the system using the command below
apt-get update
After a successful update of the system, verify whether NTP is running using the command below
systemctl status ntp

To verify that NTP is working as it should run the command below
ntpq -p
This command queries and displays the NTP server pools that ntpd has been connected to.
Output

How to force a clock update using ntp
Sometimes, you may come across a system without a battery-backed Real Time Clock and time synchronization becomes a problem. In this case, you may be required to force a clock update so that your system time is in synchrony without any time lags. Instead of running ntpdate
command which has been obsoleted, run the commands below.
First, stop the NTP service
systemctl stop ntp
Run the command below
ntpd -gq
Output
The -gq
option tells the NTP daemon to rectify the time irrespective of the skew (g) and exit (q) immediately.

Finally, start the NTP service
systemctl start ntp
Using timedatectl & timesyncd
ntpdate was phased out in earlier versions of Ubuntu and in favor of timedatectl. To check the time status run
timedatectl
Output
root@ip-172-31-41-251:/home/ubuntu# timedatectl status
Local time: Mon 2018-04-09 18:59:18 UTC
Universal time: Mon 2018-04-09 18:59:18 UTC
RTC time: Mon 2018-04-09 18:59:17
Time zone: Etc/UTC (UTC, +0000)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
The nameserver used for fetching time for timedatectl and timesyncd is found in /etc/systemd/timesyncd.conf
Additional configuration files can be found in /etc/systemd/timesynd.conf.d
Another method which you can use to set the system time immediately is using sntp as shown below.
sntp -s 24.56.178.140
The address after the -s flag represents an NTP server. Feel free to use any NTP server address.
Finally, you can also ignore the panic threshold, which by default is a 1000 seconds. This can be done in the following ways:
- editing the
/etc/default/ntp
and ensuring that the -g option is present. - editing the
/etc/ntp.conf
and placingtinker panic 0
at the top
When changes have been made on configuration files , ensure that you reload the ntp service.
systemctl restart ntp
To get more information on the NTP time servers visit the NTP site. In this article, we have seen how you can install and Synchronize time using NTP server in Ubuntu systems to keep your system time accurate.Thank you for your time. Feel free to try out the commands and give us feedback.
Minor typo in the article: Should be systemctl start ntp, not systemctl ntp start
Hi Erik,
Thanks for pointing out the typo. It's corrected.
have a clarification: my company has its own NTP server pool 1--4. so on myubuntu linux machines I need to install NTP client or NTP server? I just updated the pool its in /etc/ntp.conf but wanted to assure do I also need to install NTP server for ntp to work?
Yes you need to install on the client as well and also you add ntpdate
apt-get install ntpdate ntp -y