Configure NTP client on Ubuntu 18.04 machine

    1. Preface
      In this post I will demonstrate the required steps that needs to take place in order to configure an Ubuntu server 18.04 machine to synchronized itself with a particular NTP server.
    2. Prerequisites
      I assume the following:

      1. You have root access to your Ubuntu machine
      2. You know in advance the NTP server host name and/or IP address.
      3. The two machines (Ubuntu server and NTP server) are network reachable.
    3. Install sntp on the Ubuntu server
      Run the command:

      sntp --verion

      In case no output is displayed you need to install the sntp application using the command:

      sudo apt install ntp
      
    4. Disable the timedatectl
      By default, Ubuntu 18.04 machines are set to have their timedatectl daemon up and running and used as the “ntp service” of the system. You can check it by running the command:

      $ timedatectl
      Local time: Sun 2020-04-26 19:08:24 IDT
      Universal time: Sun 2020-04-26 16:08:24 UTC
      RTC time: Sun 2020-04-26 16:08:14
      Time zone: Asia/Jerusalem (IDT, +0300)
      System clock synchronized: no
      systemd-timesyncd.service active: yes
      RTC in local TZ: no

      As you can see in the sample output above, the systemd-timesyncd.service active is yes –> so here, currently, the “ntp” service is the timedatectl. In order to disable that, run the following command:

      $ sudo timedatectl set-ntp no
      $ timedatectl
      Local time: Sun 2020-04-26 19:08:24 IDT
      Universal time: Sun 2020-04-26 16:08:24 UTC
      RTC time: Sun 2020-04-26 16:08:14
      Time zone: Asia/Jerusalem (IDT, +0300)
      System clock synchronized: no
      systemd-timesyncd.service active: no
      RTC in local TZ: no

      Here you can see that the systemd-timesyncd.service active: no –> it was disabled correctly.

    5. Start the ntpd service
      Check if it is already up and if it is not use the second command in the following two commands:

      $ sudo systemctl status ntp
      $ sudo systemctl start ntp
    6. Install the ntpdate utility
      This utility will be used to “verify” the proper settings for the ntpd service. It can be installed using the command:

      $ sudo apt install ntpdate
    7. Check synchronization with the NTP server
      Use the ntpdate utility to get the current “diff” between the Ubuntu machine (NTP client) time and the NTP server time. Assuming your NTP server name is my.org.ntp.server, run the following command:

      $ sudo ntpdate -u my.org.ntp.server
      26 Apr 21:21:37 ntpdate[11656]: adjust time server 172.31.245.80 offset 8776.003027 sec

      In this case the difference is 8776 seconds — allot.

    8. Configure the NTP server in the Ubuntu machine
      Configure the my.org.ntp.server as thedesired” NTP server in the /etc/ntp.conf file by appending as the last line in the file the following line:
      server NTP_SERVER_NAME prefer iburst, which in this case it will be:
      server my.org.ntp.server prefer iburst
    9. Restart the ntp service
      $ sudo systemctl restart ntp

       

    10. Check the time diff again
      Run the same command as in the 7th step –> now the time difference should be very small.

      Resources:
      a)Install and configure ntpd service on Ubuntu 18.04 machine
      b) Running the ntpdate utility

      The picture: Avenida 9 de Julio, Buenos Aires, Argentina.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s