NTP primer on FreeBSD, NetBSD

Software

This post was originally written for my university intranet blog this morning.

NTP stands for Ninja Tactical Peoples Network Time Protocol and is a system you can use to keep your system clock accurate by synchronizing it with a time server.

ASIDE: According to Wikipedia its one of the earliest internet protocols still being actively used, having been defined in the mid 1980s… only just a few years before I was come to think of it. Cool.

You'll probably want to use a time server that's geographically closer to you for better accuracy, but adding a few extra doesn't hurt and indeed the relevant NFS applications can determine which is more accurate. This site has a list of freely available time server addresses.

NTP on FreeBSD and NetBSD makes use of two related tools:

ntpdate

ntpdate updates your system clock from a specified server, and is generally set to run when you boot your computer. Therefore if you shutdown and start your machine frequently it will be run more often and can provide sufficient time synchronisation.

On either BSD append the following lines to /etc/rc.conf:
FreeBSD: ntpdate_enable="YES", ntpdate_flags="servers…"
NetBSD: ntpdate=YES, ntpdate_hosts="servers…"

ntpd

If your computer runs for longer that several days at a time, it's best to configure the ntpd daemon. It makes changes to your clock by comparing it's current value to a specified server or servers.

Open your /etc/rc.conf file again and append the following lines:
FreeBSD: ntpd_enable="YES"
NetBSD: ntpd=YES

Then create a new /etc/ntp.conf and fill in your server details, along with the location of a file to record the time drift that you know won't be overwritten or changed by another process, and if you prefer a line to prevent access to your NTP server from other computers:

server ntp.example.com prefer
server ntp.example.org
server ntp.example.net
driftfile /var/db/ntp.drift (not needed for > FreeBSD 6.2)
restrict default ignore

More information

The BSD DaemonFor more information and configuration options, consult the ntpdate and ntpd manual pages, as well as the NTP chapters in the FreeBSD Handbook, and NetBSD Guide. BSD handbook documentation rocks!

AFTERWORD: If you really need to run a version of FreeBSD prior to 5.x, replace ntpd_enable with xntpd_enable.

Author bio and support

Me!

Ruben Schade is a technical writer and infrastructure architect in Sydney, Australia who refers to himself in the third person. Hi!

The site is powered by Hugo, FreeBSD, and OpenZFS on OrionVM, everyone’s favourite bespoke cloud infrastructure provider.

If you found this post helpful or entertaining, you can shout me a coffee or send a comment. Thanks ☺️.