Set up and configure NTP Server and Client on Debian 11

In this article, we want to teach you how to Set up and configure NTP Server and Client on Debian 11.

NTP stands for Network Time Protocol which is running on any server/computer platform.

It is applied to the network appliance (tray mount, rack, etc), which acquires and uses time from an external source to maintain time within its local internal clock, and then supplies the time it’s a connected network.

Set up and configure NTP Server and Client on Debian 11

Before you start this guide, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article about the Initial Server Setup with Debian 11.

Install NTP Server on Debian 11

First, you need t update the local package index with the following command:

sudo apt update

Then, install the NTP server on Debian 11 with the following command:

sudo apt install ntp

Now you can verify your installation by checking the NTP version:

sntp --version

In your output you will see something similar to this:

Output
sntp 4.2.8p15@1.3728-o Wed Sep 23 11:46:38 UTC 2020 (1)

Here you need to restart the NTP server on Debian 11 with the following command:

systemctl restart ntp

Verify that the NTP server is active and running on Debian 11:

systemctl status ntp
Output
ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-11-06 05:28:26 EDT; 10s ago
Docs: man:ntpd(8)
Process: 5715 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 5721 (ntpd)
Tasks: 2 (limit: 2340)
Memory: 948.0K
CPU: 34ms
CGroup: /system.slice/ntp.service
└─5721 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 107:113

At this point, you need to configure the firewall on the NTP server so that clients can access it. To do this, run the following commands:

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

Install an NTP Client

Here you need to configure the NTP client to be time synced with the NTP server. To do this, you have to install the ntpd service on the client machine with the following command:

sudo apt install ntpdate

Then, install the NTP on your client machine:

sudo apt install ntp

After your installation is finished, let’s configure the NTP client.

Configure the NTP Client

It is now time to configure the NTP client so that its clock can be synced with the NTP server.

You need to open the NTP configuration file with your favorite text editor, here we use vi:

sudo vi /etc/ntp.conf

You need to comment on the pool lines and add the “server server-ip-address prefer iburst” to the file like as shown below:

...
#pool 0.debian.pool.ntp.org iburst
#pool 1.debian.pool.ntp.org iburst
#pool 2.debian.pool.ntp.org iburst
#pool 3.debian.pool.ntp.org iburst
server server-ip-address prefer iburst
...

When you are finished, save and close the file.

Now you need to restart the NPT client to apply the changes:

systemctl restart ntp

Then, you can check the status that its clock synced with the NTP server on Debian 11:

ntpq -p
Output
remote         refid  st t  when poll reach delay offset jitter
==============================================================================
server-ip-address     ...

For more information, you can visit the official NTP documentation.

Conclusion

At this point, you learn to Install and Configure the NTP server and Client on Debian 11.

Hope you enjoy it.

You may be interested in these articles on the orcacore website:

Install and Configure NTP Server and Client on Centos 7

Install and Configure NTP Server and Client on AlmaLinux 8

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!