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.

<img alt="Install NTP server package with apt" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-19-1024×539.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="395" src="data:image/svg xml,” width=”750″>

Verifying an installation

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

sntp --version

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-20-1024×50.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="37" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-22-1024×367.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="269" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Firewall configuration" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-27-1024×67.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="49" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Installing ntpdate" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-23-1024×254.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="186" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Install ntp package" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-24-1024×140.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="103" loading="lazy" src="data:image/svg xml,” width=”750″>

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.

<img alt="Configure ntp client" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-25-1024×467.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="342" loading="lazy" src="data:image/svg xml,” width=”750″>

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

systemctl restart ntp

<img alt="Restart ntp" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-26-1024×105.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="77" loading="lazy" src="data:image/svg xml,” width=”750″>

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

ntpq -p

Below is the sample output.

<img alt="ntpq" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/1-28-1024×112.png" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="82" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

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