Network Time Protocol is used to synchronize the time on Linux Server. NTP continuously sync and adjusts the time setting of the client by querying the NTP server. It is recommended to be used by systems which need very fine tuned time synchronization requirements (milliseconds). Recommended setup to use is to have a common NTPD server on your LAN and then configure other devices to sync to it.
Install NTP packages
Use yum to install NTP Package for the server and client:
# yum install ntp
We need to force a time update to correct the time on the ntp server. Run the following command at least 3 times to get an accurate time from the timeservers. Be sure the ntp service is stopped.
# ntpdate asia.pool.ntp.org
Update NTP config
Edit the /etc/ntp.conf file on the server. Add the following line to allow machines on your own network to synchronize with your NTP server.
# restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
Under the default servers section, add the local clock to the ntp.conf file so that if the NTP server is disconnected from the internet, NTP server provides time from its local system clock.
# server 127.127.1.0 # local clock
# fudge 127.127.1.0 stratum 10
Now start the NTP service on the server and it will sync time on the ntp server of CentOS or Red Hat.
# /etc/init.d/ntpd start
# ntpq -c lpeer
Now on the client ntp servers. First run ntpdate 3 times on to manually sync time on the local NTP server. Be sure the ntpd service is not running when you use this command.
# ntpdate 192.168.0.1
Now edit the /etc/ntp.conf file and add the IP address of the local ntp server. Put it above other ntp server lines.
# server 19.168.1.1 prefer
Start the ntp service and check for the status. After a few minutes of starting the ntpd service, you should see an asterisk (*) on you ntpq output. This indicates that the ntp is currently synced on that server.
# /etc/init.d/ntpd start
# ntpq -c lpeer
remote refid st t when poll reach delay offset jitter
+server2.ntp 209.51.161.238 2 u 4 64 37 32.457 1.289 0.140
+server1.ntp 204.9.54.119 2 u 7 64 37 30.796 1.794 0.135
*ntp.server.new .ACTS. 1 u 3 64 37 58.377 0.724 0.648
LOCAL(0) .LOCL. 10 l 6 64 37 0.000 0.000 0.001
– masterkenneth