Network Time Protocol, commonly referred to as NTP, is a protocol that’s responsible for synchronizing system clocks in a network. NTP refers to both the protocol and the client system alongside the server programs residing on the networked systems.
In this guide, we will show you how to install NTP server and client(s) on Ubuntu 18.04.
Testing Environments
This guide aims at accomplishing the following:
- Installing and configuring NTP server on Ubuntu 18.04 server.
- Installing NTP client on Ubuntu 18.04 client machine and ensure that it is synched by the Server.
Let’s get started !
Install & Configure NTP Server on Ubuntu 18.04 Server
Below is a step-by-step procedure of installing the NTP server and making the necessary modifications to achieve the desired time synchronization in the network.
Step 1: Update System Repositories
To start off, let’s begin by updating the system packages as shown.
$ sudo apt update -y
Step 2: Install NTP Server on Ubuntu 18.04
With system packages already installed, install NTP protocol on Ubuntu 18.04 LTS by running.
$ sudo apt install ntp
When prompted, type Y
and hit ENTER to complete the installation process.
To confirm that NTP protocol has been successfully installed, run the command.
$ sntp --version
Step 3: Configure NTP Server Pools on Ubuntu 18.04
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.
These usually work just as fine. However, you may consider changing to NTP server pools closest to your location. The link below directs you to a page where you can select your most preferred NTP pool list.
https://support.ntp.org/bin/view/Servers/NTPPoolServers
In our example, we will use the NTP pools located in Europe as shown.
To replace the default NTP pool servers, open the NTP configuration file using your favorite text editor as shown.
$ sudo vim /etc/ntp.conf
Copy and paste the NTP pool list in Europe to the configuration files as shown.
server 0.europe.pool.ntp.org server 1.europe.pool.ntp.org server 2.europe.pool.ntp.org server 3.europe.pool.ntp.org
Next, save and quit the text editor.
For the changes to take effect, restart the NTP service and verify its status using the commands.
$ sudo systemctl restart ntp $ sudo systemctl status ntp
If UFW firewall is enabled, we need to allow NTP service across it so that client machines can access the NTP server.
$ sudo ufw allow ntp OR $ sudo ufw allow 123/udp
To implement the changes, reload the firewall as shown.
$ sudo ufw reload
To verify the changes made execute the command.
$ sudo ufw status
Perfect! we have successfully set up our NTP server on Ubuntu 18.04 LTS system. Let’s now set up NTP on the client system.
Install & Configure NTP Client on Ubuntu 18.04 Client
In this section, we shall install and configure a NTP client on Ubuntu 18.04 client system to be synchronized by the Ubuntu 18.04 NTP Server system.
Step 1: Update System Repositories
To start off, update the system by running.
$ sudo apt update -y
Step 2: Install Ntpdate on Ubuntu 18.04
ntpdate is a utility/program that quickly allows a system to synchronize time and date by querying an NTP server.
To install ntpdate run the command.
$ sudo apt install ntpdate
For the client system to resolve the NTP server by hostname, you need to add the NTP server’s IP address and hostname in the /etc/hosts file.
Therefore, Open the file using your favorite text editor.
$ sudo vim /etc/hosts
Append the IP address and hostname as shown.
10.128.0.21 bionic
Step 3: Verify Client Time Sync with NTP Server
To manually check if the client system is in sync with the NTP server’s time, run the command.
$ sudo ntpdate NTP-server-hostname
In our case, the command will be.
$ sudo ntpdate bionic
A time offset between the NTP server and the client system will be displayed as shown.
To synchronize the client time with the NTP server, you need to turn off the timesynchd service on the client system.
$ sudo timedatectl set-ntp off
Step 4: Install NTP Client on Ubuntu 18.04
Next, you need to install NTP service on the client system. To achieve this, issue the command.
$ sudo apt install ntp
Press Y
when prompted and hit ENTER to proceed with the installation process.
Step 5: Configure NTP Client on Ubuntu 18.04
The objective in this step is to use the NTP server earlier configured to act as our NTP server. For this to happen we need to edit the /etc/ntp.conf file.
$ sudo vim /etc/ntp.conf
Append the line below where bionic
is the NTP server’s hostname.
server bionic prefer iburst
Save and exit the configuration file.
For the changes to come into effect, restart the NTP service as shown.
$ sudo systemctl restart ntp
Step 6: Verify the NTP Time Synchronization Queue
With the client and NTP server insync, you can view the sync details by executing the command.
$ ntpq -p
Sample Output
remote refid st t when poll reach delay offset jitter ============================================================================== bionic 71.79.79.71 2 u 6 64 377 0.625 -0.252 0.063
This brings us to the end of this guide. At this point you have successfully configured the NTP server on Ubuntu 18.04 LTS and configured a client system to be synchronized with the NTP server. Feel free to reach out to us with your feedback.
Hi Dear,
What if the server and client were offline working state? How can I make the stratum of the server to be accepted?
@Alkhafaji,
If both the NTP server and client are offline or in a working state, you can manually set the stratum of the NTP server to a value that is accepted in the ntp.conf file.
Finally. The trick is configuring with ntpdate, which has to be installed. My time server on the internal network is my firewall. Installing Ubuntu 18.04 broke that, despite it being the only server listed in /etc/ntp.conf.
Evidently, ntp doesn’t read that file anymore (?), and I didn’t have any better luck fooling around with timedatectl and ‘timedatectl set-ntp on‘
Thanks for this information.
Please let me know the steps How to configure if Windows 16 is an Ntp server and Ubuntu is a Client-server?
What about NTP authentication, It is extremely hard to find information on this for Ubuntu. Where is the key set, and where is the algorithm defined such as MD5, SHA1. This is very frustrating. Most sites do the bare minimum, and that is it. There do not seem to be any examples in the default ntp.conf file.
Very helpful article, thank you!
I used to do the below steps after a new installation.
sudo rm -rf /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Kolkata /etc/localtime