How To Sync System Time With NTP Servers In FreeBSD?


The computer clocks are not perfect they are prone to drift that means over the time system clock starts lagging from the actual time. There are many network services that require the correct time on a local system.

So the Network Time Protocol (NTP) provides a way to maintain the accuracy of a system clock. NTP is an internet protocol that is used to synchronize time across the multiple servers.

FreeBSD includes the NTP daemon program (ntpd) which sets and maintains the system time by synchronizing with the NTP servers.

Ahead in this article, we will discuss to configure a FreeBSD system to synchronize time with a remote NTP server.

Enabling NTP services on FreeBSD

To make sure the NTP services are running when the system is power on, you need to enable the NTP services. You can enable the ntpd by editing /etc/rc.conf file.

You can use the given command to open the rc.conf using vi in your terminal –

vi /etc/rc.conf

Press i to get into the insert mode and then add the given line –

ntpd_enable="YES"

Now get into the command mode by pressing Esc, enter the command :wq to save the file, and exit from the editor. Once the file is gets saved, reboot your system to make changes effective.

Adjust the firewall

The ntpd communicates with the NTP server or peers on the network using UDP packets on port number 123. So firewall in your system should be configured to allow the UDP packets on port 123.

You can add the given line to your pf.conf file in FreeBSD that is using the PF firewall on it.

pass out proto {tcp udp} to port {123}

 Add NTP server or pool to /etc/ntp.conf file

NTP daemon reads /etc/ntp.conf file to find which NTP server to query. Choosing more than one NTP server is recommended so that if one goes unreachable then it can sync the time with the other one.

Open the /etc/ntp.conf by using –

vi /etc/ntp.conf

From the list of publicly accessible NTP servers select the servers which are geographically close to you also see their usage policy.

By default, ntpd synchronize the system time from FreeBSD’s project sponsored pool which is 0.freebsd.pool.ntp.org you can comment it out and add the pool of servers that are closer to you for example I am in India so I will use pool 0.in.pool.ntp.org iburst.

or also you can add the servers like this –

server 0.in.pool.ntp.org
server 1.in.pool.ntp.org
server 2.in.pool.ntp.org
server 3.in.pool.ntp.org

Using iburst option at the end of the pool URL makes initial synchronization faster.

Conclusion

Ok, that’s all for now. If you have a query on this topic then write to us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.