Setting up time synchronization
I wanted to setup time synchronization on my Linux router. I then wanted to have my Windows machine synchronize time with the router.
Here is the article about how I accomplished that.
Contents |
[edit] Setting up a Linux NTP server
Had to install the NTP server software and configure it to the configuration that would work for me.
[edit] yum Package
The applicable yum package is ntp:
yum install ntp
[edit] Configuration file
The applicable configuration file is /etc/ntp.conf. The sections I had to modify pertained to the restrict and server options.
[edit] restrict options
The first restrict options allow the local machine to access the ntp daemon:
restrict 127.0.0.1 restrict -6 ::1
Now, I added a section to allow LAN machines to be able to query the server but not to be able to modify configuration or provide trap service (quoting from the man page: which is intended for use by remote event logging programs):
restrict 192.168.3.0 mask 255.255.255.0 nomodify notrap restrict 192.168.4.0 mask 255.255.255.0 nomodify notrap
Finally, we need to allow access to the servers we will be using to synchronize time. I got these servers from the pool.ntp.org Project. Same restrictions as the LAN with the added restriction that these servers are not allowed to perform query on our servers:
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
For more information on the restrict options:
man ntp_acc
[edit] server options
Finally, we setup which servers we want to synchronize with. As mentioned above, I got these servers from the pool.ntp.org Project:
server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org
[edit] Starting NTP service
To start the ntpd service, you would do something like this:
/sbin/service ntpd start
To configure it to start automatically:
/sbin/chkconfig ntpd on
[edit] Testing and troubleshooting
First thing, we should make sure it starts correctly. After starting the server, grep /var/log/messages for ntpd just to make sure things started up fine:
[belminf@home ~]# sudo grep ntpd /var/log/messages home ntpd[15000]: ntpd 4.2.4p2@1.1495-o Mon Sep 24 14:40:07 UTC 2007 (1) home ntpd[15001]: precision = 1.000 usec home ntpd[15001]: Listening on interface #0 wildcard, 0.0.0.0#123 Disabled home ntpd[15001]: Listening on interface #1 lo, 127.0.0.1#123 Enabled home ntpd[15001]: Listening on interface #2 eth2, 68.161.230.103#123 Enabled home ntpd[15001]: Listening on interface #3 eth0, 192.168.3.1#123 Enabled home ntpd[15001]: Listening on interface #4 eth1, 192.168.4.1#123 Enabled home ntpd[15001]: kernel time sync status 0040 home ntpd[15001]: frequency initialized 307.091 PPM from /var/lib/ntp/drift
We could then use the ntpq command to view the current status of the server and what other srevers it's interacting with by using the -p option.
When you first start up the server, you should see something like this:
[belminf@home ~]# /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
mail2.safire.bz 18.103.0.198 2 u 3 64 7 58.155 -3.329 0.856
phoenix.netserv 64.113.44.54 2 u 63 64 3 59.387 1.998 0.697
kiri.nonexiste. 66.36.239.104 3 u 65 64 3 57.072 4.045 0.504
LOCAL(0) .LOCL. 10 l 62 64 3 0.000 0.000 0.001
But as the sever synchronizes with other servers, you should see something like this:
[belminf@home root]$ /usr/sbin/ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*mail2.safire.bz 18.103.0.198 2 u 10 64 77 57.713 -2.274 0.890
+phoenix.netserv 64.113.44.54 2 u 4 64 77 59.038 1.368 1.327
+kiri.nonexiste. 66.36.239.104 3 u 8 64 77 56.552 3.564 0.505
LOCAL(0) .LOCL. 10 l 6 64 77 0.000 0.000 0.001
For info on the significance of this output, man ntpq.
[edit] Getting a Windows PC to synchronize
[edit] Setting the NTP server
The following command will set your server and then, just to make sure the change was successful, perform a query:
C:\>net time /setsntp:192.168.3.1&& net time /querysntp The command completed successfully. The current SNTP value is: 192.168.3.1 The command completed successfully.
[edit] Restarting the service
And probably good to restart the w32time service:
C:\>net stop w32time&& net start The Windows Time service is stopping. The Windows Time service was stopped successfully. The Windows Time service is starting. The Windows Time service was started successfully.
[edit] Manual time synchronization
If force the time to synchronize, use this command:
w32tm /resync
Categories: Services | Linux | Windows

