Install and Setup NTP Server on Ubuntu 22.04/Debian 11

|
Last Updated:
|
|

In this tutorial, you will learn how to install and setup NTP server on Ubuntu 22.04/Debian 11. Network Time Protocol is a networking protocol that is used to synchronize system clocks on a network. NTP client employs a server-client architecture where NTP clients synchronize time from NTP server(s). NTP daemon ( ntpd ) is an NTP client program.

Install and Setup NTP Server on Ubuntu 22.04/Debian 11

Install NTPd on Ubuntu 22.04/Debian 11

Once the update is done, proceed to install NTP daemon on Ubuntu 22.04/Debian 11. The ntpd daemon is provided by the ntp package.

To check if ntp package is installed on Ubuntu 22.04/Debian 11 run the command:

sudo apt update -y
 dpkg -l ntp

If the package is not installed you will get output similar to:

dpkg-query: no packages found matching ntp

The ntp package is available on the default Ubuntu 22.04 and Debian 11 repositories.

Install ntp on Ubuntu 22.04/Debian 11 by running the command:

sudo apt install ntp ntpdate ntpstat -y

Verify that that ntp package has been installed successfully by checking the version number:

sntp --version

Output:

sntp [email protected] Wed Feb 16 17:13:02 UTC 2022 (1)

Running NTPd on Ubuntu 22.04/Debian 11

After installation NTP is started and enabled to start at boot time:

systemctl status ntp

● ntp.service - Network Time Service
     Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-05-14 09:01:38 UTC; 4min 51s ago
       Docs: man:ntpd(8)
    Process: 109951 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
   Main PID: 109957 (ntpd)
      Tasks: 2 (limit: 2241)
     Memory: 1.4M
        CPU: 138ms
     CGroup: /system.slice/ntp.service
             └─109957 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 114:120

May 14 09:01:40 jellyfish ntpd[109957]: Soliciting pool server 160.119.216.206
May 14 09:01:40 jellyfish ntpd[109957]: Soliciting pool server 160.119.216.197
May 14 09:01:41 jellyfish ntpd[109957]: Soliciting pool server 2001:19f0:5401:16b:5400:3ff:fef6:2691
May 14 09:01:41 jellyfish ntpd[109957]: Soliciting pool server 64:ff9b::a077:d8ca
May 14 09:01:42 jellyfish ntpd[109957]: Soliciting pool server 64:ff9b::a077:d8ca
May 14 09:01:42 jellyfish ntpd[109957]: Soliciting pool server 91.189.94.4
May 14 09:01:43 jellyfish ntpd[109957]: Soliciting pool server 91.189.89.199
May 14 09:01:44 jellyfish ntpd[109957]: Soliciting pool server 91.189.91.157
...

Setup NTP Server on Ubuntu 22.04/Debian 11

NTP daemon (ntpd) main configuration file is /etc/ntp.conf. The file is configured to enable NTP server to fetch the correct time from NTP servers of higher stratum such as pool.ntp.org.

The pool directive in the file enables setting of NTP time servers (pool) to use.

sudo vim /etc/ntp.conf

By default NTP on Ubuntu 22.04/Debian 11 uses ubuntu pool time servers from the NTP servers pool.ntp.org;


# 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

# Use Ubuntu's ntp server as a fallback.
pool ntp.ubuntu.com

A list of time servers can be found at NTP Public Pool Time Servers where one can choose which timeserver to use according to their timezone.

First comment out the default ubuntu pool timeservers:

...
# 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

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com
...

To add up servers from the ke.pool.ntp.org pool add the following entry on the configuration file:

...
#US
server 0.us.pool.ntp.org iburst
server 1.us.pool.ntp.org iburst
server 2.us.pool.ntp.org iburst
server 3.us.pool.ntp.org iburst
...

TIP: Setting the pool as pool.ntp.org allows the system to determine the nearest time servers to use.

iburst option in the configuration file changes the initial interval of polls to a NTP server in order to speed up the initial synchronization.

Configure Access Control for NTP Server (Optional)

NTP server can optionally be configured to only allow specific NTP client connections to query them using the restrict directive in the /etc/ntp.conf configuration file which uses the syntax:

restrict address [mask mask] [other options]

This access control can be used to limit access to NTP service to particular LAN. For instance to only allow connections from the network 192.168.56.0/24, define the network address by appending the line:

restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap

Where:

  • nomodify options prevents any changes to the configuration.
  • notrap option prevents ntpdc control message protocol traps.

More about restrict and other command options can be read on man ntp.conf.

Save the configuration file and restart NTP server for the changes to take effect.

 sudo systemctl restart ntp

Confirm NTP service is set to start at boot time:

sudo systemctl is-enabled ntp
enabled

If disabled, enable it by running the command below;

sudo systemctl enable ntpd

Configure Firewall to Allow NTP Services

If Ubuntu UFW is enabled allow UDP port 123. NTP clients connect to NTP server on that particular port.

sudo ufw allow from any to any port 123 proto udp

You can as well allow NTP queries from specific Network;

sudo ufw allow from 192.168.56.0/24 to any port 123 proto udp

Verify NTP Time Service

Verify NTP server by checking the NTP server connection to NTP peers by running the command;

ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000   +0.000   0.000
+time.cloudflare 10.5.8.4         3 u   30   64  177   11.899   +0.609   7.783
*time.walb.tech  163.237.218.18   2 u   30   64  175  245.101   -1.475  26.302
+167-248-49-102. 129.6.15.27      2 u   28   64  177  285.856   -0.663  12.947
-50-205-244-112- 50.205.244.27    2 u   25   64  177  315.383  -25.764  20.901
-chilipepper.can 17.253.34.123    2 u   48   64  177  275.317  -52.046  39.830
-alphyn.canonica 142.3.100.2      2 u   40   64  177  274.640   -9.207  13.777
+pugot.canonical 17.253.108.125   2 u   44   64  177  179.313   -3.865  10.417
-golem.canonical 17.253.108.253   2 u   40   64  127  274.772  -51.738  50.008

Synchronizing Client’s System Time with NTP Server

Now that the NTP server is configured, it is high time to configure clients to synchronize their clocks with the NTP server.

Install and Configure NTP Client on Ubuntu/Debian systems

That concludes our guide on how to install and setup NTP server on Ubuntu/Debian.

Related Tutorials

How to Configure NTP Server on pfSense

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment