NTP is a networking protocol which enables one to synchronize clock among different computers using IP packets. NTP is commonly used when you need to maintain a cluster of hosts as part of distributed compute and storage cloud, where clock synchrony is important for proper operations. NTP is capable of compensating for variable latency over networks, and can achieve clock synchronization with 1 millisecond accuracy under ideal conditions. If you would like to synchronize time on all hosts involved via NTP, you need to set up NTP client on each host, which is described as follows.
Install NTP Client on CentOS, RHEL or Fedora
First, install ntp with yum:
After that, start ntpd service and enable it to auto-start:
On CentOS/RHEL 6 or earlier:
$ sudo service ntpd start
On CentOS/RHEL 7 or later or Fedora:
$ sudo systemctl enable ntpd.service
Install NTP Client on Ubuntu, Debian or Linux Mint
Install ntp with apt-get:
After installing NTP, NTP daemon process ntpd should automatically start running, and auto-start upon boot. If not, you can manually start it as follows.
Configure NTP Client
After you install ntp as above, edit /etc/ntp.conf to change NTP servers in the file as needed. Depending on where you are located, you may want to choose NTP servers located geographically close by. For example, if you are located in North America, you can set the following in /etc/ntp.conf.
server 0.north-america.pool.ntp.org server 1.north-america.pool.ntp.org server 2.north-america.pool.ntp.org server 3.north-america.pool.ntp.org
For a list of available public NTP servers, check out: http://www.pool.ntp.org/
Note that in case the clock on your host is significantly out of sync against NTP servers, it may take a long time for the host to drift to the correct current time, as the ntpd daemon process performs smooth clock adjustment over time. So if your clock is significantly incorrect, it is recommended that you synchronize time by running ntpdate manually. Note that before running ntpdate, you need to stop ntpd daemon first.
Use NTP Behind Proxy or Firewall
NTP uses UDP packets with port number 123. So if your host is behind a corporate proxy or firewall, and the proxy or firewall blocks that port number, the public NTP servers you specify in /etc/ntp.conf won't be reachable to your host. So make sure that your host can reach the NTP servers on port 123, using UDP. When a corporate proxy or firewall is in place, typically there exist internal NTP servers set up by the company. So you should use those internal NTP servers instead.
Use NTP in the Virtual Machine (VM) Environment
If the host in question is a XenServer's guest VM, you need to set up ntpd on dom0 host machine, not on the gust VM itself. You won't be able to synchronize clock with NTP on XenServer VMs when clock on their dom0 is not up-to-date. Once you synchronize clock on dom0, time on guest VMs will automatically be sync-ed without setting up ntpd.
As far as VMware Server is concerned, host machine's clock and guest VM's clock can drift independently. So you need to set up ntpd on guest VMs, independent of the host machine.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!