by

How to setup NTP server and client on Debian 10

NTP stands for Network Time Protocol. It is a protocol or service which is used to synchronize the clock of your client machines with the clock of a server. The clock of the server is further synced to the Internet.

In this article, I am going to show how you can set up an NTP server in your environment and sync the clock with the client machines. I have executed all the commands and procedures on my Debian 10 machines.

Update Debian package repository

Open up the terminal with root privileges and run the following command to update the package repository.

apt-get update

Below is the sample output.

Update Debian repository

Install NTP server on Debian

To install an NTP server, run the following command on the terminal. When you are prompted, enter Y from the keyboard.

apt-get install ntp

Wait for the installation to finish. This may take several minutes to complete depending on your Internet speed.

Below is the sample output.

Install NTP server package with apt

Verifying an installation

You can verify the installation and version by executing the below command.

sntp --version

Restart the NTP server

Run the following command to restart the NTP server.

systemctl restart ntp

To verify whether the NTP service is actually running, execute the following command.

systemctl status ntp

Below is the sample output which shows that the NTP service is running on the server.

Configure the firewall on NTP server so that clients can access it

Open up the terminal on the NTP server and run the following command with root privileges.

iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -j ACCEPT

Below is the sample output.

Firewall configuration

Installing an NTP client

Let us configure the NTP client to be time synced with the NTP server. For this, you have to install the ntpd daemon on the client machine.

apt-get install ntpdate

Wait for the installation to finish. This could take several minutes to complete depending on your internet speed.

Below is the sample output.

Installing ntpdate

Installing an NTP on the client

Open up the terminal with root privileges and run the following command.

apt-get install ntp

Wait for the installation to finish. This may take several minutes to complete depending on the internet speed.

Below is the sample output.

Install ntp package

Once you have installed the NTP daemon on the client machine, it is now time to configure it so that its clock can be synced with the NTP server.

Run the following command to open a configuration file in the nano editor.

nano /etc/ntp.conf

Add the following lines,

server 10.1.1.1 prefer iburst

Below is the sample output after adding the above line in the configuration file.

Configure ntp client

Restart the NTP service after adding the above line by running the following command on the terminal with root privileges.

systemctl restart ntp

Restart ntp

To check the status, run the following command on the terminal.

ntpq -p

Below is the sample output.

ntpq

Conclusion

We are done with the basic configuring of an NTP server and client. Good luck!

Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

News Feed