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"
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
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
This command queries and displays the NTP server pools that ntpd has been connected to.
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
-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
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
Additional configuration files can be found in
Another method which you can use to set the system time immediately is using sntp as shown below.
sntp -s 18.104.22.168
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/ntpand ensuring that the -g option is present.
- editing the
tinker panic 0at 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.