Configuring a Linux Host as NTP Server

 

  • Network devices may need an NTP server to sync its clock; so that all devices in the network display same time…We can configure a Linux host as an NTP server.
  • Check whether NTP daemon is installed in Linux: [Tested in RedHat-3.4.6]
[root@server2 ~]# rpm -qa | grep ntp-
ntp-4.2.0.a.20040617-6.el4
[root@server2 ~]#

Procedure:

First we need to sync the linux host with stratum-0 or 1 NTP public servers (with NTP daemon disabled-to use ntp port: UDP 123). Once it is sync-ed, we can start the NTP daemon and it will respond to sync-request from local network devices.

  • Check whether ntpd is disabled – Only then we can open UDP:123 port to sync with public NTP servers.

Use “service ntpd status” or “pgrep ntpd” or “netstat -a | grep ntp”. Last 2 commands will not have any outputs if NTP daemon is disabled.

  • Check Public NTP servers are configured in “etc/ntp.conf”
[root@server2 ~]# cat /etc/ntp.conf | grep ^server
server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server  127.127.1.0     # local clock
[root@server2 ~]#
  • Even if we start the NTP service now, the linux host will not sync with public NTP servers if the difference between local time and NTP server time is huge. Hence manually force the linux host to update its time as given by NTP server. (NTP daemon has be disabled for the port to open)
[root@server2 ~]#date -s "Jan 01 00:00:00"
[root@server2 ~]# date
Sat Jan  1 00:00:18 PST 2011
[root@server2 ~]#
[root@server2 ~]# ntpdate 0.us.pool.ntp.org
28 Aug 13:17:46 ntpdate[27387]: step time server 74.118.152.85 offset 20693378.740392 sec
[root@server2 ~]# date
Sun Aug 28 13:17:48 PDT 2011
[root@server2 ~]#

We can see NTP logs in “/var/log/messages” folder.

  • Now we can start the ntpd process using “service ntpd start” so that local linux host can act as NTP server for routers. Check whether the linux host is in sync with public NTP servers using “ntpq –p” command.
  • “tcpdump –vv  -i eth0 port 123” to check incoming/outgoing NTP packets.
  • Configuration on network device. In this example it is Force10 router;
Force10#show run ntp
!
ntp server 10.11.131.220
ntp update-calendar
Force10#
Force10#show clock detail
13:44:59.997 PDT Sun Aug 28 2011
Time source is NTP
Force10#show ntp status
Clock is synchronized, stratum 3, reference is 10.11.131.220
frequency is -64.000 ppm, stability is 407.836 ppm, precision is 4294967283
reference time is D2052746.38463000 (20:44:54.219 UTC Sun Aug 28 2011)
clock offset is -50.780340 msec, root delay is 0.08142 sec
root dispersion is 0.33315 sec, peer dispersion is 278.152 msec
peer mode is client

Note: NTP status will show clock sync-ed only after some minutes.

<NTP debug on Force10 when NTP sync occurs>

3d0h35m : NTP: rcv packet from 10.11.131.220

leap 3, mode 4, version 3, stratum 0, ppoll 16

rtdel 0000 (0.000000), rtdsp 00A2 (2.471924), refid 494E4954 (73.78.73.84)

ref 00000000.00000000 (6:28:16.000 UTC Thu Feb 7 2036)

org D20529E2.F6AAA000 (20:56:2.963 UTC Sun Aug 28 2011)

rec D20529E2.E71550CA (20:56:2.902 UTC Sun Aug 28 2011)

xmt D20529E2.E715F88F (20:56:2.902 UTC Sun Aug 28 2011)

inp D20529E2.F6D8D000 (20:56:2.964 UTC Sun Aug 28 2011)

3d0h35m : ntpDebug: receive: pkt 48 bytes

3d0h35m : ntpDebug: receive: his mode 4

Aug 28 20:56:03: %RPM0-P:CP %NTP-6-INVALID PKT: xntpd task, invalid pkt received, bad header

3d0h37m : NTP: rcv packet from 10.11.131.220

leap 0, mode 4, version 3, stratum 2, ppoll 16

rtdel 14BD (81.008911), rtdsp 10C6B (1048.507690), refid 44000E4C (68.0.14.76)

ref D20529FF.3F0E3CD9 (20:56:31.246 UTC Sun Aug 28 2011)

org D2052A43.BBA9F000 (20:57:39.733 UTC Sun Aug 28 2011)

rec D2052A43.A25ABC0E (20:57:39.634 UTC Sun Aug 28 2011)

xmt D2052A43.A25B530C (20:57:39.634 UTC Sun Aug 28 2011)

inp D2052A43.BBD74000 (20:57:39.733 UTC Sun Aug 28 2011)

3d0h37m : ntpDebug: receive: pkt 48 bytes

3d0h37m : ntpDebug: receive: his mode 4

3d0h37m : ntpDebug: clock_update(10.11.131.220)

3d0h37m : ntpDebug: synchronized to 10.11.131.220, stratum=2

References:

Public NTP servers: http://support.ntp.org/bin/view/Servers/NTPPoolServers

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch24_:_The_NTP_Server

http://linux.die.net/man/1/ntpd

Advertisements
This entry was posted in Linux and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s