Keeping the server with accurate time is very important. Unix / Linux operating system uses NTP to implement it. The Network Time Protocol (NTP) is a protocol for synchronizing the clocks of computer systems over packet-switched, variable-latency data networks. NTP uses UDP on port 123 as its transport layer.
Adjust server time manually
The easiest way to synchronize time with timeserver is using the ntpdate command. Firstly, I changed the system time with the date command to a wrong time, and then I use the ntpdate to correct the system time.
# date –s 12:40:00
Sat Jun 6 12:40:00 EDT 2009
# hwclock –w
# ntpdate pool.ntp.org
6 Jun 12:49:14 ntpdate[6480]: step time server 66.96.30.35 offset 531.927859 sec
The ntp server “pool.ntp.org” is recommended by ntp.org, you can use other one, check out ntp.org for details.
We have found this way do a big correction. If we did in a production environment like this, it could lead to inconsistent logs or produce fatal errors. Another method is using ntpd to adjust time gently.
Adjust server time automatically
This way is to use ntpd daemon. In general, we should set a (or more) time server, the other systems can be its clients.
Server configuration
Edit the /etc/ntp.conf file and modify the appropriate lines like below.
# vi /etc/ntp.conf
server 127.127.1.0
fudge 127.127.1.0 stratum 10
restrict north-america.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
server north-america.pool.ntp.org
server pool.ntp.org
server pool.ntp.org
Before starting the ntpd daemon, run ntpdate to synchronize your clock with a time server.
# ntpdate –u north-america.pool.ntp.org
6 Jun 13:11:28 ntpdate[4125]: adjust time server 66.96.30.35 offset 0.036292 sec
As an alternative, you can add your time servers to /etc/ntp/step-tickers.
# echo north-america.pool.ntp.org >>/etc/ntp/step-tickers
Start the ntpd daemon.
# service ntpd start
Verify if it works.
# watch ntpq –p
Every 2.0s: ntpq -p Sat Jun 6 13:22:35 2009
remote refid st t when poll reach delay offset jitter
==========================================
LOCAL(0) .LOCL. 10 l 37 64 377 0.000 0.000 0.002
*triangle.kansas 128.252.19.1 2 u 88 64 176 64.097 -6.271 5.220
… …
Client configuration
Edit the /etc/ntp.conf file and modify the appropriate lines like below.
# vi /etc/ntp.conf
restrict 192.168.189.133 mask 255.255.255.0 nomodify notrap noquery
server 192.168.189.133
Note: 192.168.189.133 is my server’s IP address
Before starting the ntpd daemon, run ntpdate to synchronize your clock with your time server.
# ntpdate –u 192.168.189.133
6 Jun 13:53:26 ntpdate[6537]: adjust time server 192.168.189.133 offset -0.096182 sec
As an alternative, you can add your time servers to /etc/ntp/step-tickers.
# echo 192.168.189.133 >>/etc/ntp/step-tickers
Start the ntpd daemon.
# service ntpd start
Verify if it works.
# watch ntpq –p
Every 2.0s: ntpq -p Sat Jun 6 13:54:21 2009
remote refid st t when poll reach delay offset jitter
============================================
a.localdomain 132.214.200.120 3 u 38 64 7 0.343 23.605 6.261