Mets Minor League Blog

Music theory, instruments and musicians

Mets Minor League Blog

Music theory, instruments and musicians

How to Set Up NTP Server and Client on Ubuntu 24.04

How to Set Up NTP Server and Client on Ubuntu 24.04

Accurate time synchronization is vital for network reliability, security, and logging consistency. Setting up an NTP (Network Time Protocol) server on Ubuntu 24.04 allows your network devices to synchronize their clocks precisely. Conversely, configuring a client ensures your machine maintains accurate time, which is especially important for security certificates, log accuracy, and scheduled tasks. This guide walks you through the steps to set up an NTP server and client on Ubuntu 24.04, covering everything from installation to troubleshooting.

What You’ll Need

  • Ubuntu 24.04 server or desktop installed and updated
  • Administrative (sudo) privileges
  • Basic knowledge of Linux command line
  • Optional: A second Ubuntu system to act as the client (for testing)

Step-by-Step

  1. Update your system packages

    Before starting, ensure your system is up to date to avoid package conflicts:

    sudo apt update && sudo apt upgrade -y
  2. Install NTP packages

    On the server (and client if needed), install the NTP daemon:

    sudo apt install ntp -y
  3. Configure the NTP server

    Open the NTP configuration file:

    sudo nano /etc/ntp.conf

    In this file, you’ll specify the NTP servers your server will synchronize with. To create your own local NTP server, you can add local hardware references or use public NTP servers:

    # Use public NTP servers for synchronization
    server 0.ubuntu.pool.ntp.org iburst
    server 1.ubuntu.pool.ntp.org iburst
    server 2.ubuntu.pool.ntp.org iburst
    server 3.ubuntu.pool.ntp.org iburst
    
    # Allow clients to synchronize
    restrict default nomodify notrap noquery
    restrict 127.0.0.1
    restrict ::1

    Save and exit the file (Ctrl+O, Enter, Ctrl+X).

  4. Allow NTP traffic through the firewall

    If you use UFW firewall, permit NTP:

    sudo ufw allow 123/udp
  5. Restart the NTP service

    Apply changes by restarting NTP:

    sudo systemctl restart ntp

    Check the status to ensure it’s running properly:

    sudo systemctl status ntp
  6. Configure the NTP client

    On the client machine, open the configuration file:

    sudo nano /etc/ntp.conf

    Comment out default servers and add your server’s IP address or hostname:

    # Use your server as the NTP source
    server  iburst

    Save and close the file.

  7. Restart the NTP service on the client
    sudo systemctl restart ntp

    Check synchronization status with:

    ntpq -p
  8. Verify synchronization

    On both server and client, run:

    timedatectl

    Ensure that the system clock is synchronized and reflects the correct time.

Common Mistakes

  • Not allowing UDP port 123 through the firewall, which blocks NTP traffic.
  • Using incorrect server IP or hostname in the client configuration.
  • Failing to restart the NTP service after configuration changes.
  • Not synchronizing time on the server before configuring clients, leading to inconsistent time.
  • Leaving default restrictive policies in the /etc/ntp.conf file that prevent clients from accessing the server.
  • Using an outdated or incompatible NTP package version.

Tips

  • Set your server to synchronize with reliable external NTP sources for accurate time.
  • Use static IP addresses for your NTP server to avoid resolution issues.
  • Regularly check NTP synchronization status with ntpq -p.
  • Consider configuring your server as a stratum 1 or 2 server for better accuracy if you have hardware time sources.
  • For security, restrict NTP access to trusted clients only by adjusting the restrict lines in /etc/ntp.conf.

Troubleshooting

If your NTP server or client isn’t synchronizing correctly:

  • Check NTP service status: Run sudo systemctl status ntp. If inactive, restart with sudo systemctl restart ntp.
  • Verify firewall rules: Ensure UDP port 123 is open using sudo ufw status. If not, allow it with sudo ufw allow 123/udp.
  • Check synchronization status: Use ntpq -p. If the server is not listed or marked with a ‘*’ or ‘+’ sign, it indicates synchronization issues.
  • Review logs: Check system logs for errors: journalctl -u ntp.
  • Ensure correct configuration: Double-check server IP/hostname and restrict rules.
  • Time drift issues: If time is significantly off, manually set the time with sudo timedatectl set-time 'YYYY-MM-DD HH:MM:SS' before rechecking synchronization.

Frequently Asked Questions

1. Can I use my Ubuntu 24.04 machine as an NTP server for other operating systems?

Yes, Ubuntu can serve as an NTP server for Windows, macOS, or other Linux distributions, as long as they can be configured to sync with an NTP source.

2. How many clients can my NTP server support?

The number of clients depends on your server’s hardware and network capacity. For small networks, a single Ubuntu server can handle dozens to hundreds of clients comfortably.

3. Is it necessary to synchronize my server with external NTP servers?

Yes, syncing with reliable external NTP servers ensures your server maintains accurate time, which it then distributes to clients.

4. How do I secure my NTP server from unauthorized access?

Restrict access in /etc/ntp.conf using the restrict directive, limit allowed IP addresses, and consider firewall rules to block unwanted traffic.

5. What should I do if my system time is still incorrect after setup?

Manually set the time using timedatectl set-time, then restart the NTP service and verify synchronization.

6. Can I run multiple NTP servers on the same network?

Yes, but it’s recommended to have a primary stratum 1 or 2 server and multiple secondary servers for redundancy.

By following these steps, tips, and troubleshooting advice, you can establish a reliable NTP infrastructure on your Ubuntu 24.04 systems, ensuring all your network devices keep accurate, synchronized time for optimal operation and security.

Related

How to Set Up NTP Server and Client on Ubuntu 24.04
Scroll to top