How to Install NTP Server and Client on Ubuntu
Abstract: A time offset between the NTP server and the client system will be displayed as shown. Verify Client Time Sync with NTP Server To synchronize the clie
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 EnvironmentsThis 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 ServerBelow 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 RepositoriesTo start off, let’s begin by updating the system packages as shown.
$ sudo apt update -yUpdate Ubuntu System 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 --versionCheck NTP on Ubuntu 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.
Default NTP Server PoolsThese 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.
NTP Pools from EuropeTo 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.orgConfigure NTP Pools on Ubuntu
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 ntpVerify NTP Status
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 statusVerify NTP Access on UFW Firewall
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 ClientIn 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 RepositoriesTo start off, update the system by running.
$ sudo apt update -yUpdate NTP Client Machine 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 ntpdateInstall ntpdate on Ubuntu Client
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 bionicAdd IP Address and Hostname 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.
Verify Client Time Sync with NTP ServerTo synchronize the client time with the NTP server, you need to turn off the timesynchd service on the client system.
$ sudo timedatectl set-ntp offStep 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.
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 iburstConfigure NTP Client on Ubuntu
Save and exit the configuration file.
For the changes to come into effect, restart the NTP service as shown.
$ sudo systemctl restart ntpStep 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 -pSample 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.