Network Time Protocol(NTP)

The Network Time Protocol (NTP) enables the accurate settings of time and date information in order to keep the time clocks on networked computer systems synchronized to a common reference over the network or the Internet. It is protocol which is run over the port "123" and uses UDP.

Below are the steps to configure NTP server on your local machine -

NTP Server actions

• #which ntpd - We will get know whether NTP package is installed on the machine and if installed it will show the executable file path

• #yum install ntp - Installs the NTP package on your local machine

• #vi /etc/ntp.conf - Edit the configuration as per the requirement. I have removed server 3.centos.pool.ntp.org and added the loopback address,so that even if my Internet network goes down, I can fetch the time my local network or the hardware clock from my machine. Further, you need to allow clients from your networks to synchronize time with this server. To accomplish this, add the following line to NTP configuration file, where restrict statement controls, what network is allowed to query and sync time. REPLACE NETWORK IPs ACCORDINGLY

  • chkconfig ntpd on - To make NTP daemon persistent even if the machine reboots, use chkconfig

  • chkconfig --list | grep ntpd - Just to br sure that chkconfig is configured

  • service ntpd start - Start the ntpd service

  • system-config-firewall - Configure the firewall for port 123 which is used by ntp on the NTP server/current server

  • ntpstat - To check if the ntp service is up and running. From the image you can see there is difference of 111ms which will reduce gradually to lower values. Another way to cross check the service is by the command #ntpq -p which shows the pool of ntp servers your server is connected to.

Client Server actions

  • Follow the steps 1 and 2 as mentioned above in the NTP server actions

  • vi /etc/ntp.conf - Enter the IP address of NTP server we have configured above, in the ntp.conf file of Client server. Add "prefer" in the entry you make in the ntp.conf file to use configured NTP server. Rest of the servers are used just as backup if your NTP server goes down.

  • chkconfig ntpd on - To make NTP daemon persistent even if the machine reboots

  • ntpstat - With this you can see that your Client server is synchronised with your own NTP server