How to synchronize time with NTPD time server

NTP stands for Network Time Protocol and is used for clock synchronization across multiple computers. An NTP server is responsible for keeping a set of computers in sync with each other. There are NTPD servers available over the internet to which you can sync, or you can run your own NTPD server and configure client computers to sync their times to it.

In this tutorial, you will learn how to install and configure the NTP client on major Linux distros, including DEB and RPM based systems. You will then see the commands needed to sync a client PC with an NTPD time server. Let’s get started.

In this tutorial you will learn:

  • How to install the NTP client on major Linux distros
  • How to synchronize time with NTPD time server
How to synchronize time with NTPD time server
How to synchronize time with NTPD time server
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux system
Software ntpdate, chrony
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to synchronize time with NTPD time server step by step instructions




Be sure to follow the correct section below, depending on which distro you are using (either DEB based or RPM).

DEB based systems

  1. To install the NTP client package on Ubuntu, Debian, and Linux Mint:
    $ sudo apt install ntpdate
    
  2. The first thing we need to do after installing the ntpdate package is to open a command line terminal and be sure to disable Ubuntu’s default timesyncd service, as this will conflict with our attempts to synchronize with the NTP server.
    $ sudo timedatectl set-ntp off
    
  3. If you wish to synchronize your system time with the world time servers, all you need to do is issue the following Linux command with root permissions and you are done:
    $ ntpdate pool.ntp.org
    
  4. The above command will synchronize your system time / clock. However, if you want to stay synchronized you need to do little bit more work. The work involves installation and configuration of NTPD daemon. NTPD uses NTP ( network time protocol ) to access a specified time server over the internet. Later, it will keep your system time synchronized without your further intervention.
    $ sudo apt install ntp
    
  5. In most cases your NTP Daemon will be configured out of the box and installation of ntp package is all you would ever need to do to keep your system time synchronized with internet standard time servers. However, it is good to check certain settings whether they are in place before we leave a system time in hands of NTP daemon. These settings are configured inside of the ntp.conf file.
    $ sudo nano /etc/ntp.conf
    
  6. In this file, place the fully qualified domain name of a time server which we intend to use for a time synchronization. For example, the default settings look like this:
    server 0.debian.pool.ntp.org iburst
    server 1.debian.pool.ntp.org iburst
    server 2.debian.pool.ntp.org iburst
    server 3.debian.pool.ntp.org iburst
    

    You can use the NTP Pool Project website to find the closest NTP server pool to your location.

  7. Once you have made any necessary changes to your ntp.conf file, be sure to save it and exit the file. Then, make changes take effect by restarting the NTP daemon.
    $ sudo systemctl restart ntp
    
  8. Lastly, use the ntpq command to list the NTP time synchronization queue:
    $ ntpq -p
    

RPM based systems



  1. To install the NTP client package on Fedora, CentOS, AlmaLinux, and Red Hat:
    $ sudo dnf install chrony
    
  2. Ensure that chrony is set to start automatically at boot:
    $ systemctl enable --now chrony
    
  3. In most cases, chrony will be configured out of the box and installation and you won’t need to do anything else to keep your system time synchronized with internet standard time servers. However, it is good to check certain settings whether they are in place before we leave a system time in hands of chrony. These settings are configured inside of the chrony.conf file.
    $ sudo nano /etc/chrony.conf
    
  4. In this file, place the fully qualified domain name of a time server which we intend to use for a time synchronization. For example, the default settings look like this:
    pool 2.fedora.pool.ntp.org iburst
    

    You can use the NTP Pool Project website to find the closest NTP server pool to your location.

  5. Once you have made any necessary changes to your chrony.conf file, be sure to save it and exit the file. Then, make changes take effect by restarting chrony.
    $ sudo systemctl restart chronyd
    
  6. Lastly, use the chronyc sources command to list the NTP time synchronization queue:
    $ chronyc sources
    

    By default the chrony NTP client will perform a time synchronization every 64 seconds.

Closing Thoughts




In this tutorial, we saw how to configure a Linux system to synchronize the system clock with an NTPD server. In most cases, you will probably want to sync to one of the many public time servers available over the internet. However, it is also possible to configure ntpdate (on DEB systems) or chrony (on RPM systems) to synchronize to other time servers, such as one hosted elsewhere on your local network.



Comments and Discussions
Linux Forum