This article is going to take you through on how to setup NTP server on Ubuntu 22.04. The Network Time Protocol (NTP) is a networking protocol that allows computer systems to synchronize their clocks over packet-switched, variable-latency data networks. NTP is designed to keep all participating computers in sync with Coordinated Universal Time to within a few milliseconds (UTC).
How to Setup NTP Server on Ubuntu 22.04
- Update your packages.
sudo apt update
- Then start by installing NTP sever using the command below.
sudo apt install ntp
Sample output
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: fonts-open-sans gir1.2-gnomebluetooth-1.0 i965-va-driver intel-media-va-driver kwayland-data libaacs0 libavcodec58 libavformat58 libavutil56 libbdplus0 libbluray2 libchromaprint1 libcodec2-1.0 libdouble-conversion3 libgme0 libgsm1 libigdgmm12 libkf5waylandclient5 libmd4c0 libmfx1 libminizip1 libmng2 libnorm1 libopenal-data libopenal1 libopenmpt0 libpcre2-16-0 libpgm-5.3-0 libqrcodegencpp1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5waylandclient5 libqt5widgets5 librabbitmq4 librlottie0-1 libshine3 libsndio7.0 libsrt1.4-gnutls libssh-gcrypt-4 libswresample3 libswscale5 libudfread0 libva-drm2 libva-x11-2 libva2 libvdpau1 libx264-163 libxcb-record0 libxcb-screensaver0 libxcb-xinerama0 libxcb-xinput0 libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers mesa-vdpau-drivers qt5-gtk-platformtheme qt5-image-formats-plugins qttranslations5-l10n va-driver-all vdpau-driver-all Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: 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-pthreads-2.1-7 libopts25 ntp sntp 0 upgraded, 4 newly installed, 1 to remove and 0 not upgraded. Need to get 855 kB of archives. After this operation, 2,298 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libevent-pthreads-2.1-7 amd64 2.1.12-stable-1build3 [7,642 B] Get:2 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 libopts25 amd64 1:5.18.16-4 [59.5 kB] Get:3 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 ntp amd64 1:4.2.8p15+dfsg-1ubuntu2 [721 kB] Get:4 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 sntp amd64 1:4.2.8p15+dfsg-1ubuntu2 [67.1 kB] Fetched 855 kB in 2s (543 kB/s)
Configure NTP server
- You need to edit NTP configuration file so as to switch the server pool to the nearest to your location. Check out the closest server pool in the NTP pool project.
- Next open the config file using the command below;
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
- Save and exit the file then restart using the following command to apply the 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 12:09:59 EAT; 40s ago Docs: man:ntpd(8) Process: 17092 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS) Main PID: 17098 (ntpd) Tasks: 2 (limit: 4588) Memory: 1.7M CPU: 40ms CGroup: /system.slice/ntp.service └─17098 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 136:142 Apr 19 12:09:59 nfs.itnixpro.com ntpd[17098]: Listen normally on 5 ens33 [fe80::9aac:4f1f:e53f:6f70%2]:123 Apr 19 12:09:59 nfs.itnixpro.com ntpd[17098]: Listening on routing socket on fd #22 for interface updates Apr 19 12:09:59 nfs.itnixpro.com systemd[1]: Started Network Time Service.
Configure Firewall for NTP server clients
- By default NTP uses UDP port 123, allow it 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
- On your client machine, install ntp update using the command below.
sudo apt install ntpdate
- Then, on the client, disable the systemd timesyncd service.
sudo timedatectl set-ntp off
If you get the error, Failed to set ntp: NTP not supported, it means the systemd-timesyncd
package is not installed.
- Next install NTP on your client machine using the following command.
sudo apt install ntp
- After installation, add the NTP server IP in the config file of client using the command below. Note, replace the IP below with your real server IP.
sudo bash -c "echo server 192.168.0.102 prefer iburst >> /etc/ntp.conf"
- Restart your client NTP to apply changes.
sudo systemctl restart ntp
- Client and server are now time synced, you can now list time synchronization queue using the following command.
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 ntp.ubuntu.com .POOL. 16 p - 64 0 0.000 0.000 0.000 *192.168.0.102 45.85.15.7 3 u 7 64 1 0.814 20.104 2.456 +ntp1.icolo.io 160.119.217.233 2 u 8 64 1 160.110 2.589 3.836 -time.cloudflare 10.45.8.244 3 u 7 64 1 75.876 70.824 3.723 +ntp2.icolo.io 160.119.217.235 2 u 10 64 1 165.686 2.488 2.041 -time.cloudflare 10.45.8.244 3 u 7 64 1 76.056 70.700 4.050 +ntp0.icolo.io 160.119.217.235 2 u 6 64 1 159.742 2.521 3.607 pugot.canonical 17.253.108.125 2 u 14 64 1 184.065 77.148 0.000 chilipepper.can 131.188.3.220 2 u 15 64 1 184.208 70.749 0.000 golem.canonical 131.188.3.220 2 u 11 64 1 175.551 75.483 0.000 alphyn.canonica 17.253.34.123 2 u 12 64 1 246.788 75.892 0.000
- As you can see, out NTP server, 192.168.0.102 is the preferred NTP server for the client. This is depicted by asterisk (*).
*192.168.0.102 45.85.15.7 3 u 7 64 1 0.814 20.104 2.456
- This marks the end of our article, Congratulations! You have learned how to Setup NTP Server on Ubuntu 22.04 and also how to configure client to sync time from the NTP server.
Read more on NTP Documentation