NTP Configuration

Introduction

MidnightBSD uses OpenNTPD as the system ntpd by default. For many simple time synchronization needs, this is adequate.

It is recommended to configure at least 4 NTP servers.

Enable it as follows:

doas sysrc ntpd_enable="YES"

After enabling, start the daemon:

doas service ntpd start

Switching to ntp

You can install ntpd from mports:

doas mport install ntp

Disable the system ntpd

doas sysrc ntpd_enable="NO"
doas service ntpd stop
        

Then enable ntp

doas sysrc ntp_enable="YES"
doas sysrc ntp_sync_on_start="YES"
        
To set ntp flags: doas sysrc ntp_flags="-g"

Edit the configuration file in /usr/local/etc/ntp.conf

After enabling, start the daemon:

doas service ntp start

Example configuration file

server time.nist.gov iburst
server time.apple.com iburst
server 0.midnightbsd.pool.ntp.org iburst
server 1.midnightbsd.pool.ntp.org iburst
server 2.midnightbsd.pool.ntp.org iburst
server 3.midnightbsd.pool.ntp.org iburst
driftfile /var/db/ntp.drift
tinker panic 0
tinker step 0.128
        

Using GPS as a source

Example configs in /usr/local/etc/ntp.conf:

# gps source directly
#server 127.127.20.0 mode 0 minpoll 4 maxpoll 4
#fudge 127.127.20.0 refid GPS time1 0.000
# pps source directly
#server 127.127.22.0 minpoll 4 maxpoll 4 prefer
#fudge 127.127.22.0 refid PPS flag3 1
# uncomment for gpsd
#server 127.127.28.0 minpoll 4 maxpoll 4
#fudge 127.127.28.0 refid GPS strtaum 0 time1 0.060
        

Adjust time1 offsets to get your GPS source to be within +- 5 seconds of internet servers

Setup gpsd
doas sysrc gpsd_enable="YES"
doas sysrc gpsd_flags="-n"
doas sysrc gpsd_devices="/dev/cuaU0"
        

Switching to ntpsec

You can install ntpsec from mports:

doas mport install ntpsec

Disable the system ntpd

doas sysrc ntpd_enable="NO"
doas service ntpd stop
        

Then enable ntpsec:

doas sysrc ntpsec_enable="YES"

Edit the configuration file in /usr/local/etc/ntpsec.conf

After enabling, start the daemon:

doas service ntpsec start

Warning: ntpsec port is not complete yet. The daemon works, but there are issues with the python utilities.

Enabling NTS

nts enable
# Point to your existing key and certificate
nts key /etc/ssl/mydomain.key
nts cert /etc/ssl/mydomain.crt
        

Syncing on startup with rdate

The base system includes the rdate utility to sync time.

For example, to manually sync time on the CLI

doas rdate -n stargazer.midnightbsd.org

To automatically sync time at system startup

doas sysrc rdate_enable="YES"
doas sysrc rdate_flags="-n stargazer.midnightbsd.org"