How to Install NTP Server and Client on Ubuntu

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
Update Ubuntu System
Update 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.

Install NTP Server on Ubuntu
Install NTP Server on Ubuntu

To confirm that NTP protocol has been successfully installed, run the command.

$ sntp --version
Check NTP on Ubuntu
Check 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 Pools
Default NTP Server Pools

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.

NTP Pools from Europe
NTP Pools from Europe

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
Configure NTP Pools on Ubuntu
Configure 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 ntp
Verify NTP Status
Verify 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 status
Verify NTP Access on UFW Firewall
Verify 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 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
Update NTP Client Machine
Update 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 ntpdate
Install ntpdate on Ubuntu Client
Install 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	bionic
Add IP Address and Hostname
Add 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 Server
Verify Client Time Sync with NTP Server

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.

Install NTP Client on Ubuntu
Install NTP Client on Ubuntu

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
Configure NTP Client on Ubuntu
Configure 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 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.

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

7 thoughts on “How to Install NTP Server and Client on Ubuntu”

    • @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.

      Reply
  1. 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.

    Reply
  2. 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.

    Reply
  3. 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

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.