# This file is part of systemd.## systemd is free software; you can redistribute it and/or modify it# under the terms of the GNU Lesser General Public License as published by# the Free Software Foundation; either version 2.1 of the License, or# (at your option) any later version.## Entries in this file show the compile time defaults.# You can change settings by editing this file.# Defaults can be restored by simply deleting this file.## See timesyncd.conf(5) for details.[Time]#NTP=#FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org#RootDistanceMaxSec=5#PollIntervalMinSec=32#PollIntervalMaxSec=2048
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will# pick a different set every time it starts up. Please consider joining the# pool: <http://www.pool.ntp.org/join.html>pool0.debian.pool.ntp.orgiburstpool1.debian.pool.ntp.orgiburstpool2.debian.pool.ntp.orgiburstpool3.debian.pool.ntp.orgiburst
例如修改为:
serverntp1.aliyun.comserverntp2.aliyun.com
重启服务生效:
$systemctlrestartntpd
使用 ntpq -p 查看同步状态
root@debian:~# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
0.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
1.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
2.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
3.debian.pool.n .POOL. 16 p - 64 0 0.000 0.000 0.000
-tick.ntp.infoma .GPS. 1 u 146 128 176 225.512 -11.584 0.508
+203.107.6.88 100.107.25.114 2 u 12 64 377 29.612 -9.788 0.910
+119.28.183.184 100.122.36.196 2 u 17 64 337 66.883 -8.777 1.218
*202.118.1.130 .PTP. 1 u 77 64 376 44.633 9.074 0.494
-119.28.206.193 100.122.36.4 2 u 73 128 277 69.470 -8.139 5.240
# By default, exchange time with everybody, but don't allow configuration.restrict-4defaultkodnotrapnomodifynopeernoquerylimitedrestrict-6defaultkodnotrapnomodifynopeernoquerylimited# Local users may interrogate the ntp server more closely.restrict127.0.0.1restrict::1# Needed for adding pool entriesrestrictsourcenotrapnomodifynoquery# Clients from this (example!) subnet have unlimited access, but only if# cryptographically authenticated.#restrict 192.168.123.0 mask 255.255.255.0 notrust# If you want to provide time to your local subnet, change the next line.# (Again, the address is an example only.)#broadcast 192.168.123.255
为确保失去网络也能提供同步服务,需要增加一个本地时间作为时间源:
server127.0.0.1fudge127.0.0.1stratum10
接下来新增策略,允许局域网内的主机与本机同步时间,例如本例中我的局域网 IP 为 192.168.50.0/24,则可以写为