Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use NTP for time synchronization in Ubuntu

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use NTP for time synchronization in Ubuntu. It is very detailed and has a certain reference value. Friends who are interested must finish it!

NTP is a TCP/IP protocol that synchronizes time through the network. Usually the client requests the current time from the server and sets its clock according to the result.

This description is simple, but the implementation of this function is extremely complicated-first of all, there are multi-tier NTP servers, * layer NTP servers connect to the atomic clock, and layer 2 and layer 3 servers take the responsibility of load balancing to handle all requests from the Internet. In addition, the client may be more complex than you think-it must eliminate communication delays and adjust the time without interfering with other processes running on the server. Fortunately, all of these complexities are encapsulated and you don't need to see them.

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

Timedatectl

In the Ubuntu version of * *, timedatectl replaces the old ntpdate. By default, timedatectl synchronizes the time immediately when the system starts and checks it again via socket later after the network connection is activated.

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

Timesyncd

In the Ubuntu version of * *, timesyncd replaces the client side of ntpd. By default, timesyncd periodically detects and synchronizes time. It also stores the updated time locally so that it can be adjusted step by step when the system is rebooted.

With the current time status and time configuration of timedatectl and timesyncd settings, you can use the timedatectl status command to confirm.

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 you install NTP and use it instead of timedatectl to synchronize time, NTP synchronized will be set to yes.

The nameserver that timedatectl and timesyncd use to get the time can be specified through / etc/systemd/timesyncd.conf, and there are flexible additional configuration files under / etc/systemd/timesyncd.conf.d/.

Ntpdate

Due to the existence of timedatectl, ntpdate has been abandoned in various distributions and is no longer installed by default. If you install it, it will set your computer's time according to Ubuntu's NTP server when the system starts up. Then every time a new network interface starts, it retries to synchronize time-during which time it slowly shifts time as long as the time difference it covers is not too large. This behavior can be controlled by the-Bhammerb switch.

Ntpdate ntp.ubuntu.com

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 in the [0-3] .ubuntu.pool.ntp.org pool, as well as ntp.ubuntu.com, and support IPv6 if necessary. If you want to force IPv6, you can use ipv6.ntp.ubuntu.com, but this is not the default configuration.

Ntpd

Ntp's daemon, ntpd, calculates the time offset of your system clock and continuously adjusts it, so there is no correction of a large time gap, for example, does not result in discontiguous logs. This process consumes only a small amount of process resources and memory, but it is negligible to modern servers.

Installation

To install ntpd, type in the terminal command line:

Sudo apt install ntp

Configuration

Edit / etc/ntp.conf-add / remove server lines. The following servers are configured by default:

# 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 statu

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 564 377 68.461-44.274 110.334 + ntp2.m-online.n 212.18.1.106 2 u 564 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 564 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 with Ubuntu 16.04, ntp supports the PPS specification, providing ntp with a local time source to provide higher precision. Check the links listed below for more configuration information.

The above is all the contents of the article "how to use NTP for time synchronization in Ubuntu". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report