Setup NTP Server on Debian 11

This article is going to take you through on how to Setup NTP Server on Debian 11. The Network Time Protocol (NTP) is a networking protocol that synchronizes computer clocks across packet-switched, variable-latency data networks. NTP is designed to keep all participating computers within a few milliseconds of Coordinated Universal Time (UTC).

How to Setup NTP Server on Debian 11

  • Update your packages.
sudo apt update
  • Then, using the command below, install the NTP server.
sudo apt install ntp

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libopts25 sntp
Suggested packages:
  ntp-doc
The following packages will be REMOVED:
  systemd-timesyncd
The following NEW packages will be installed:
  libevent-core-2.1-7 libevent-pthreads-2.1-7 libopts25 ntp sntp
0 upgraded, 5 newly installed, 1 to remove and 3 not upgraded.
Need to get 1,221 kB of archives.
After this operation, 2,841 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://deb.debian.org/debian bullseye/main amd64 libevent-core-2.1-7 amd64 2.1.12-stable-1 [139 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 libevent-pthreads-2.1-7 amd64 2.1.12-stable-1 [57.1 kB]
Get:3 http://deb.debian.org/debian bullseye/main amd64 libopts25 amd64 1:5.18.16-4 [69.2 kB]
Get:4 http://deb.debian.org/debian bullseye/main amd64 ntp amd64 1:4.2.8p15+dfsg-1 [785 kB]
Get:5 http://deb.debian.org/debian bullseye/main amd64 sntp amd64 1:4.2.8p15+dfsg-1 [171 kB]
Fetched 1,221 kB in 1s (894 kB/s)
(Reading database ... 142539 files and directories currently installed.)
Removing systemd-timesyncd (247.3-7) ...
Selecting previously unselected package libevent-core-2.1-7:amd64.
(Reading database ... 142527 files and directories currently installed.)
Preparing to unpack .../libevent-core-2.1-7_2.1.12-stable-1_amd64.deb ...
Unpacking libevent-core-2.1-7:amd64 (2.1.12-stable-1) ...
Selecting previously unselected package libevent-pthreads-2.1-7:amd64.
Preparing to unpack .../libevent-pthreads-2.1-7_2.1.12-stable-1_amd64.deb ...
Unpacking libevent-pthreads-2.1-7:amd64 (2.1.12-stable-1) ...
Selecting previously unselected package libopts25:amd64.
Preparing to unpack .../libopts25_1%3a5.18.16-4_amd64.deb ...
Unpacking libopts25:amd64 (1:5.18.16-4) ...
Selecting previously unselected package ntp.
Preparing to unpack .../ntp_1%3a4.2.8p15+dfsg-1_amd64.deb ...
Unpacking ntp (1:4.2.8p15+dfsg-1) ...
Selecting previously unselected package sntp.
Preparing to unpack .../sntp_1%3a4.2.8p15+dfsg-1_amd64.deb ...
Unpacking sntp (1:4.2.8p15+dfsg-1) ...
Setting up libopts25:amd64 (1:5.18.16-4) ...
Setting up ntp (1:4.2.8p15+dfsg-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/ntp.serv
ice → /lib/systemd/system/ntp.service.

Configure NTP server

  • Switch to the nearest server pool by editing NTP config file. Check out the closest server pool to your continent in the NTP pool project.
  • Using the command below, open the config file;
sudo nano /etc/ntp.conf
  • replace the existing pools
# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
  • with one nearest to you. For example Africa/South Africa;
# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
server 0.za.pool.ntp.org
server 1.za.pool.ntp.org
server 2.za.pool.ntp.org
server 3.za.pool.ntp.org
  • Restart the NTP server using the following command to apply changes.
sudo systemctl restart ntp
  • NTP server should be up and running, you can check status using the following command.
sudo systemctl status ntp

Sample output

● ntp.service - Network Time Service
     Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-04-19 20:30:26 EAT; 9s ago
       Docs: man:ntpd(8)
    Process: 5151 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
   Main PID: 5157 (ntpd)
      Tasks: 2 (limit: 4623)
     Memory: 932.0K
        CPU: 32ms
     CGroup: /system.slice/ntp.service
             └─5157 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 124:131

Apr 19 20:30:26 debian ntpd[5157]: Listen and drop on 0 v6wildcard [::]:123
Apr 19 20:30:26 debian ntpd[5157]: Listen and drop on 1 v4wildcard 0.0.0.0:123
Apr 19 20:30:26 debian ntpd[5157]: Listen normally on 2 lo 127.0.0.1:123
Apr 19 20:30:26 debian ntpd[5157]: Listen normally on 3 ens33 192.168.0.103:123
Apr 19 20:30:26 debian ntpd[5157]: Listen normally on 4 lo [::1]:123

Configure Firewall for NTP server clients

  • Next allow NTP on firewall using the command below.
sudo ufw allow from any to any port 123 proto udp
  • Then reload the firewall to apply the changes
sudo ufw reload

Configure NTP Client

  • Install NTP update on your client machine using the command below.
sudo apt install ntpdate
  • Next disable the systemd timesyncd service on the client.
sudo timedatectl set-ntp off
  • Then install NTP on your client system.
sudo apt install ntp
  • After the installation, use the command below to add the NTP server IP to the client’s config file. Please note that the IP address below should be replaced with the IP address of your actual server.
sudo bash -c "echo server 192.168.0.103 prefer iburst >> /etc/ntp.conf"
  • To apply changes, restart your NTP client.
sudo systemctl restart ntp
  • Now that the client and server are in sync, you can use the following command to list the time synchronization queue.
ntpq -p

Sample output

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000   +0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000   +0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000   +0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000   +0.000   0.000
*192.168.0.103     91.189.89.199    3 u    1   64    1    0.398  +69.481   1.909
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000   +0.000   0.000
  • The NTP server with asterisk, *, is the preferred NTP server.
  • This concludes our article; congratulations! You’ve learnt how to Setup NTP server on Debian 11 and how to configure a client to use the NTP server for time synchronization.

Read more on NTP Documentation

Other Tutorials

Setup NTP Server on Ubuntu 22.04

Install KVM on Ubuntu 22.04

Install Cacti on Ubuntu 22.04

Install NFS Server on Rocky Linux

System administrator | Software Developer | DevOps

Leave a Comment