How to install NTP server and client on Ubuntu 24.04

NTP, or Network Time Protocol, is a protocol used to synchronize all system clocks on a network to use the same time. When using the term NTP, the article refers to the protocol itself and the client and server programs running on the computers connected to the network. NTP belongs to the traditional TCP/IP protocol suite and can easily be classified as one of its oldest components.

 

When you initially set up your clock to synchronize with NTP, it takes 6 exchanges over 5 to 10 minutes before the clock is set. Once the network clock is synchronized, the client updates its clock with the server every 10 minutes. This is typically done through a single message exchange (transaction). These transactions use system port 123.

This article will describe a step-by-step process on how to:

  1. Install and configure NTP server on Ubuntu machine.
  2. Configure NTP client to synchronize time with server.

The article ran the mentioned commands and procedures on Ubuntu 22.04 LTS and Ubuntu 24.04 systems.

 

Install and configure NTP server on host computer

Follow these steps to install NTP server on Ubuntu server:

Note : The article is using the Ubuntu command line, Terminal, to install and configure NTP. You can open the Terminal application via searching for the application launcher or the shortcut Ctrl + Alt + T .

Step 1: Update the package repository index

To install the latest software versions from the Internet repository, your local repository index must match them. Run the following command as sudo to update your local repository index:

$ sudo apt update

How to install NTP server and client on Ubuntu 24.04 Picture 1

Step 2: Install NTP Server using apt-get

Please run the following command as sudo to install the NTP server daemon from the APT repository:

$ sudo apt install ntp

Please note that only authorized users can add, remove, and configure software on Ubuntu.

How to install NTP server and client on Ubuntu 24.04 Picture 2

 

The system may ask you for your sudo password and give you the Y/n option to continue the installation. Type Y and press Enter ; the NTP server will then be installed on your system. However, this process may take some time, depending on your Internet speed.

Step 3: Verify settings (optional)

You can verify your NTP settings and also check the version number by running the following command in Terminal:

$ sntp --version

How to install NTP server and client on Ubuntu 24.04 Picture 3

Step 4: Switch to the NTP server pool closest to your location

When you install an NTP server, it is usually configured to get the appropriate time. However, you can switch to the server pool closest to your location. This involves making some changes to the /etc/ntp.conf file.

Open the file in nano editor as sudo by running the following command:

$ sudo nano /etc/ntp.conf

How to install NTP server and client on Ubuntu 24.04 Picture 4

In this file, you will be able to see the pool list. The task here is to replace this pool list with the pool of the time server closest to your location. The pol.ntp.org project provides reliable NTP service from a cluster of time servers. To select the pool list according to your location, visit the following page:

https://support.ntp.org/bin/view/Servers/NTPPoolServers

How to install NTP server and client on Ubuntu 24.04 Picture 5

 

This page asks us to add the following lines to the ntp.conf file:

server 0.us.pool.ntp.org server 1.us.pool.ntp.org server 2.us.pool.ntp.org server 3.us.pool.ntp.org

This is the file interface after adding the above lines:

How to install NTP server and client on Ubuntu 24.04 Picture 6

Exit the file by pressing Ctrl + X and enter y to save changes.

Step 5: Restart NTP server

For the above changes to take effect, you need to restart the NTP server. Run the following command as sudo to do so:

$ sudo service ntp restart

Step 6: Verify that the NTP server is running

Now, check the status of NTP service using the following command:

$ sudo service ntp status

How to install NTP server and client on Ubuntu 24.04 Picture 7

The Active status verifies that the NTP server is active.

Step 7: Configure the firewall so that the client can access the NTP server

Finally, it's time to configure the system's UFW firewall so that incoming connections can access the NTP server at UDP port number 123.

Run the following command as sudo to open port 123 for incoming traffic:

$ sudo ufw allow from any to any port 123 proto udp

How to install NTP server and client on Ubuntu 24.04 Picture 8

Your Ubuntu server is now configured as an NTP server.

Configure NTP client to synchronize time with NTP server

Now, let's configure the Ubuntu client to synchronize time with the NTP server.

Step 1: Install ntpdate

The ntpdate command will allow you to manually test your connection configuration with the NTP server. Open the Terminal application on the client and enter the following command as sudo:

$ sudo apt-get install ntpdate

How to install NTP server and client on Ubuntu 24.04 Picture 9

 

Step 2: Specify the IP and hostname of the NTP server in the hosts file

In order for your NTP server to resolve to the hostname in the client, you need to configure your /etc/hosts file.

Open the hosts file as sudo in the nano editor by entering the following command:

$ sudo nano /etc/hosts

Now, add the IP of the NTP server and specify the hostname as follows in this file:

How to install NTP server and client on Ubuntu 24.04 Picture 10

Exit the file by pressing Ctrl + X and then save by typing y .

Step 3: Check if the client's time is synchronized with the NTP server

The following ntpdate command will allow you to manually check if the time is synchronized between the client and server systems:

$ sudo ntpdate NTP-server-host

The ideal output would be to display the time difference between the two systems.

Step 4: Disable the systemd timesyncd service on the client

Since we want the client to synchronize time with the NTP server, let's disable the timesyncd service on the client.

Enter the following command to execute:

How to install NTP server and client on Ubuntu 24.04 Picture 11

Step 5: Install NTP on client

Run the following command as sudo to install NTP on the client:

$ sudo apt-get install ntp

Step 6: Configure the /etc/ntp.conf file to add the NTP server as a new time server

Now, we want our client to use our own NTP host server as the default time server. To do this, we need to edit the /etc/ntp.conf file on the client.

Run the following command as sudo to open the file in the Nano editor:

$ sudo nano /etc/ntp.conf

Then add the following line to the file, where NTP-server-host is the hostname you specified for your NTP server:

server NTP-server-host prefer iburst

This is what the file looks like after specifying the time server:

How to install NTP server and client on Ubuntu 24.04 Picture 12

Press Ctrl + X to close the file and type y to save changes.

Step 7: Restart NTP server

For the above changes to take effect, you need to restart the NTP service. Run the following command as sudo to do so:

$ sudo service ntp restart

Step 8: View the time sync queue

Now your client and server are configured to synchronize time. You can view the time synchronization queue by running the following command:

$ ntpq -ps

You should be able to see NTP-server-host as the time synchronization host/source in the queue.

So that's all you need to know about installing and configuring NTP to synchronize the time on your networked Ubuntu machines. The process may seem a bit complicated, but if you follow all the steps carefully, your machines will be synchronized in no time.

4.5 ★ | 2 Vote

May be interested

  • Ubuntu Server Upgrade StepsUbuntu Server Upgrade Steps
    ubuntu also constantly updates itself with newer versions. if you're using the desktop, you'll be prompted when an update is available and receive instructions on the process. however, on the server, you may not have this privilege. so updating ubuntu server will involve running a few command lines.
  • How to configure DNS Server on Ubuntu Server 11.04How to configure DNS Server on Ubuntu Server 11.04
    dns server is a server with domain name resolution function. in this article, we will detail the steps to install and configure dns server on linux with ubuntu server version 11.04.
  • How to install MySQL on Ubuntu 20.04How to install MySQL on Ubuntu 20.04
    in this article, tipsmake will show how to install mysql version 8.0 on ubuntu 20.04 server. by completing it, you'll have an active relational database that can be used to build your next website or app.
  • How to install µTorrent (uTorrent) in Ubuntu 20.04How to install µTorrent (uTorrent) in Ubuntu 20.04
    µtorrent provides clients for windows and macos x, however it is installed as a server in ubuntu linux and provides a web ui for managing downloads.
  • Use Nautilus as FTP ClientUse Nautilus as FTP Client
    the nautilus file management utility for gnome desktop can be used as an ftp client without users having to install any additional software into their system.
  • Git environment settingsGit environment settings
    before you can use git, you must install and make some configuration changes. here are the steps to install git client on ubuntu and centos linux.
  • How to install Ubuntu in parallel with Windows using USBHow to install Ubuntu in parallel with Windows using USB
    installing ubuntu in parallel with windows 7 and 8 with usb will help users not to waste time writing files to disk, running on many different computers.
  • How to install and use Jitsi Meet on Ubuntu serverHow to install and use Jitsi Meet on Ubuntu server
    jitsi meet is a free, open source video conferencing application available for use online or with desktop software. you can easily create a jitsi meeting in the browser after a few seconds.
  • How to configure NTP Server and NTP Client in Windows Server 2019How to configure NTP Server and NTP Client in Windows Server 2019
    if the computer is an active directory domain controller, the ntp server feature is enabled automatically. so, the following example is for a computer that needs to enable ntp server in a workgroup environment.
  • How to Set Up vsftpd FTP on Ubuntu LinuxHow to Set Up vsftpd FTP on Ubuntu Linux
    this tutorial will show you how to set up your own ftp in ubuntu linux. with it, you can make your own file storage server, file storage website, or use as an ftp client. install vsftpd .