NTP Server
Setting up an NTP (Network Time Protocol) server on an Ubuntu machine is a straightforward process. You can use chrony
or ntpd
(Network Time Protocol Daemon) to accomplish this task. Here's how to set up an NTP server using chrony
, which is the preferred tool in modern versions of Ubuntu.
Steps to Set Up an NTP Server on Ubuntu (using chrony
):
chrony
):Update your system:
Before installing new packages, itโs always a good idea to update your system.
Install
chrony
:If it's not already installed, you can install
chrony
by running:Configure
chrony
as an NTP server:Now you need to configure
chrony
to act as an NTP server.Open the configuration file with a text editor, for example:
Find the line that begins with
server
(itโs usually a line likeserver 0.centos.pool.ntp.org iburst
) and add the NTP servers you want to use. You can use public NTP servers likepool.ntp.org
, or configure your own servers.To configure
chrony
as an NTP server, you need to allow incoming NTP requests. Scroll to the bottom of the configuration file and add the following line:You can replace
192.168.0.0/16
with the IP address range of the clients that should be able to sync their time with this server.
Restart the
chrony
service:After making changes to the configuration file, restart the
chrony
service to apply the changes.Enable
chrony
to start on boot:To ensure that
chrony
starts automatically when the system reboots, use the following command:Verify the NTP server status:
You can check if the
chrony
service is running properly by typing:Or you can check if the server is syncing correctly:
Allow NTP through the firewall (if applicable):
If you're using
ufw
(Uncomplicated Firewall), you need to allow NTP traffic (UDP port 123):Test the NTP server:
To test if the NTP server is working, you can try syncing time from a client machine. On the client machine, you can use the following command:
You can also configure the client to use your server for NTP by editing the
chrony.conf
file on the client:Add the NTP server's IP address (the one you just set up) under the
server
directive:Then restart the client service:
Last updated