NTP Server

Setting up an NTP (Network Time Protocol) server on an Ubuntu machine is a straightforward process. You can use chrony or ntpd (Network Time Protocol Daemon) to accomplish this task. Here's how to set up an NTP server using chrony, which is the preferred tool in modern versions of Ubuntu.

Steps to Set Up an NTP Server on Ubuntu (using chrony):

  1. Update your system:

    Before installing new packages, it’s always a good idea to update your system.

    sudo apt update
    sudo apt upgrade
  2. Install chrony:

    If it's not already installed, you can install chrony by running:

    sudo apt install chrony
  3. Configure chrony as an NTP server:

    Now you need to configure chrony to act as an NTP server.

    • Open the configuration file with a text editor, for example:

      sudo nano /etc/chrony/chrony.conf
    • Find the line that begins with server (it’s usually a line like server 0.centos.pool.ntp.org iburst) and add the NTP servers you want to use. You can use public NTP servers like pool.ntp.org, or configure your own servers.

    • To configure chrony as an NTP server, you need to allow incoming NTP requests. Scroll to the bottom of the configuration file and add the following line:

      allow 192.168.0.0/16  # Allow NTP access from this subnet

      You can replace 192.168.0.0/16 with the IP address range of the clients that should be able to sync their time with this server.

  4. Restart the chrony service:

    After making changes to the configuration file, restart the chrony service to apply the changes.

    sudo systemctl restart chrony
  5. Enable chrony to start on boot:

    To ensure that chrony starts automatically when the system reboots, use the following command:

    sudo systemctl enable chrony
  6. Verify the NTP server status:

    You can check if the chrony service is running properly by typing:

    sudo systemctl status chrony

    Or you can check if the server is syncing correctly:

    chronyc tracking
  7. Allow NTP through the firewall (if applicable):

    If you're using ufw (Uncomplicated Firewall), you need to allow NTP traffic (UDP port 123):

    sudo ufw allow 123/udp
  8. Test the NTP server:

    To test if the NTP server is working, you can try syncing time from a client machine. On the client machine, you can use the following command:

    sudo chronyc -a makestep

    You can also configure the client to use your server for NTP by editing the chrony.conf file on the client:

    sudo nano /etc/chrony/chrony.conf

    Add the NTP server's IP address (the one you just set up) under the server directive:

    server <your_server_ip> iburst

    Then restart the client service:

    sudo systemctl restart chrony

Last updated