0Pricing
Linux Networking & TCP/IP for Developers · 课时

NTP 与时间同步服务

使用 chrony 和 timedatectl 借助 NTP 保持 Linux 时钟准确,并了解同步时间为何对联网服务至关重要。

NTP 与时间同步服务 是 CoddyKit 上的免费 Linux Networking & TCP/IP for Developers 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Networking & TCP/IP for Developers 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Networking & TCP/IP for Developers 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Why Time Matters

Accurate clocks are essential for networked systems. Logs, TLS certificates, authentication tokens, and distributed databases all break when clocks drift apart. The Network Time Protocol (NTP) keeps them aligned.

How NTP Works

NTP clients query time servers, measure the network round-trip, and gradually adjust the local clock. It corrects for delay so even over the internet machines stay within milliseconds.

Stratum Levels

NTP servers are ranked by stratum. Stratum 0 is a reference clock (like GPS), stratum 1 servers connect directly to it, and each layer below is one step further. Lower stratum means closer to the source.

Checking Time Status

The simplest check is timedatectl, which shows the current time, timezone, and whether NTP synchronization is active.

timedatectl status

Enabling NTP

Turn on automatic synchronization with one command. The system then keeps the clock in sync in the background.

sudo timedatectl set-ntp true

Meet chrony

chrony is the modern NTP implementation used by most Linux distributions. It handles intermittent connections and large time jumps better than the older ntpd.

sudo systemctl status chronyd

Viewing Sources

List the time servers chrony is using and how it rates them with chronyc sources. The asterisk marks the currently selected source.

chronyc sources -v

Measuring Accuracy

chronyc tracking shows how far off the clock is and how it is being corrected, including the estimated offset from true time.

chronyc tracking

Configuring Servers

Edit /etc/chrony/chrony.conf to point at preferred pools or internal time servers, then restart the service. Many setups use the public NTP pool.

pool pool.ntp.org iburst

Timezone vs Clock

Time synchronization sets the absolute moment (UTC), while the timezone affects how it is displayed. Set the zone separately and keep the hardware clock in UTC.

sudo timedatectl set-timezone Europe/Istanbul

Forcing a Sync

After a long downtime the clock may be far off. chronyc makestep forces an immediate correction instead of slowly slewing, useful right after boot.

sudo chronyc makestep

Quick Check

Test your NTP knowledge.

Recap

You learned to manage time synchronization.

  • NTP keeps clocks aligned, which is critical for logs, TLS, and auth.
  • Use timedatectl to check and enable sync; chrony is the modern daemon.
  • chronyc sources and tracking show servers and accuracy.

常见问题解答

「NTP 与时间同步服务」课时是免费的吗?

是的 — 「NTP 与时间同步服务」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Networking & TCP/IP for Developers 课程的其余内容,请升级到 CoddyKit PRO。 Linux Networking & TCP/IP for Developers 课程共包含 4 节课。

「NTP 与时间同步服务」这节课中我会学到什么?

使用 chrony 和 timedatectl 借助 NTP 保持 Linux 时钟准确,并了解同步时间为何对联网服务至关重要。 你通过在浏览器中直接运行的动手代码来练习 Linux Networking & TCP/IP for Developers,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Linux Networking & TCP/IP for Developers 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Linux Networking & TCP/IP for Developers 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「NTP 与时间同步服务」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Linux Networking & TCP/IP for Developers 课中编写并运行代码吗?

能。每节 Linux Networking & TCP/IP for Developers 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 使用 SSH 安全远程访问
  2. HTTP/HTTPS Web 服务
  3. DHCP 与 DNS 服务
  4. NTP 与时间同步服务
← 返回 Linux Networking & TCP/IP for Developers