NTP, or Network Time Protocol, is a protocol used to synchronize all system clocks in a network to use the same time. When we use the term NTP, we refer to the protocol itself and 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 to sync with NTP, 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 messages (transaction). These transactions use port number 123 of your system.
In this article, we will describe a step-by-step procedure on how to:
We have run the commands and procedures mentioned in this article on a Ubuntu 22.04 LTS system. and Ubuntu 24.04
Follow these steps to install the NTP server on your Ubuntu server machine:
Note: We are using the Ubuntu command line, the Terminal, to install and configure NTP. You can open the Terminal application either through the application launcher search or the Ctrl+Alt+T shortcut.
To install the latest software versions from the Internet repositories, your local repository index must align with them. Run the following command as sudo in order to update your local repository index:
$ sudo apt update
Please run the following command as sudo in order to install the NTP server daemon from the APT repositories:
$ sudo apt install ntp
Please note that only an authorized user can add, remove and configure software on Ubuntu.
The system might ask you for the sudo password and provide you with a Y/n option to continue the installation. Enter Y and then hit enter; the NTP server will then be installed on your system. The process may, however, take some time, depending on your Internet speed.
You can verify your NTP installation and also check the version number by running the following command in your Terminal:
$ sntp --version
When you install the NTP server, it is mostly configured to fetch the 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 the 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 pol.ntp.org 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:
https://support.ntp.org/bin/view/Servers/NTPPoolServers
We have searched for a pool list for the US:
The page tells 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 how my file looks after adding the above lines to it:
Quit the file by hitting Ctrl+X and entering y to save changes.
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
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.
Finally, it is time to configure your system’s UFW firewall so 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 as an NTP server.
Let us now configure our Ubuntu client machine to be time-synchronized with the NTP server.
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
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.
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.
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:
Run the following command as sudo in order to install NTP on your client machine:
$ sudo apt-get install ntp
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 to close the file and enter y to save the changes.
In order 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
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, your machines will be synced in no time.
Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…
ISPConfig is an open-source control panel that allows users to manage multiple servers from a…
As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…
Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…
Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…
phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…