The FreeBSD Diary |
(TM) | Providing practical examples since 1998If you buy from Amazon USA, please support us by using this link. |
Time synchronization - xntpd
2 August 1998
|
||||||||||
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.pidbut under 4.*, /usr/sbin/ntpd -c /etc/ntp.conf -p /var/run/ntpd.pidand under 5.*, /usr/sbin/ntpd -p /var/run/ntpd.pid -f /var/db/ntpd.driftFor more information on xntpd, try man xntpd or the online manual. |
||||||||||
/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: |
||||||||||
|
||||||||||
server your.isp.com driftfile /etc/ntp.drift |
||||||||||
|
||||||||||
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
|
||||||||||
|