The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

Things look quiet here. But I've been doing a lot of blogging at dan.langille.org because I prefer WordPress now. Not all my posts there are FreeBSD related. I am in the midst of migrating The FreeBSD Diary over to WordPress (and you can read about that here). Once the migration is completed, I'll move the FreeBSD posts into the new FreeBSD Diary website.

Time synchronization - xntpd 2 August 1998
Share
Need more help on this topic? Click here
This article has 2 comments
Show me similar articles

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.

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)
Share
Need more help on this topic? Click here
This article has 2 comments
Show me similar articles