I believe that every organization should have a NTP/time server if they have more than one computer on site. Having an NTP server will allow you to keep the times on all of your computers in sync. This helps when comparing the logs from various servers to trace through various events that happened. It’s nice to be assured that the event really happened at the time specified in the log file regardless of what server you’re on.
In this post I will show you how to setup your RedHat Linux AS 3 or 4 machine as an NTP server. You could then take all of your other servers and workstations and have them synchronize their time from your NTP server.
By default, the files necessary to run the ntpd service are installed on a RedHat machine if you installed everything. If you did not install everything, go grab the ntp package off your install CDs or download it directly from RedHat. The name of the package that is installed on my RedHat AS4 server is ntp-4.2.0.a.20040617-4
Now we have to edit the /etc/ntp.conf file to plug in the NTP servers that we’ll synchronize with and setup the permissions of who can synchronize with us. To do this follow my steps below.
- First make sure your computer's clock is set to something sensible (within a few minutes of the 'true' time). If it isn’t, NTP may never get them synchronized. On RedHat AS4, you can use the command system-config-date, and I believe on RedHat AS3, the command is redhat-config-date.
- Open up /etc/ntp.conf in your favorite editor.
vi /etc/ntp.conf
- Plug in the timeservers that we’ll synchronize with. I use the servers from pool.ntp.org. The 0, 1 and 2.pool.ntp.org names point to a random set of servers that will change every hour.
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
- Restrict the access that the pool.ntp.org servers have to our system. By putting the below restrictions in your ntp.conf file, the servers are not allowed to modify the run-time configuration or query your Linux NTP server.
restrict 0.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 1.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
restrict 2.pool.ntp.org mask 255.255.255.255 nomodify notrap noquery
- Allow systems on your own network to query your NTP server. We have to define the networks from which this server will accept NTP synchronization requests. To do this we add another restrict statement that does not have the noquery restriction. Since my home network contains IP addresses in the range of 192.168.1.1-255, I plug in the following network:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
We could easily add many networks, or even individual hosts by using the mask 255.255.255.255.
- We also want to permit full access to our NTP server from the localhost. Add a line like the following in your ntp.conf file if it is not already in there.
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
- The last thing we want to do is to setup ntpd to automatically start at system boot.
chkconfig --level 35 ntpd on
- And then verify that your system is set to start ntpd on system boot for runlevels 3 and 5. Run the command:
chkconfig --list ntpd
And your output should look like:
ntpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
- Now your NTP config should be all setup. Let’s manually stop and then start it. Run the /etc/init.d/ntpd stop and then the /etc/init.d/ntpd start commands.
root@as1 filmoregroup.com [asdb] > /etc/init.d/ntpd stop
Shutting down ntpd: [ OK ]
root@as1 filmoregroup.com [asdb] > /etc/init.d/ntpd start
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
- At your shell prompt you can run the ntpq command to check the synchronization status of your server with the external time servers we specified in the ntp.conf file.
As root, run the command:
ntpq -p
And your output should look something like:
root@as1 filmoregroup.com [asdb] > ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+ns1.dns.pciwest 204.123.2.5 2 u 562 1024 377 76.131 -2.912 1.129
+dns1.tjgroup.no 192.43.244.18 2 u 550 1024 377 143.463 1.390 0.422
*time4.stupi.se .PPS. 1 u 604 1024 377 122.685 0.087 0.492
LOCAL(0) LOCAL(0) 10 l 35 64 377 0.000 0.000 0.001
If the jitter column has a value of 4000.00 for any of the servers then it is usually a sign that your server is not able to synchronize with that server specified on the line with the bad jitter value. You may have a firewall or other internet connectivity problem then.
- Your NTP server should now be setup. You can now tell other machines on your network how synchronize with your NTP server.
Synchronize Your Other Linux Clients
In order to point other Linux boxes on your network to your new NTP server, you’d follow the instructions above. However, instead of synchronizing with the pool.ntp.org servers you’d synchronize with the hostname of your NTP server. You also WOULD NOT need to grant access from other machines on the network to your server as we did by adding the command:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
Alternatively, you can use the command system-config-time on RedHat AS 4, or redhat-config-time on RedHat AS 3 to use a GUI to specify the NTP server to synchronize with. I have a document on doing it this way at http://timarcher.com/?q=node/16