Introduction
Network Time Protocol, or NTP, synchronizes both the client and server's system clocks. This can be vital for some applications that are sensitive to time synchronization between all computers on the network. This article will show you how to sync your NTP server and client machine on Ubuntu 20.04.
Prerequisites
To follow this tutorial you will need two Ubuntu machines with sudo user privileges.
The server Shell must have its own dedicated IP address.
Follow the directions here to set up your dedicated IP address.
Installing NTP to server
Before we start, it is a good rule to update the local system's repositories. Enter the following command into the terminal:
sudo apt update
Enter the sudo password when you receive the prompt.
Next, we install the NTP application.
sudo apt install ntp -y
To check the version enter:
sntp --version
NTP Configuration
Use the nano command to edit the NTP configuration file:
sudo nano /etc/ntp.conf
We must replace the default NTP pools list with the appropriate pools for your location.
Area | Hostname |
Worldwide | pool.ntp.org |
Asia | asia.pool.ntp.org |
Europe | europe.pool.ntp.org |
North America | north-america.pool.ntp.org |
Oceania | oceania.pool.ntp.org |
South America | south-america.pool.ntp.org |
In our case, we will change to north-america.pool.ntp.org
Press Ctrl+x to exit and enter y when you are prompted to save.
Restart NTP Service
sudo service ntp restart
Allow NTP service through the firewall
sudo ufw allow ntp
To verify, enter:
sudo ufw status
NTP Client and Server clock Synchronization
To manually synchronize the NTP server we need to use ntpdate, but first, we must install it. Use the command below:
sudo apt install ntpdate
Now you're all done and your machines have been properly synchronized!
To execute ntpdate use the following command:
sudo ntpdate <your ntp server's IP address>
Next, we must 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
Install NTP to Client Machine
To install NTP the client machine enter the following command:
sudo apt install ntp -y
Next, we need to edit the configuration file on the client machine so that it automatically syncs with the NTP server:
sudo nano /etc/ntp.conf
The line below must be added to the configuration file, remember to replace <NTP-server-hostname> with your server's hostname.
server <NTP-server-hostname> prefer iburst
After the changes are complete, save and exit the configuration file.
To view the synchronization station of your NTP server, use the following command:
ntpq -p
Comments
0 comments
Please sign in to leave a comment.