How to set up NTP Server and Client on Debian 11

NTP stands for Network Time Protocol. It is a protocol or service used to synchronize the clock of your client computers with the clock of a server. The server's clock is also synchronized with the Internet.

In this article, I'll show you how to set up an NTP server in your environment and synchronize the clock with the client machines. I have run all the commands and procedures on my Debian 11 machines.

Update Debian package repository

before we start installing new packages, we should take care that the Debian repository lists are updated. Open up the terminal with root privileges and run the following command to update the package repository.

apt-get update

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

Configuring the NTP client

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 to 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!