Configure NTP Server and Client on Debian 12 Bookworm – Easy Steps

This tutorial intends to teach you to Configure NTP Server and Client on Debian 12 Bookworm. NTP is a popular time synchronization protocol that is used to sync clock time through a network. It makes sure that all systems connected to the network maintain synchronized clocks and coordinate distributed systems. An NTP Client is a system that connects to an NTP server to receive accurate time information.

In this guide, from Orcacore, we want to teach you how to Configure NTP Server and Client on Debian 12. Also, for Time synchronization on Debian 12, you can use the following guide:

Set Up Time Synchronization on Debian 12 Bookworm

How To Configure NTP Server and Client on Debian 12 Bookworm?

To complete this guide, you must have access to your server as a non-root user with sudo privileges. To do this, you can follow this guide on Initial Server Setup with Debian 12 Bookworm.

Step 1 – Install NTP Server on Debian 12

First, you must run the system update by using the command below:

sudo apt update

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

sudo apt install ntp -y

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

ntpd --version

In your output you will see something similar to this:

Output
ntpd ntpsec-1.2.2

Step 2 – How To Check NTP Server Status?

At this point, restart the NTP server on Debian 12 with the following command:

sudo systemctl restart ntp

Verify that the NTP server is active and running on Debian 12 with the command below:

sudo systemctl status ntp
Output
● ntpsec.service - Network Time Service
     Loaded: loaded (/lib/systemd/system/ntpsec.service; enabled; preset: enabl>
     Active: active (running) since Tue 2023-07-04 04:25:16 EDT; 9s ago
       Docs: man:ntpd(8)
    Process: 790 ExecStart=/usr/libexec/ntpsec/ntp-systemd-wrapper (code=exited>
   Main PID: 793 (ntpd)
      Tasks: 1 (limit: 4653)
     Memory: 10.5M
        CPU: 165ms
     CGroup: /system.slice/ntpsec.service
...

Step 3 – Configure iptables for NTP Server

At this point, you need to configure the firewall on the NTP server so that clients can access it. NTP uses 123/UDP. 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

Note: If you don’t have iptables installed on your server, you can install it with the command below:

sudo apt install iptables

When you are done, log in to your Client machine and proceed to the next step to install the NTP client.

Step 4 – Install NTP Client on Debian 12

At this point, you need to configure the NTP client to be time-synced with the NTP server. So you have to install the ntpd service on the client machine with the following command:

Here our client machine is Debian 12 too.

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.

Step 5 – How To Sync NTP Client with NTP Server on Debian 12?

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 Client configuration file with your favorite text editor, here we use vi editor:

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 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:

sudo systemctl restart ntp

Verify Synced NTP Server and Client Clock

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

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 have learned to Configure NTP Server and Client on Debian 12 Bookworm. You have learned to install NTP on both the Debian 12 server and client and sync the clock between them.

Hope you enjoy it. You may like these articles:

Set up Time Synchronization on AlmaLinux 9

Back up and Restore FileSystem With Timeshift on Ubuntu 22.04

How To Fix the Linux Time change After Reboot

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!