NTP (stands for network time protocol) is used to synchronize the system clock of the client system with the clock of the server.
It helps the network applications to have an accurate time.
NTP is intended to synchronize all participating computers to within a few milliseconds of Coordinated Universal Time (UTC).
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu Software Installation tasks.
In this context, we shall look into how to configure an NTP server and client on Ubuntu.
Here, we need Two Ubuntu machines (For NTP host and NTP client) as well as Sudo user on both Ubuntu machines.
To install and configure the NTP server on the host machine, follow the below steps.
In order to install the NTP server, first update the local repositories on the system.
Open the command-line Terminal in the host system and execute the following command in it:
$ sudo apt update
Then provide sudo password.
Now install NTP on the host system.
Type the following command in Terminal and press Enter:
$ sudo apt install ntp
When asked for confirmation, press y, after which the system will start the installation of NTP.
Once completed, you can verify the installation from the following command:
$ sntp --version
By default, NTP is configured to pull the time from internet servers.
However, you can manually configure it to pull time from the nearest pools based on your geographical location.
i. Edit NTP configuration file as follows:
$ sudo nano /etc/ntp.conf
In the configuration file, you will see a list of pools that NTP by default uses.
ii. To add the pools nearest to your location, visit support.ntp.org website, and select your location.
iii. In the configuration file, remove the default list of pools and insert the list of pools that you have copied from the support.ntp.org website.
iv. Once you are done, press Ctrl+x. Now you will be prompted if you want to save the changes, hit y.
After making the changes to the /etc/ntp.conf file, restart the NTP service using the following command:
$ sudo service ntp restart
If a firewall is running on the NTP host, you will need to add a rule that allows NTP through it.
Execute the following command in Terminal to add a rule to the firewall:
$ sudo ufw allow ntp
To verify if the rule has been added successfully, type the following command in Terminal and press Enter:
$ sudo ufw status
Now the NTP server has been configured on the host machine.
Now let's move towards NTP client configuration.
Here, we will configure the NTP client machine to sync the clock with the NTP server.
Ntpdate command is used for one-time sync to the NTP server.
Open the Terminal in the client machine and issue the following command to install ntpdate:
$ sudo apt install ntpdate
Then enter sudo password.
When asked for confirmation, enter y, after which the system will start the installation of ntpdate.
In this step, we will manually synchronize the NTP client to the NTP server to check if time is accurate and the difference is not more than 1024 seconds.
To do so, issue the following command in Terminal replacing the <server-IP> with the actual IP address of NTP server:
$ sudo ntpdate <server-IP>
Disable the system timesyncd service as we are going to synchronize our system time with the NTP server.
Run the following command to do so:
$ sudo timedatectl set-ntp off
As you have seen form, the output of ntpdate command that time difference is very less, so we can now configure ntp.conf on the client machine to automatically sync it with the NTP server.
First, you will need to install NTP on the client machine.
Enter the following command in the Terminal:
$ sudo apt install ntp
When asked for confirmation, enter y, after which the system will start the installation of NTP.
Once completed, you can configure NTP as described in the next step.
In this step, we will configure the npt.conf to automatically synchronize the client machine with the NTP server.
In the client machine, edit the ntp.conf file as follows:
$ sudo nano /etc/ntp.conf
Add the below line in the config file replacing the <server-hostname> with your NTP server host name:
server <NTP-server-hostname> prefer iburst
Once you are done, press Ctrl+x. Now, you will be prompted if you want to save the changes, press y.
After making change to the /etc/ntp.conf file, restart the NTP service using the following command:
$ sudo service ntp restart
Now the client machine has been connected to the host system for the time synchronization.
In order to view NTP current synchronization status, run the following command in Terminal:
$ ntpq -p
This article will guide you on how to configure the NTP server on the #Ubuntu machine and then sync a clock of NTP client machine. Now you can easily set up NTP server and connect multiple client machines with it for time synchronization.
The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.
NTP is intended to synchronize all participating computers to within a few milliseconds of Coordinated Universal Time (UTC).
How do I start #NTP on Linux?
In order to add command line options to the ntpd service (/etc/init. d/ntpd), one has to edit /etc/sysconfig/ntpd file and add the desired option to the OPTIONS variable, and restart the service via 'service ntpd restart'.
What port does NTP use?
NTP time servers work within the TCP/IP suite and rely on User Datagram Protocol (UDP) port 123. NTP servers are normally dedicated NTP devices that use a single time reference to which they can synchronize a network.
This time reference is most often a Coordinated Universal Time (UTC) source.
To Sync NTP client with server via command line:
1. Edit the /etc/ntp.
2. Search for the lines beginning server .
3. Replace the server entries with the IP address or hostname of the NTP server or servers with which you want to synchronize.
4. Save the file.
5. Configure the NTP client service to start at run level 3 when the appliance boots.