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 with NTP, follow the steps below.
To install ntp on CentOS, Fedora or RHEL:
To install ntp on Ubuntu or Debian:
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/
After installing NTP, check that NTP daemon process (i.e., ntpd) is running. If not, you need to start it as follows.
To start ntpd on CentOS, Fedora or RHEL:
$ sudo chkconfig ntpd on
To start ntpd on Ubuntu or Debian:
Note that in case the clock on your host is significantly out of sync, 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, as follows.
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!
Latest posts by Dan Nanni (see all)
- How to set up Apt caching server on Ubuntu or Debian - February 7, 2016
- How to monitor OpenFlow messages with packet sniffer - February 2, 2016
- How to search multiple pdf documents for words on Linux - January 13, 2016