In this tutorial, we will show you how to install a setup NTP server and client on Ubuntu 20.04 LTS. For those of you who didn’t know, NTP (stands for network time protocol) is used to synchronize the system clock of the client system with the clock of the server. The NTP server has features that allow synchronization between two systems with an accuracy of one nanosecond so that the two systems can communicate easily. System time applies not only to the user but also to the computer itself. In fact, time stamps make it easy to communicate between two or more computers and provide network services properly, as well as optimize the network card.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the configured NTP server and client on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Prerequisites
- A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Setup NTP Server and Client on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following apt
commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing NTP Server on Ubuntu.
Run the following command below to install the NTP server to your Ubuntu system:
sudo apt install ntp
You can verify the installation from the following command:
sntp --version
Step 3. Configure NTP server.
By default, NTP protocol comes with default NTP pool servers already configured in its configuration file as shown below in the /etc/ntp.conf
file:
sudo nano /etc/ntp.conf
You may consider changing to NTP server pools closest to your location. Use the NTP Pool Project website to find the closest NTP server pool to your location. Example replace NTP pool list in Singapore to the configuration files as shown:
server 0.sg.pool.ntp.org server 1.sg.pool.ntp.org server 2.sg.pool.ntp.org server 3.sg.pool.ntp.org
Now restart the NTP service for the changes to take effect:
sudo systemctl restart ntp
Step 4. Configure Firewall.
If you have a firewall enabled on the Ubuntu system, you’ll need to allow the port for NTP in order to accept incoming requests:
sudo ufw allow ntp sudo ufw reload sudo ufw status
Step 5. NTP Client and Server Clock Synchronization.
To manually synchronize the NTP server we need to use ntpdate
, Use the command below to install it:
sudo apt install ntpdate
Next, execute ntpdate
use the following command below:
sudo ntpdate <your-ntp server's-IP-address>
Then, disable the systemd timesyncd
service because we will be using our NTP server for this instead. Enter the following command:
sudo timedatectl set-ntp off
Step 6. Installing NTP on Client.
Now we need to install the NTP daemon on our client system:
sudo apt install ntp
After that, edit the configuration file on the client machine so that it automatically syncs with the NTP server:
sudo nano /etc/ntp.conf
Add the following file:
server <NTP-server-hostname> prefer iburst
In order to view NTP’s current synchronization status, run the following command below in Terminal:
ntpq -p
Congratulations! You have successfully configured the NTP. Thanks for using this tutorial to set up the NTP server and client on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Ubuntu website.