Time synchronization – xntpd

Time synchronization – xntpd

This article shows you how to ensure the clock on your computer is kept synchronized.
It originally dealt only with xntpd, but this is also
applicable to ntpd.

See also NTP in the
FreeBSD Handbook.

Details for 5.x were added on 15 July 2004.

2 August 1998

Late last night I was reading up on Apache, the
http server.  It seems a good idea to install a time synchronization daemon because
parts of http are expressed as the time of day.  So I started looking up some
information.  xntpd is a Network Time Protocol daemon.  I decided to
go with that.  It comes with FreeBSD; very little effort is required to get it
running.

NOTE: under later versions of FreeBSD, notably 4.*, the xntpd binary
has been replaced with ntpd.  However, the following options will work as
shown.

In the mailing list archives
I found a message
which showed how to install xntpd.  In brief, it outlined the following
steps:

1.  Create /etc/ntp.conf:

	server <address of time server>
	driftfile /etc/ntp.drift
	
	Note: Under 5.*, you do not have to include the driftfile line.

2.  Enable xntpd by adding the following entries to /etc/rc.conf.  
    See /etc/defaults/rc.conf for the values you need.  They 
    should look something like this:
    Under 3.*

        xntpd_enable="YES"
        xntpd_flags="-c /etc/ntp.conf -p /var/run/xntpd.pid"
    Under 4.*, you should use this

        xntpd_enable="YES"
        xntpd_flags="-c /etc/ntp.conf -p /var/run/ntpd.pid"
    Under 5.*, you should use this

        ntpd_enable="YES"
3.  On the next reboot you'll be syncing clocks automatically.
4.  Or you can issue this command:
    Under 3.*
      /usr/sbin/xntpd -c /etc/ntp.conf -p /var/run/xntpd.pid
    but under 4.*,

      /usr/sbin/ntpd -c /etc/ntp.conf -p /var/run/ntpd.pid
    and under 5.*,

      /usr/sbin/ntpd -p /var/run/ntpd.pid -f /var/db/ntpd.drift
For more information on xntpd, try man xntpd or 
the online manual.

I use my ISP as a time server.  You might want to ask your ISP if they provide
such a service.  If they do, use them.  If they don’t, try the one resources
listed at the end of this article.  It’s also been pointed out to me that it might
pay to use more than one timer server.

/etc/ntp.conf

Here is the contents of my xntpd configuration file.  You can use it as
an example, but you should not use the servers listed below.  They will not be
appropriate for you as they are too far away.  I suggest you use your ISP as a time
server.  That’s what I’m doing.

server actrix.gen.nz
driftfile /etc/ntp.drift

Use your FreeBSD box as a time server for your subnet

If you are running several machines at home, one of them should act as a server for
the others.  There is no reason for each of the machines to individually access a
time server.  In fact, it’s an ineffecient use of resources which increases traffic.

Once
you go through the above installation process, your FreeBSD box can act as both a client
and a server.  Thus, it can act as a server for the rest of your subnet.   I run
several NT boxes on my subnet.  I installed a time client on those machines and they
now synchronize with the FreeBSD box.  In this solution, the gateway machine talks to
the external time servers and my local subnet coordinates their time with the gateway.

A side-benefit of this approach is that should anything go wrong with the time on your
network, you only need to change your gateway time and all other machines will pick up the
change.

xntpd as both client and server

Note that xntpd can act as both a server and as a client at the same time.
  One box is designated as your local server and all of your other boxes should point
to it.  The server will point to your ISP.  Here are some sample configuration
files to do this:

/etc/ntp.conf on the server

server your.isp.com
driftfile /etc/ntp.drift

/etc/ntp.conf on the clients

server your.local.server
driftfile /etc/ntp.drift

You should change your.isp.com to the host name of your ISPs time
server.  Contact your ISP for details.  You should also change your.local.server
to the IP address or the host name of the box on your subnet which will service your other
boxes.

Windows time synchronization clients

The following is a list of Windows applications which will work with xntpd.
  If your favorite isn’t listed below, please add yours via a comment.

Whatever client you choose, it must be able to use SNTP (Simple Network Time Protocol),
which is what xntpd uses.

Note that if you are running Samba, it can be a time server.  See the end of this article for details.

1 September 1998

Today I installed the time daemon on the new system.  It ran first time.

Time related resources

UTC, TAI, and
UNIX time

an explanation of each and how they differ

Public NTP
Time Servers

good stuff and some sound guidelines

Time WWW server
copies of the software you might want.  Lots of links to other information.

US Navy time servers

a good resource

RFC 1769

Simple Network Time Protocol (SNTP)

2 thoughts on “Time synchronization – xntpd”

  1. stefano j attardi

    (posted by Dan Langille)

    I thought it would be nice to add to the "Windows time
    synchronization clients" section that Windows 2000 now
    has a built-in service, the Windows Time Service, which,
    when activated, periodically syncronizes time with a
    time server.

    More information about the Service:
    http://support.microsoft.com/support/kb/articles/Q224/7/
    99.ASP

    And about how to configure it:
    http://support.microsoft.com/support/kb/articles/Q216/7/
    34.ASP

    I also would like to suggest my favorite Windows 9x NTP
    client, Automachron (freeware):
    http://www.oneguycoding.com/automachron/

    Thanks for the excellent help I’ve found in your site,

  2. The command "ntpdc -c peers" will show your upstream time server peers. If I run this on my time server, I see this:

    $ ntpdc -c peers
    remote local st poll reach delay offset disp
    =======================================================================
    =dense.utcc.utor 10.0.0.1 2 1024 377 0.07260 0.005372 0.01482
    =wxo-svr2.cmc.ec 10.0.0.1 3 1024 377 0.04015 0.011733 0.01866
    =time.nrc.ca 10.0.0.1 2 1024 377 0.08786 0.022891 0.01485
    =time1.chu.nrc.c 10.0.0.1 2 1024 377 0.06392 0.012392 0.01483
    *wxo-svr1.cmc.ec 10.0.0.1 2 1024 377 0.03757 0.012347 0.01866

    If I run it on another box on my LAN, I see this:

    $ ntpdc -c peers
    remote local st poll reach delay offset disp
    ====================================================================
    *bast.example 192.168.0.23 3 256 377 0.00027 0.000410 0.01208

    Where bast.example is my own timeserver.


    The Man Behind The Curtain

Leave a Comment

Scroll to Top