Co[de]mmunications

Programming and ramblings on software engineering.

Enabling NTP in OpenBSD

The system clock in my Sun Ultra 5 drifted away every few days. This is how NTP is enabled in OpenBSD:

$ sudo su -
# echo 'ntpd_flags=""' >> /etc/rc.conf.local

This will cause the ntpd daemon to be started next time you reboot the system. To start it right now, do:

$ sudo ntpd

Last, to make sure the daemon is running correctly, examine the contents of /var/log/daemon:

$ sudo su -
# cat /var/log/daemon | grep ntpd
Oct 12 17:35:50 sverker ntpd[17976]: ntp engine ready
Oct 12 17:36:09 sverker ntpd[17976]: peer 62.20.50.110 now valid
Oct 12 17:36:10 sverker ntpd[17976]: peer 217.118.216.117 now valid
Oct 12 17:36:11 sverker ntpd[17976]: peer 83.241.233.179 now valid
Oct 12 17:36:11 sverker ntpd[17976]: peer 91.194.67.9 now valid
Oct 12 17:36:12 sverker ntpd[17976]: peer 81.234.213.16 now valid
Oct 12 17:37:08 sverker ntpd[19401]: adjusting local clock by 4.491034s
Oct 12 17:40:57 sverker ntpd[19401]: adjusting local clock by 2.992072s
Oct 12 17:43:03 sverker ntpd[19401]: adjusting local clock by 1.459956s
Oct 12 17:47:16 sverker ntpd[19401]: adjusting local clock by -0.598555s
Oct 12 17:50:25 sverker ntpd[19401]: adjusting local clock by -0.347570s
Oct 12 17:50:25 sverker ntpd[17976]: clock is now synced
Oct 12 18:25:26 sverker ntpd[19401]: adjusting local clock by -0.968709s
Oct 12 18:27:36 sverker ntpd[19401]: adjusting local clock by -0.929344s
Oct 12 18:27:36 sverker ntpd[19401]: adjusting clock frequency by -1280.000000 to -1280.000000ppm
Oct 12 18:27:36 sverker ntpd[17976]: clock is now unsynced
Oct 12 18:31:55 sverker ntpd[19401]: adjusting local clock by -0.614471s
Oct 12 18:31:55 sverker ntpd[17976]: clock is now synced

If you are unfamiliar with the sudo and su utilities, I suggest you read this intro and this manpage. The short version is that you substitute user identity (to root, in this case).

Update: As mentioned by joedonut at reddit, it is possible to enable NTP when you install OpenBSD. This article describes how to enable the daemon for users who chose not to do it at install time.