ntp - fetching and synchronizing time with atomic clocks

Synchronize time on Linux with atomic clocks using ntp. Find out how to install ntp, use ntpdate, configure cron and the firewall. Accurate time...

The Linux system clock can be synchronized with a time standard published on ntp servers. Synchronization can happen in real time, or as a one-off. To carry out this operation we need the ntp program. Once installed we have the ntpdate command at our disposal. Now we just need to know the addresses of the time servers, e.g. tempus1.gum.gov.pl. We issue the command ntpdate tempus1.gum.gov.pl and the date and time are already updated.
However, two things need to be kept in mind. A condition for time synchronization via the ntp protocol is that UDP port 123 not be blocked by our firewall. The second matter is keeping the synchronization up to date. We can use cron.
Just create a script that will perform synchronization with a time server every day. For this we carry out the following steps:

  • we create the file touch /etc/cron.daily/time
  • we change the permissions chmod ug+x /etc/cron.daily/time
  • echo '#!/bin/sh' > /etc/cron.daily/time
  • echo "ntpdate -u tempus1.gum.gov.pl" >> /etc/cron.daily/time
  • If we want to synchronize the system time with the hardware clock time:
    echo "/sbin/hwclock --systohc" >> /etc/cron.daily/time

We still need to make sure whether our time is set to local or universal. For this we issue the command timeconfig, and choose the No option. Then we choose the time zone: Europe/Warsaw.