Using NTP for Time Synchronization in Ubuntu

Using NTP for Time Synchronization in Ubuntu

NTP is a TCP/IP protocol for synchronizing time over a network. Typically the client requests the current time from the server and sets its clock based on the result.

This description is quite simple, but implementing this function is extremely complex - first, there must be multiple layers of NTP servers. The first layer of NTP servers connects to the atomic clock, and the second and third layers of servers take on the responsibility of load balancing to handle all requests from the Internet. Also, the client may be more complex than you think - it has to account for communication delays, adjust the time and not interfere with other processes running on the server. Fortunately, all of this complexity is encapsulated so you don't see it and don't need to see it.

In Ubuntu, ntpdate and ntpd are used to synchronize time.

timedatectl

In the latest Ubuntu versions, timedatectl replaces the old ntpdate. By default, timedatectl will sync the time immediately at system boot, and check again later via the socket when the network connection is active.

If ntpdate / ntp is already installed, timedatectl will fall back to letting you use the previous settings. This ensures that the two time synchronization services do not conflict with each other, while preserving original behavior and configuration when you upgrade. But this also means that when upgrading from older distributions ntp/ntpdate will still be installed, thus causing the new systemd-based time service to be disabled.

timesyncd

In the latest Ubuntu versions, timesyncd replaces the client part of ntpd. By default, timesyncd will periodically detect and synchronize the time. It also stores the updated time locally so that it can make single-step adjustments when the system is restarted.

The current time status and time configuration set by timedatectl and timesyncd can be confirmed using the timedatectl status command.

timedatectl status
     Local time: Fri 2016-04-29 06:32:57 UTC
   Universal time: Fri 2016-04-29 06:32:57 UTC
      RTC time: Fri 2016-04-29 07:44:02
      Time zone: Etc/UTC (UTC, +0000)
   Network time on: yes
  NTP synchronized: no
   RTC in local TZ: no

If NTP is installed and used instead of timedatectl to synchronize time, NTP synchronized will be set to yes.

The nameserver used by timedatectl and timesyncd to obtain the time can be specified through /etc/systemd/timesyncd.conf. In addition, there are flexible additional configuration files under /etc/systemd/timesyncd.conf.d/.

ntpdate

Due to the existence of timedatectl, distributions have deprecated ntpdate and it is no longer installed by default. If you install it, it will set your computer's time according to Ubuntu's NTP servers during system boot. After that, every time a new network interface is started, it will retry to synchronize the time - during which time it will slowly drift away as long as the time difference it covers is not too large. This behavior can be controlled with the -B/-b switch.

Time Server

By default, systemd-based tools request time synchronization from ntp.ubuntu.com. Classic ntpd-based services basically use 2.ubuntu.pool.ntp.org from the [0-3].ubuntu.pool.ntp.org pool, as well as ntp.ubuntu.com, and support IPv6 if needed. If you want to force the use of IPv6, you can use ipv6.ntp.ubuntu.com, but this is not the default configuration.

ntpd
The ntp daemon ntpd calculates the time offset of your system clock and adjusts it continuously, so there are no large corrections that would cause discontinuous logs, for example. This process takes a small amount of process resources and memory, but it is insignificant on modern servers.

Install

To install ntpd, enter in the terminal command line: sudo apt install ntp

Configuration

Edit /etc/ntp.conf - add/remove server line. The default configuration has the following servers:

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
  # on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
  # more information.
  server 0.ubuntu.pool.ntp.org
  server 1.ubuntu.pool.ntp.org
  server 2.ubuntu.pool.ntp.org
  server 3.ubuntu.pool.ntp.org

After modifying the configuration file, you need to reload ntpd:

sudo systemctl reload ntp.service

View Status

Use ntpq to see more information:

# sudo ntpq -p
     remote refid st t when poll reach delay offset jitter
  ==============================================================================
  +stratum2-2.NTP. 129.70.130.70 2 u 5 64 377 68.461 -44.274 110.334
  +ntp2.m-online.n 212.18.1.106 2 u 5 64 377 54.629 -27.318 78.882
  *145.253.66.170 .DCFa. 1 u 10 64 377 83.607 -30.159 68.343
  +stratum2-3.NTP. 129.70.130.70 2 u 5 64 357 68.795 -68.168 104.612
  +europium.canoni 193.79.237.14 2 u 63 64 337 81.534 -67.968 92.792

PPS Support

Starting from Ubuntu 16.04, ntp supports the PPS specification, which provides ntp with a local time source to provide higher accuracy. See the links listed below for more configuration information.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Setting up time synchronization using NTP in Ubuntu
  • How to change password and set password complexity policy in Ubuntu
  • Ubuntu opens port 22
  • How to install and configure GitLab on Ubuntu 20.04
  • How to install vncserver in Ubuntu 20.04
  • Ubuntu20.04 VNC installation and configuration implementation
  • Detailed tutorial on how to log in to the system using the root user in the new version of Ubuntu 20.04
  • Modification of the default source sources.list file of ubuntu20.04 LTS system

<<:  Detailed explanation of MySQL slow log query

>>:  Web project development VUE mixing and inheritance principle

Recommend

Detailed explanation of mixed inheritance in Vue

Table of contents The effect of mixed inheritance...

5 things to note when writing React components using hooks

Table of contents 01. Use useState when render is...

Detailed explanation of global parameter persistence in MySQL 8 new features

Table of contents Preface Global parameter persis...

Use of Linux dynamic link library

Compared with ordinary programs, dynamic link lib...

Mysql table creation foreign key error solution

Database Table A: CREATE TABLE task_desc_tab ( id...

Vue implements left and right sliding effect example code

Preface The effect problems used in personal actu...

Detailed explanation of monitoring NVIDIA GPU usage under Linux

When using TensorFlow for deep learning, insuffic...

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQ...

Detailed explanation of docker visualization graphics tool portainer

Table of contents 1. Introduction to Portainer 2....

HTML validate HTML validation

HTML validate refers to HTML validation. It is the...

Analysis and description of network configuration files under Ubuntu system

I encountered a strange network problem today. I ...