This article explains how to set up NTP server and client on Ubuntu 24.04.
A Network Time Protocol (NTP) server is designed to synchronize the clocks of computers and other devices over a network. It enables devices to request the current time from the server, which obtains the accurate time from a reliable source, such as an atomic clock.
NTP ensures that all devices on the network have accurate, synchronized time, which is crucial for time-sensitive operations. It helps maintain consistent timestamps across systems, essential for logging events, security protocols, and preserving data integrity.
Install NTP server
There are multiple NTP servers one can use on Ubuntu systems. Users can use [NTPsec] or [Chrony].
You can pick one of the two to use in your environment.
Install NTPsec
Run the command below to install NTPsec.
sudo apt install ntpsec
After installing NTPsec, you can find its configuration file at the following location: [/etc/ntpsec/ntp.conf
].
Install Chrony
To install Chrony, run the command below.
sudo apt install chrony
After installing Chrony, you can find its configuration file at the following location: [/etc/chrony/chrony.conf
].
Configure NTP server
Once the NTP server is installed, open its configuration file and add the highlighted lines.
NTPsec configuration
Comment out [#] the bold lines to disable the default NTP pool. Then, add the pool you want to use.
# Comment this out if you have a refclock and want it to be able to discipline
# the clock by itself (e.g. if the system is not connected to the network).
#tos minclock 4 minsane 3
# Specify one or more NTP servers.
# Public NTP servers supporting Network Time Security:
# server time.cloudflare.com nts
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See https://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
pool time.nist.gov iburst
# Use Ubuntu's ntp server as a fallback.
#server ntp.ubuntu.com
Save and exit the file.
Check the status.
ntpq -p
Chrony configuration
Comment out [#] the bold lines to disable the default NTP pool. Then, add the pool you want to use.
# About using servers from the NTP Pool Project in general see (LP: #104525).
# Approved by Ubuntu Technical Board on 2011-02-08.
# See http://www.pool.ntp.org/join.html for more information.
#pool ntp.ubuntu.com iburst maxsources 4
#pool 0.ubuntu.pool.ntp.org iburst maxsources
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2
pool time.nist.gov iburst
# add this line to allow all clients on network
allow 192.168.156.0/24
Save the file and exit.
Restart Chrony
sudo systemctl restart chrony
Check status.
chronyc sources
Set up NTP client
Now that the NTP server is set up, you can configure your Ubuntu client to synchronize its time with the server.
There’s no additional software to install on the client.
Run the command below to open the NTP client configuration file.
sudo nano /etc/systemd/timesyncd.conf
Then, add the local server name in the file.
[Time]
NTP=srv1.example.com
Save the file and exit.
Restart the services.
sudo systemctl restart systemd-timesyncd
Check status.
timedatectl timesync-status
You should see output similar to the one below.
Server: 192.168.156.130 (srv1.example.com)
Poll interval: 1min 4s (min: 32s; max 34min 8s)
Leap: normal
Version: 4
Stratum: 2
Reference: 84A36006
Precision: 1us (-26)
Root distance: 16.433ms (max: 5s)
Offset: +2.247ms
Delay: 380us
Jitter: 0
Packet count: 1
Frequency: +31.702ppm
That should do it!
Conclusion:
Setting up an NTP server and client on Ubuntu 24.04 ensures that your devices maintain accurate time synchronization, which is vital for various network operations. Here are the key points to remember:
- NTP Importance: Essential for keeping accurate, synchronized time across devices.
- Server Options: Choose between NTPsec and Chrony based on your needs.
- Configuration: Adjust the configuration files to specify desired NTP servers and settings.
- Client Setup: No additional software is required; simple configuration is sufficient.
- Verification: Use commands to check the status and ensure synchronization works correctly.
- Benefits of Accuracy: Consistent timestamps contribute to better security protocols, logging, and data integrity.
Following the outlined steps, you can successfully establish a reliable NTP setup to enhance your network’s time management.
Leave a Reply