Press "Enter" to skip to content

Ubuntu 24.04 NTP Configuration

Last updated on August 11, 2024

Pre-Check

## check OS/kernel version
root@baseline:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04 LTS
Release:    24.04
Codename:   noble

root@baseline:~# uname -r
6.8.0-39-generic

Intall & Configure NTP Service

## install ntp service
➜  ~ apt install ntp -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-6.8.0-31 linux-headers-6.8.0-31-generic linux-image-6.8.0-31-generic linux-modules-6.8.0-31-generic linux-modules-extra-6.8.0-31-generic linux-tools-6.8.0-31 linux-tools-6.8.0-31-generic
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  ntpsec python3-ntp
Suggested packages:
  certbot ntpsec-doc ntpsec-ntpviz
The following packages will be REMOVED:
  systemd-timesyncd
The following NEW packages will be installed:
  ntp ntpsec python3-ntp
0 upgraded, 3 newly installed, 1 to remove and 4 not upgraded.
Need to get 462 kB of archives.
After this operation, 1,183 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports noble/universe arm64 python3-ntp arm64 1.2.2+dfsg1-4build2 [99.1 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports noble/universe arm64 ntpsec arm64 1.2.2+dfsg1-4build2 [347 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports noble/universe arm64 ntp all 1:4.2.8p15+dfsg-2~1.2.2+dfsg1-4build2 [15.7 kB]
Fetched 462 kB in 2s (209 kB/s)
(Reading database ... 174669 files and directories currently installed.)
Removing systemd-timesyncd (255.4-1ubuntu8.2) ...
Selecting previously unselected package python3-ntp.
(Reading database ... 174653 files and directories currently installed.)
Preparing to unpack .../python3-ntp_1.2.2+dfsg1-4build2_arm64.deb ...
Unpacking python3-ntp (1.2.2+dfsg1-4build2) ...
Selecting previously unselected package ntpsec.
Preparing to unpack .../ntpsec_1.2.2+dfsg1-4build2_arm64.deb ...
Unpacking ntpsec (1.2.2+dfsg1-4build2) ...
Selecting previously unselected package ntp.
Preparing to unpack .../ntp_1%3a4.2.8p15+dfsg-2~1.2.2+dfsg1-4build2_all.deb ...
Unpacking ntp (1:4.2.8p15+dfsg-2~1.2.2+dfsg1-4build2) ...
Setting up python3-ntp (1.2.2+dfsg1-4build2) ...
Setting up ntpsec (1.2.2+dfsg1-4build2) ...
Created symlink /etc/systemd/system/timers.target.wants/ntpsec-rotate-stats.timer → /usr/lib/systemd/system/ntpsec-rotate-stats.timer.
Created symlink /etc/systemd/system/network-pre.target.wants/ntpsec-systemd-netif.path → /usr/lib/systemd/system/ntpsec-systemd-netif.path.
Created symlink /etc/systemd/system/ntp.service → /usr/lib/systemd/system/ntpsec.service.
Created symlink /etc/systemd/system/ntpd.service → /usr/lib/systemd/system/ntpsec.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ntpsec.service → /usr/lib/systemd/system/ntpsec.service.
Setting up ntp (1:4.2.8p15+dfsg-2~1.2.2+dfsg1-4build2) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for dbus (1.14.10-4ubuntu4) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

## get current timezone
➜  ~ timedatectl
               Local time: Sat 2024-08-10 08:02:19 UTC
           Universal time: Sat 2024-08-10 08:02:19 UTC
                 RTC time: Sat 2024-08-10 16:01:14
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: n/a
          RTC in local TZ: no
          
## change timezone
➜  ~ timedatectl list-timezones | grep -i 'hong'
Asia/Chongqing
Asia/Hong_Kong
Hongkong

➜  ~ timedatectl set-timezone Asia/Hong_Kong

➜  ~ timedatectl
               Local time: Sat 2024-08-10 16:04:56 HKT
           Universal time: Sat 2024-08-10 08:04:56 UTC
                 RTC time: Sat 2024-08-10 16:03:50
                Time zone: Asia/Hong_Kong (HKT, +0800)
System clock synchronized: yes
              NTP service: n/a
          RTC in local TZ: no

## restart ntp.service
➜  ~ systemctl daemon-reload
➜  ~ systemctl restart ntp.service

Evaluate

➜  ~ ntpq -p
     remote                                   refid      st t when poll reach   delay   offset   jitter
=======================================================================================================
 0.ubuntu.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 1.ubuntu.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 2.ubuntu.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 3.ubuntu.pool.ntp.org                   .POOL.          16 p    -  256    0   0.0000   0.0000   0.0001
 prod-ntp-4.ntp1.ps5.canonical.com       .DNS4.          16 u    -   64    0   0.0000   0.0000   0.0001
+time.neu.edu.cn                         .PTP.            1 u   28   64    3  54.7568 -60.9588  10.6517
 time.cloudflare.com                     .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
 time.cloudflare.com                     .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
+111.230.189.174                         100.122.36.196   2 u   28   64    3  15.0999 -61.2628  10.9106
*dns2.synet.edu.cn                       .BDS.            1 u   25   64    3  49.3385 -62.4338   9.7895
-117.80.231.60                           133.243.238.243  2 u   26   64    3  32.0290 -64.2971  10.2292
 ntp8.flashdance.cx                      .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
 ntp1.flashdance.cx                      .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
 electrode.felixc.at                     .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
 ntp7.flashdance.cx                      .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
-1.117.63.30                             85.199.214.102   2 u   27   64    3  35.0258 -62.3482  10.5312
 ntp6.flashdance.cx                      .INIT.          16 u    -   64    0   0.0000   0.0000   0.0001
+time.neu.edu.cn                         .PTP.            1 u   24   64    3  51.0604 -62.1028  10.1884

➜  ~ date
Sat Aug 10 04:08:56 PM HKT 2024

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *