[stordis-toc]
Introduction
Network Time Protocol (NTP) keeps the clocks of all devices in your network synchronized. A local NTP server gives one time source to your switches, servers and lab machines.
Synchronized clocks are important during troubleshooting. When the logs of all devices use the same time, you can find which device failed first and how the problem moved through the network.
This guide shows how to install and configure an NTP server on Ubuntu 24.04 and how to connect clients to it.
NOTE
In Ubuntu 24.04, the ntp package installs NTPsec. NTPsec is a secure version of the classic NTP daemon. The configuration file is /etc/ntpsec/ntp.conf. The file /etc/ntp.conf from older guides is not used.
Prerequisites
- A server or virtual machine with Ubuntu 24.04.
- A user account with sudo rights.
- A static IP address on the server. Clients use this address.
- Access to upstream time sources on UDP port 123: public NTP servers on the internet or a time server in your company.
What you need
- The IP address of the NTP server.
- The network address of your clients, for example
192.168.1.0/24. - The addresses of the upstream time sources, if you do not use the default public pool.
Step 1: Update the system
sudo apt update && sudo apt upgrade -y
Step 2: Install NTPsec
sudo apt install ntpsec -y
The command sudo apt install ntp installs the same software.
Only one time service must run on the server. If apt shows that it removes systemd-timesyncd, this is correct.
Step 3: Set the upstream time sources
Open the configuration file:
sudo nano /etc/ntpsec/ntp.conf
The default file uses public pool servers. These are the lines that start with pool. If your server has internet access, you can keep them and go to Step 4.
To use your own time sources:
- Put
#at the start of eachpoolline. - Add one
serverline for each time source:
server <time-source-IP-or-name> iburst
Example with the public NTP pool:
server 0.pool.ntp.org iburst server 1.pool.ntp.org iburst server 2.pool.ntp.org iburst server 3.pool.ntp.org iburst
The iburst option makes the first synchronization faster.
Save the file: press Ctrl+O, Enter, then Ctrl+X.
Pro Tip
Use at least three or four time sources. With only two sources, NTP cannot find which source has the incorrect time.
Step 4: Allow NTP traffic through the firewall
The default NTPsec configuration answers time requests from clients. Use the firewall to control which clients can connect.
Allow NTP only from the network of your clients. Replace 192.168.1.0/24 with your network:
sudo ufw allow from 192.168.1.0/24 to any port 123 proto udp sudo ufw reload
To allow NTP from all networks, use sudo ufw allow 123/udp in place of the first command.
Make sure that the firewall is active and has the rule:
sudo ufw status
CAUTION
Before you enable ufw on a remote server (sudo ufw enable), allow SSH: sudo ufw allow OpenSSH. If you do not, you lose the SSH connection.
Step 5: Restart and verify the NTP service
- Restart the service to load the new configuration:
sudo systemctl restart ntpsec
- Make sure that the service is active (running):
systemctl status ntpsec
- Wait 1–2 minutes. Then show the time sources:
ntpq -p
| Column | Description |
|---|---|
remote |
The time source. The * sign shows the source that the server uses now. The + sign shows a good backup source. |
st |
Stratum: the distance from the reference clock. A lower number is better. |
reach |
The result of the last 8 requests (octal). 377 shows that all requests got an answer. 0 shows that the source does not answer. |
offset |
The time difference to the source, in milliseconds. |
The server is ready when one line starts with *.
Step 6: Connect the clients
Replace <NTP-server-IP> with the IP address of your Ubuntu server.
- Open the file
/etc/systemd/timesyncd.confand set the server in the[Time]section:
[Time] NTP=<NTP-server-IP>
- Restart the service and show the result:
sudo systemctl restart systemd-timesyncd timedatectl timesync-status
sudo config ntp add <NTP-server-IP> sudo config save -y show ntp
sonic-cli configure terminal ntp server <NTP-server-IP> exit write memory show ntp associations
Troubleshooting
Show the log of the service. Look for errors in the configuration file:
sudo journalctl -u ntpsec -n 50
The server cannot get answers from the time sources. Make sure that your network and firewalls allow outgoing traffic on UDP port 123.
- Make sure that the ufw rule includes the network of the client (
sudo ufw status). - Make sure that the server has a source with
*inntpq -p. A server that is not synchronized does not give time to clients. - Make sure that only one time service runs on the client.
Procedure completion
Congratulations!
You have successfully configured an NTP server on Ubuntu 24.04. All devices in your network can now use the same time source, and their logs are easy to compare during troubleshooting.
Happy networking!
Useful links:
How can I set up a console connection to Edgecore Open Networking switch?
How to configure management IP address in SONiC?
How to build the community version of SONiC Virtual Switch (SONiC VS) image?
For more free resources, visit: https://stordis.com/free-resources/
Comments 0
Comments
Please sign in to leave a comment.