HTML & CSS 4h ago 1 views 4 min read

How to configure NTP on Ubuntu 24.04

Set up and verify the Chrony time synchronization service on Ubuntu 24.04 to ensure your server clock stays accurate.

Riya K.
Updated 4h ago
Sponsored

Cloud Hosting — blazing fast websites

Fully managed cloud hosting with free SSL, auto-backups and a friendly cPanel. Built for WordPress, Laravel and custom PHP apps.

Configure the Chrony service to synchronize your system clock with reliable NTP servers. This guide covers installing the package, editing configuration files, and verifying the connection on Ubuntu 24.04.

Prerequisites

  • Operating System: Ubuntu 24.04 (Jammy Jellyfish) or newer.
  • Privileges: A user account with sudo privileges.
  • Network: Internet connectivity to reach public NTP pools or your internal time server.

Step 1: Install Chrony

Update your package index to ensure you get the latest version of the time synchronization software. Then install the chrony package using apt. Chrony is the standard NTP daemon for modern Linux distributions like Ubuntu.

sudo apt update
sudo apt install chrony -y

After the installation completes, the chrony service will be installed but not started automatically. You will need to enable and start the service to begin synchronization.

Step 2: Start and Enable the Service

Start the chrony service immediately to begin syncing the system clock. Then enable it to start automatically on system boot so the time remains accurate after a reboot.

sudo systemctl start chrony
sudo systemctl enable chrony

You will see output indicating the service status. A successful start shows active (running). If the service fails to start, check the logs in the next steps.

Step 3: Configure NTP Servers

Edit the main configuration file located at /etc/chrony/chrony.conf. This file defines which time servers your system should query. By default, Ubuntu includes a list of public pools, but you may want to add specific servers or restrict access.

sudo nano /etc/chrony/chrony.conf

Inside the file, locate the lines starting with server. These lines specify the NTP servers. You can uncomment existing entries by removing the # symbol or add new ones. For production environments, it is recommended to use multiple servers for redundancy. Add the following lines at the top of the file if you want to use public pools:

# Use the default Ubuntu public pools
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

If you are setting up an internal time server, add a line like this instead:

server 192.168.1.10 iburst

Save and close the file by pressing Ctrl+X, then Y, then Enter in the nano editor. Reload the configuration to apply changes without stopping the service.

sudo systemctl reload chrony

Step 4: Restrict Access (Optional)

For security, restrict which clients can query your NTP service if this server acts as a time source for others. Add the following lines to the chrony.conf file to allow queries from the local network and the subnet of the server itself.

allow 192.168.0.0/16
allow 127.0.0.1
deny all

Replace 192.168.0.0/16 with your specific network range. After editing, reload the service again to apply the new restrictions.

Verify the installation

Check the current status of the chrony service to ensure it is running and syncing. Look for the output showing the number of sources found and the synchronization status.

sudo systemctl status chrony

You should see a line stating Active: active (running). To see detailed statistics about the synchronization, including the offset and jitter, run the following command. This shows how far your local clock is from the NTP server.

chronyc tracking

Expected output looks like this:

leap fractional-second-sync status: 0
reference time: 2024-05-20 14:30:00.123456789
root distance: 0.001234 s
reference ID: 192.168.1.10
sync status: synchronized

The sync status: synchronized line confirms that the system clock is locked to the NTP server. If it says unsynchronized, the connection to the server is failing.

Troubleshooting

If the service fails to start or sync, check the logs for errors. The most common issues are network connectivity, firewall blocks, or misconfigured server addresses.

Error: Service not found or failed.
Fix: Ensure the package is installed. Run sudo apt install chrony again. Then check if the service is enabled with sudo systemctl is-enabled chrony.
Error: chronyc: unable to set reference time
Fix: Your system cannot reach the NTP server. Check your internet connection and ensure port 123 (UDP) is not blocked by a firewall. Run sudo ufw allow 123/udp if using UFW.
Error: chrony: cannot find source
Fix: Verify the server addresses in /etc/chrony/chrony.conf. Ensure the iburst flag is present on public pool entries, as it speeds up the initial synchronization. Restart the service after changes with sudo systemctl restart chrony.

To force an immediate resync after fixing configuration errors, use the following command:

sudo chronyc makestep

This command instantly adjusts your system clock to match the NTP server, ignoring the gradual drift. Use this only when necessary, as it can disrupt scheduled tasks depending on the time adjustment size. Monitor the chronyc tracking output again to confirm the offset has reduced to near zero.

sudo chronyc tracking

Ensure the offset value is stable and the sync status remains synchronized. If the offset fluctuates wildly, your internet connection may be unstable or the NTP server may be unreachable.

Sponsored

Windows Dedicated Server

High-performance Windows dedicated servers with licensed Windows Server, Remote Desktop access and enterprise-grade hardware.

Tags: securityLinuxUbuntuSysadminNTP
0
Was this helpful?

Related tutorials

Comments 0

Login to leave a comment.

No comments yet — be the first to share your thoughts.