My quick NTP notes
These are just some quick notes on the Network Time Protocol (NTP) server for my reference and will get updated when time permits.
To install simply run :-
Show Plain Text- apt-get install ntp
You can edit then edit the /etc/ntp.conf file adding any local servers or options for the process to start up with.
To check the ntpd server is synchronizing correctly run :-
Show Plain Text- ntpq -p [<hostname>]
You should get something like the following table where you want the offset to be as small as possible. If the offset value is greater than 1024 it is highly likely that the clock is not being set, drifting and doing its own thing. This can happen with network faults and if your PC is thrashing.
remote | refid | st | t | when | poll | reach | delay | offset | jitter |
gen2.ihug.co.nz | 130.217.76.34 | 2 | u | 5 | 64 | 3 | 9.239 | 2.013 | 1.101 |
ns2.tpnet.co.nz | 131.203.16.6 | 2 | u | 4 | 64 | 3 | 22.021 | -17.914 | 0.054 |
jaffa.inode.co.nz | 131.203.16.10 | 2 | u | 6 | 64 | 3 | 7.035 | 1.227 | 4.853 |
Here's an example of an ntpq -p command showing the time is not in synch, look at the size of the offset :-
remote | refid | st | t | when | poll | reach | delay | offset | jitter |
gen2.ihug.co.nz | 130.217.76.34 | 2 | u | 57 | 64 | 377 | 7.108 | -781647 | 87510.0 |
ns2.tpnet.co.nz | 131.203.16.6 | 2 | u | 60 | 64 | 373 | 21.647 | -661522 | 78586.4 |
ipaudit.tpnet.co.nz | 131.203.16.6 | 2 | u | 61 | 64 | 377 | 21.939 | -781645 | 87458.9 |
If the time does not synch you can check the /var/log/syslog for any error entries. For example if you getting bad file descriptor errors like the following :-
Show Plain Text- ntpd[8210]: sendto(218.185.224.8) (fd=-1): Bad file descriptor
- ntpd[8210]: sendto(203.109.252.7) (fd=-1): Bad file descriptor
The most likely cause is that you are running too many NTP daemons which are clashing. Stop all daemons and try and start the NTP again, as follows :-
Show Plain Text- /etc/init.d/ntp stop
- killall ntpd
- /etc/init.d/ntp start
If you have a synchronization problem with the offset to your local time being to great i.e > 1024 seconds, you can manually force NTP to synch with :-
Show Plain Text- ntpd -q
- on older machines you can use
- ntpdate <host>
Once the time is in synch it will be best to set the hardware clock with the following command :-
Show Plain Text- hwclock --systohc [--utc]