ntpdate不能用

一般校准时间的ntpdate使用udp协议,123端口,机房托管为了防止流量攻击可能会屏蔽ntp流量

这时执行ntpdate www.pool.ntp.org将会提示

1
no server suitable for synchronization found

这里可以使用htpdate来代替ntpdate

安装

Debian的库里已经包含了htpdate,直接apt安装

1
apt install -y htpdate

修改配置文件

默认的配置文件位于/etc/default/htpdate

1
2
HTP_SERVERS="www.pool.ntp.org www.ntp.br www.wikipedia.org"
HTP_OPTIONS="-D -s -t"

可选择的参数包括

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-0 HTTP/1.0 request (default is HTTP/1.1).
-4 Force IPv4 name resolution only. Default behaviour is to try IPv6 first and fall back to IPv4.
-6 Force IPv6 name resolution only.
-a Adjust time smoothly (default in daemon mode).
-b Burst mode uses multiple polls for each web server to enhance accuracy.
-d Turn debug on. Shows the "raw" timestamp, round trip time, time delta and and basic statistics of web server responses. Usefull to determining the quality of a specific web server as time source.
-h Show help.
-i Set the pid file (default /var/run/htpdate.pid).
-l Use syslog for output (levels LOG_WARNING and LOG_INFO). Convinient if you use htpdate from cron.
-m -M These options specify the minimum (-m) and maximum (-M) polling intervals for HTP requests, in seconds. The default range is between 30 minutes and 32 hours. Htpdate calculates the optimal polling frequency between minimum and maximum values. Only applicable when running in daemon mode.
-p Precision (in milliseconds) specifies the operating accuracy of htpdate. Internally htpdate uses a different algorithm to detect a time offset, when precision is specified. Precision only has effect in daemon mode. Use with causion.
-q Query web server and display time, but do not change time (default in interactive mode).
-s Set time immediate. In daemon mode -s only applies the first poll.
-t Turn off sanity time check. By default a time offset larger than a year, compared to current localtime, is rejected. With -t set, any time stamp will be accepted.
-u Set the user and group that the server normally runs at (default is root).
-x Let htpdate compensate for the systematisch clock drift.
-D Run as daemon (requires root privileges).
-P Proxy server hostname or ip-address.
host Web server hostname or ip-address. Upto 16 hosts may be specified, but in general 3 to 5 hosts should be enough for a redundant and accurate setup.
port Portnumber (default 80 and 8080 for proxy server)