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.
sudo apt update sudo apt upgradeInstall
chrony:If it's not already installed, you can install
chronyby running:sudo apt install chronyConfigure
chronyas an NTP server:Now you need to configure
chronyto act as an NTP server.Open the configuration file with a text editor, for example:
sudo nano /etc/chrony/chrony.confFind 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
chronyas an NTP server, you need to allow incoming NTP requests. Scroll to the bottom of the configuration file and add the following line:allow 192.168.0.0/16 # Allow NTP access from this subnetYou can replace
192.168.0.0/16with the IP address range of the clients that should be able to sync their time with this server.
Restart the
chronyservice:After making changes to the configuration file, restart the
chronyservice to apply the changes.sudo systemctl restart chronyEnable
chronyto start on boot:To ensure that
chronystarts automatically when the system reboots, use the following command:sudo systemctl enable chronyVerify the NTP server status:
You can check if the
chronyservice is running properly by typing:sudo systemctl status chronyOr you can check if the server is syncing correctly:
chronyc trackingAllow NTP through the firewall (if applicable):
If you're using
ufw(Uncomplicated Firewall), you need to allow NTP traffic (UDP port 123):sudo ufw allow 123/udpTest 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:
sudo chronyc -a makestepYou can also configure the client to use your server for NTP by editing the
chrony.conffile on the client:sudo nano /etc/chrony/chrony.confAdd the NTP server's IP address (the one you just set up) under the
serverdirective:server <your_server_ip> iburstThen restart the client service:
sudo systemctl restart chrony
Last updated