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
Text code
  1. 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
Text code
  1. 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.

remoterefidsttwhenpollreachdelayoffsetjitter
gen2.ihug.co.nz130.217.76.342u56439.2392.0131.101
ns2.tpnet.co.nz131.203.16.62u464322.021-17.9140.054
jaffa.inode.co.nz131.203.16.102u66437.0351.2274.853

Here's an example of an ntpq -p command showing the time is not in synch, look at the size of the offset :-

remoterefidsttwhenpollreachdelayoffsetjitter
gen2.ihug.co.nz130.217.76.342u57643777.108-78164787510.0
ns2.tpnet.co.nz131.203.16.62u606437321.647-66152278586.4
ipaudit.tpnet.co.nz131.203.16.62u616437721.939-78164587458.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
Text code
  1. ntpd[8210]: sendto(218.185.224.8) (fd=-1): Bad file descriptor
  2. 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
Text code
  1. /etc/init.d/ntp stop
  2. killall ntpd
  3. /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
Text code
  1. ntpd -q
  2. on older machines you can use
  3. ntpdate <host>

Once the time is in synch it will be best to set the hardware clock with the following command :-

Show Plain Text
Text code
  1. hwclock --systohc [--utc]
Filed under: Linux  Tags: Debian, Ubuntu

0 Responses to “My quick NTP notes”

Sorry, comments have been closed for this post.
(default) 11 queries took 7 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`221
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`221
6DESCRIBE `categories_posts`221
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'my-quick-ntp-notes' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (73) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 73 AND `PostsTag`.`tag_id` = `Tag`.`id`) 220
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 73 AND `CategoriesPost`.`category_id` = `Category`.`id`) 111
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 7310