{"id":50,"date":"2014-09-23T16:40:32","date_gmt":"2014-09-23T16:40:32","guid":{"rendered":"http:\/\/www.balajibandi.com\/blog\/?p=50"},"modified":"2024-10-18T10:46:03","modified_gmt":"2024-10-18T09:46:03","slug":"howto-set-up-an-ntp-server","status":"publish","type":"post","link":"https:\/\/www.balajibandi.com\/?p=50","title":{"rendered":"HOWTO: Set Up an NTP Server"},"content":{"rendered":"<p><b>How to Maintain an Accurate System Clock with ntpd<\/b><\/p>\n<p><b>1. Install the NTP daemon<\/b><\/p>\n<p>First, install the NTP daemon (ntpd):<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">sudo aptitude install ntpd<\/pre>\n<\/div>\n<p>As was previously mentioned, ntpd can act both as a client (synchronizing your system time) and as a server (providing accurate time for other machines).<\/p>\n<p>Optionally, you may also want to remove the previous (deprecated) time synchronization program, ntpdate. Perhaps it may be wiser to do so after you have ntpd working <img decoding=\"async\" class=\"inlineimg\" title=\"Smile\" src=\"https:\/\/ubuntuforums.org\/images\/smilies\/icon_smile.gif\" alt=\"\" border=\"0\" \/><\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">sudo aptitude remove ntpdate<\/pre>\n<\/div>\n<p><b>2. Configure the daemon properly<\/b><\/p>\n<p>The configuration file for ntpd is located at \/etc\/ntp.conf. The default Ubuntu file probably requires some modification for optimal performance.<\/p>\n<p>The first section you may want to modify is the list of servers to synchronize with. The default section probably looks as follows:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\"># You do need to talk to an NTP server or two (or three).\nserver ntp.ubuntu.com<\/pre>\n<\/div>\n<p>In order to get the most accurate time possible, it is preferable to communicate with multiple different NTP servers, and keep them as close to your physical location as possible. There are various different server lists online . There is some debate over the proper number of servers to use. One is better than two, and three or more probably is a good idea, so long as you don&#8217;t go too overboard. An example of a few time servers that I used follows:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">server nist1-dc.WiTime.net iburst\nserver ntp0.mcs.anl.gov\nserver 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org\nserver 3.us.pool.ntp.org<\/pre>\n<\/div>\n<p>Once a few good servers have been found, add them to the list, putting &#8216;iburst&#8217; after the most promising one. For instance:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">server nist1-dc.WiTime.net iburst<\/pre>\n<\/div>\n<p>This will cause ntpd to synchronize very quickly with this server after starting up. Otherwise, ntpd will slowly tend to drift towards agreement with the server list (as is its nature), and it may take 15-20 minutes to synchronize well enough to act as a time server for the rest of your network.<\/p>\n<p>Also, add a few extra lines to the bottom of your servers list to provide your current local time as a default should you temporarly lose Internet connectivity:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">server 127.127.1.0\nfudge 127.127.1.0 stratum 10<\/pre>\n<\/div>\n<p>This will prevent any nastiness if you&#8217;re running ntpd on a laptop or other machine with intermittent periods of disconnectivity from the Internet.<\/p>\n<p>All in all, the server list should look similar to the following (this is mine, your servers will probably be different):<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\"># You do need to talk to an NTP server or two (or three).\nserver nist1-dc.WiTime.net iburst\nserver ntp0.mcs.anl.gov\nserver 0.us.pool.ntp.org\nserver 1.us.pool.ntp.org\nserver 2.us.pool.ntp.org\nserver 3.us.pool.ntp.org\nserver 127.127.1.0\nfudge 127.127.1.0 stratum 10<\/pre>\n<\/div>\n<p><b>3. Make sure the configuration works<\/b><\/p>\n<p>Now that you have a proper server list in your \/etc\/ntp.conf file, it is time to run the daemon and see if you synchronize properly! Make sure you have an active Internet connection, and then run:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">sudo \/etc\/init.d\/ntp restart<\/pre>\n<\/div>\n<p>Next, monitor your system log to see if you synchronize with a time server:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">tail -f \/var\/log\/syslog<\/pre>\n<\/div>\n<p>In about 10-15 seconds (or up to 15-20 minutes if you forgot to put &#8216;iburst&#8217; after your favorite server), you should see something like the following in your system log:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">Jul 17 16:50:22 hostname ntpd[22402]: synchronized to 140.221.9.20, stratum 2<\/pre>\n<\/div>\n<p>If this message never comes, you have not yet properly synchronized with the NTP server network. Check the list of NTP peers you are communicating with using the following:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">ntpq -c lpeer<\/pre>\n<\/div>\n<p>If the &#8216;delay&#8217;, &#8216;offset&#8217;, and &#8216;jitter&#8217; fields are non-zero and you haven&#8217;t synchronized, it probably means that you just need to wait a while. Check again that you&#8217;ve inserted the &#8216;iburst&#8217; argument to your servers list! My peers, for reference, look something like the following:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\">     remote           refid      st t when poll reach   delay   offset  jitter\n==============================================================================\n*milo.mcs.anl.go 192.5.41.40      2 u    4   64   77   46.213   67.753   2.207\n-europium.canoni 193.79.237.14    2 u   63   64   37   97.375   71.020   1.875\n-dtype.org       69.25.96.13      2 u    2   64   77   86.956   69.178   1.804\n+smtp130.junkema 216.218.254.202  2 u    2   64   77   87.266   67.677   0.916\n+kechara.flame.o 216.218.254.202  2 u    -   64   77   89.183   68.717   1.713\n-host2.kingrst.c 99.150.184.201   2 u    -   64   77   24.306   62.121   2.608\n LOCAL(0)        .LOCL.          10 l   59   64   37    0.000    0.000   0.002<\/pre>\n<\/div>\n<p><b>4. Share! (optional)<\/b><\/p>\n<p>Once ntpd is running and is synchronized with the time servers you have selected, you may set it up in order to act as a time server for other machines. To do so, add a section like the following to \/etc\/ntp.conf:<\/p>\n<div class=\"bbcode_container\">\n<div class=\"bbcode_description\">Code:<\/div>\n<pre class=\"bbcode_code\"># Allow LAN machines to synchronize with this ntp server\nrestrict 192.168.1.0 mask 255.255.255.0 nomodify notrap\nrestrict 192.168.2.0 mask 255.255.255.0 nomodify notrap<\/pre>\n<\/div>\n<p>You may add as many (or few) CIDR address blocks to allow to synchronize with your machine as you&#8217;d like. I included those commonly used with Linksys (192.168.1.*) and SMC (192.168.2.*) routers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Maintain an Accurate System Clock with ntpd 1. Install the NTP daemon First, install the NTP daemon (ntpd): Code: sudo aptitude install ntpd As was previously mentioned, ntpd can act both as a client (synchronizing your system time) and as a server (providing accurate time for other machines). Optionally, you may also want [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":4,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":2279,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions\/2279"}],"wp:attachment":[{"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.balajibandi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}