How to Install NTP Server and Client(s) on Raspberry Pi with Ubuntu Mate

Rishabh Dev Yadav
7 min readMay 1, 2020

NTP or Network Time Protocol is a protocol that is used to synchronize all system clocks in a network to use the same time. When we use the term NTP, we are referring to the protocol itself and also the client and server programs running on the networked computers. NTP belongs to the traditional TCP/IP protocol suite and can easily be classified as one of its oldest parts.

When you are initially setting up the clock, it takes six exchanges within 5 to 10 minutes before the clock is set up. Once the clocks in a network are synchronized, the client(s) update their clocks with the server once every 10 minutes. This is usually done through a single exchange of message(transaction). These transactions use port number 123 of your system.

In this article, we will describe a step-by-step procedure on how to:

  • Install and configure the NTP server on a Ubuntu machine.
  • Configure the NTP Client to be time synced with the server.

We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system. This method will also be used for Raspberry Pi NTP setting.

Install and configure NTP Server on the host computer

Follow these steps in order to install the NTP server on your host Ubuntu machine:

Note: We are using the Ubuntu command line, the Terminal, in order to install and configure NTP. You can open the Terminal application either through the application launcher search or the Ctrl+Alt+T shortcut.

Step 1: Update repository index

In order to install the latest available version of software from the Internet repositories, your local repository index needs to be in line with them. Run the following command as sudo in order to update your local repository index:

$ sudo apt-get update

Step 2: Install NTP Server with apt-get

Please run the following command as sudo in order to install NTP server daemon from the APT repositories:

$ sudo apt-get install ntp

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

The system might ask you the password for sudo and also provide you with a Y/n option to continue the installation. Enter Y and then hit enter; NTP server will then be installed on your system. The process may, however, take some time depending on your Internet speed.

Step 3: Verify installation (optional)

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

$ sntp --version

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

When you install the NTP server, it is mostly configured to fetch proper time. However, you can switch the server pool to the ones closest to your location. This includes making some changes in the /etc/ntp.conf file.

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

$ sudo nano /etc/ntp.conf

In this file, you will be able to see a pool list. We have highlighted this list in the above image. The task here is to replace this pool list by a pool of time servers closest to your location. The project provides reliable NTP service from a big cluster of time servers. To choose a pool list according to your location, visit the following page:

For india, See here:-

Replace the highlighted text with following given text and everything will reamin same.

pool iburst
pool iburst
pool iburst
pool iburst

Quit the file by hitting Ctrl+X and then by entering y for saving changes.

Step 5: Restart the NTP server

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

$ sudo service ntp restart

Step 6: Verify that the NTP Server is running

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

$ sudo service ntp status

The Active status verifies that your NTP server is up and running.

Step 7: Configure Firewall so that client(s) can access NTP server

Finally, it is time to configure your 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

Your Ubuntu host machine is now configured to be used as an NTP server.

Configure NTP Client to be Time Synced with the NTP Server

Let us now configure our Ubuntu client machine to be time synchronized with the NTP server.

Step 1: Install ntpdate

The ntpdate command will let you manually check your connection configuration with the NTP-server. Open the Terminal application on the client machine and enter the following command as sudo:

$ sudo apt-get install ntpdate

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

For your NTP server to be resolved by a hostname in your client machine, 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 your NTP server’s IP and specify a hostname as follows in this file:

Quit the file by hitting Ctrl+X and then save it by entering y.

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

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

$ sudo ntpdate NTP-server-host

The output should ideally show a time offset between the two systems.

Step 4: Disable the systemd timesyncd service on the client

Because we want our client to sync time with the NTP server, let us disable the timesyncd service on the client machine.

Enter the following command to do so:

Step 5: Install NTP on your client

Run the following command as sudo in order to install NTP on your client machine:

$ sudo apt-get install ntp

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

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

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

$ sudo nano /etc/ntp.conf

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

server NTP-server-host prefer iburst

This is how my file looks like after I have specified the time server:

Hit Ctrl+x in order to quit the file and then enter y to save the changes.

Step 7: Restart the NTP server

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

$ sudo service ntp restart

Step 8: View the Time Synchronization Queue

Now your client and server machines are configured to be time-synced. 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 this was all you needed to know about installing and configuring NTP to synchronize time on your networked Ubuntu machines. The process may seem a little cumbersome but if you follow all of the above steps carefully, one-by-one, your machines will be synced in no time.