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 to synchronize time 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 is about how to use NTP to synchronize time in Ubuntu. I think it is very practical, so I share it with you. I hope you can get something after reading this article.

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.

Timedatectl

In the latest version of Ubuntu, 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 latest version of Ubuntu, 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.

?

one

two

three

four

five

six

seven

eight

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.

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: sudo apt install ntp at the terminal command line

Configuration

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

?

one

two

three

four

five

six

seven

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

?

one

two

three

four

five

six

seven

eight

# 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 2u 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 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 how to use NTP to synchronize time in Ubuntu. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Original link: https://www.cnblogs.com/libra13179/p/13228721.html

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