In this guide from the Linux Tutorials, we want to teach you to Install and Configure NTP Server and Client on Ubuntu 22.04.
The Network Time Protocol (NTP) is an application layer protocol in the TCP/IP protocol suite. It is used to synchronize the clock between the client and the server to provide high-precision time correction.
The NTP server receives accurate Coordinated Universal Time (UTC) from an authoritative clock source, such as an atomic clock or GPS. Then, the NTP client requests and receives time from the NTP server.
NTP relies on User Datagram Protocol (UDP) port 123.
Install and Configure NTP Server and Client on Ubuntu 22.04
To install and configure NTP, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Ubuntu 22.04.
Now follow the steps below to complete this guide.
Installing NTP Server on Ubuntu 22.04
First, you need to update your local package index with the command below:
sudo apt update
Then, use the command below to install the NTP server on Ubuntu 22.04:
sudo apt install ntp
Verify your NTP installation by checking its version:
Output sntp [email protected] (1)
Here you need to restart the NTP server with the following command:
sudo systemctl restart ntp
Verify that the NTP server is active and running on Ubuntu 22.04:
sudo systemctl status ntp
Output ntp.service - Network Time Service Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: e> Active: active (running) since Mon 2022-05-30 08:25:26 CEST; 5s ago Docs: man:ntpd(8) Process: 50261 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, sta> Main PID: 50280 (ntpd) Tasks: 2 (limit: 2282) Memory: 1.3M CGroup: /system.slice/ntp.service └─50280 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 112:119
At this point, you need to configure the firewall on the NTP server so that clients can access it. To do this, run the following commands:
sudo iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
sudo iptables -A INPUT -p udp --sport 123 -j ACCEPT
Install an NTP Client
Here you need to configure the NTP client to be time synced with the NTP server. To do this, you have to install the ntpd service on the client machine with the following command, here our client machine is Ubuntu:
sudo apt install ntpdate
Then, install the NTP on your client machine:
sudo apt install ntp
After your installation is finished, let’s configure the NTP client.
Configure the NTP Client
It is now time to configure the NTP client so that its clock can be synced with the NTP server.
You need to open the NTP configuration file with your favorite text editor, here we use vi:
sudo vi /etc/ntp.conf
You need to comment on the pool lines and add the “server server-ip-address prefer iburst” to the file as shown below:
... #pool 0.debian.pool.ntp.org iburst #pool 1.debian.pool.ntp.org iburst #pool 2.debian.pool.ntp.org iburst #pool 3.debian.pool.ntp.org iburst server server-ip-address prefer iburst ...
When you are finished, save and close the file.
Now you need to restart the NPT client to apply the changes:
systemctl restart ntp
Then, you can check the status that its clock synced with the NTP server on Ubuntu 22.04:
Output remote refid st t when poll reach delay offset jitter ============================================================================== server-ip-address ...
For more information, you can visit the official NTP documentation.
With this guide, you learn to Install and Configure NTP Server and Client on Ubuntu 22.04.
Hope you enjoy it.