9
June
2020
Baith time in Linux, synchronization of the computer's clock on the NTP protocol
10:18

Baith time in Linux, synchronization of the computer's clock on the NTP protocol

9 June 2020 10:18

The hourly belt of the system is selected when installing a distribution. In the future, you can configure the synchronization of time (NTP protocol) for a more accurate time and organize the withdrawal of information about other time zones. For example, when in Moscow morning, in the central part of the United States, a deep night. This article on how to improve time synchronization, set an hour-long belt and take the time of other time zones per screen.

Introduction

The work of the time service in Linux is possible in two versions that do not exclude one another:

  • Client (synchronizes the time of this PC with other exact time servers)
  • Server (for distribution accurate time for other network computers in the local network).

I am considering the client service of the time.

Goals:
a) get high accuracy of time (less than 0.5 seconds), on a local computer
b) implement the output on the time screen in various time zones.

Here is action plan:

  1. Install,
  2. Launch,
  3. Check.

Inclusion of the NTP client

In order for the time to synchronized over the network, you need to install the NTP client and the NTPDate utility:

su -
apt-get update
apt install ntp

An indication of the watch belt

First of all, you need to check which time zone is set in the system.

ls -l /etc/localtimE.

For Moscow, St. Petersburg and the European part of the Russian Federation, a link will be displayed:

/etc/localtime -> /usr/share/zoneinfo/Europe/Moscow

this is right. But you can reconfigure the computer to another time zone (if the PC has moved to another region).

In Linux Mint, the clock program is called time-admin (которую необходимо запускать с правами суперпользователя su). Also, this program is available in the "Start" menu - "parameters" - "date and time".
TI programme-admin

The change of clock belt can be performed using the command line. First, we find out what time zones exist, for example, in Europe:

ls /usr/share/zoneinfo/Europe/

Amsterdam Busingen Kiev Monaco Sarajevo Vaduz
Andorra Chisinau Kirov Moscow Saratov Vatican
Astrakhan Copenhagen Kyiv Nicosia Simferopol Vienna
Athens Dublin Lisbon Oslo Skopje Vilnius
Belfast Gibraltar Ljubljana Paris Sofia Volgograd
Belgrade Guernsey London Podgorica Stockholm Warsaw
Berlin Helsinki Luxembourg Prague Tallinn Zagreb
_Bratislava Isle_ofMan Madrid Riga Tirane Zaporozhye
Brussels Istanbul Malta Rome Tiraspol Zurich
Bucharest Jersey Mariehamn Samara Ulyanovsk
_Budapest Kaliningrad Minsk SanMarino Uzhgorod

Now we make a soft symbolic link, for example, to Minsk:

We look at the current time zone

ls -l /etc/localtime

The text is displayed "/etc/localtime -> /usr/share/zoneinfo/Europe/Moscow "

We change the time zone, for example, to Minsk (only for example):

sudo ln -sf /usr/share/zoneinfo/Europe/Minsk /etc/localtime

Time Settings

For the work of the client NTP, conditions are needed: the presence of a configuration file /etc/ntp.conf
permission to launch the client NTP and directly launch the client.

  1. Configuration file /etc/ntp.conf

    driftfile /var/lib/ntp/ntp.drift
    leapfile /usr/share/zoneinfo/leap-seconds.list
    statistics loopstats peerstats clockstats
    filegen loopstats file loopstats type day enable
    filegen peerstats file peerstats type day enable
    filegen clockstats file clockstats type day enable
    pool 0.ubuntu.pool.ntp.org iburst
    pool 1.ubuntu.pool.ntp.org iburst
    pool 2.ubuntu.pool.ntp.org iburst
    pool 3.ubuntu.pool.ntp.org iburst
    pool ntp.ubuntu.com
    restrict -4 default kod notrap nomodify nopeer noquery limited
    restrict -6 default kod notrap nomodify nopeer noquery limited
    restrict 127.0.0.1
    restrict ::1
    restrict source notrap nomodify noquery

  2. The launch of the NTP client service is permitted by default.

You can, but not necessarily give commands

 systemctl enable ntp
 systemctl start ntp
 systemctl status ntp

In order for the service to re -read the updated configuration (if you edit the /etc/ntp.conf file), you need to execute

sudo systemctl restart ntp

Observation of the customer of time synchronization

ntpq -pw

A list of NTP servers will be displayed, with which the client performs time synchronization. (We must wait for the output of the program to end).

How to find out the deviation of the time of the local computer and the remote time server

Using the NTPQ utility.

Or Clockdiff

su -
apt-get update
apt install iputils-clockdiff

We learn the deviation of time from another computer - NTP server:

sudo clockdiff 130.149.17.21

or

sudo clockdiff 1.ru.pool.ntp.org

It can be seen that the deviation, i.e. The inaccuracy of the PC is 34 milliseconds:

..................................................
host=130.149.17.21 rtt=34(0)ms/34ms delta=-1ms/-1ms Tue Jun 9 11:38:44 2020

When comparing with another server, the situation is the same, a deviation of 35 ms:

clockdiff 91.206.16.3

..................................................
host=91.206.16.3 rtt=35(0)ms/35ms delta=0ms/0ms Tue Jun 9 11:44:57 2020

It should be borne in mind that Clockdiff does not take into account network delays (Ping), it only allows you to compare the time with another computer without delay of package in network.

A more accurate value of the deviation is displayed by the command

ntpq -p

or
ntpq -pw

Where the difference is visible (OffSet +- Jitter) already in a couple of milliseconds.

Another way to find out time deviation

https://time.is

World time output to the screen

World Time Apllication (Globaltime) for Xfce Desktop Environment allows you to make a clock display with time for several time zones.
Installation of the "GlobalTime" application:

sudo apt install xfce4-datetime-plugin

Sources:



Related publications