目前互联网中ntp是仍在使用不安全的互联网协议之一。后来Cloudflare发布了NTS协议,去保证NTP的安全。
注意:NTP 客户端会查询多个服务器并实施算法来选择最佳估计值,并拒绝明显错误的答案。
目前支持NTS的公共服务器非常少,主要的提供商有Cloudflare和Netnod
ntpclient现在有两个版本,一个是python版本,一个是go版本,另外则是chrony已经有分支支持nts。fedora从33版本已经开始支持NTS了。
系统仅支持Debian 9 (Stretch), Debian 10 (Buster), Ubuntu 16.04 LTS (Xenial Xerus) , Ubuntu 18.04 LTS (Bionic Beaver).
拉取库
git clone https://gitlab.com/hacklunch/ntsclient; cd ntsclient; make
假如不想ntsclient以root用户运行
sudo setcap CAP_SYS_TIME+ep ./ntsclient
执行
./ntsclient --config ntsclient.toml
拉取库,使用./buildprep安装构建需要的包
git clone https://gitlab.com/NTPsec/ntpsec.git; cd ntpsec;sudo ./buildprep
构建完成后,可以用waf构建NTPsec
./waf configure
./waf build
设置配置文件,创建ntp.conf
# Exchange time with everybody, but don't allow configuration.
# This is the right security setup for 99% of deployments.
restrict default kod limited nomodify nopeer noquery
restrict -6 default kod limited nomodify nopeer noquery
# Local users may interrogate the NTP server more closely.
restrict 127.0.0.1
restrict -6 ::1
# Minimal logging - we declare a drift file and that's it.
driftfile /var/lib/ntp/ntp.drift
server nts.netnod.se:4460 nts iburst
server sth1.nts.netnod.se:4460 nts iburst
server sth2.nts.netnod.se:4460 nts iburst
开始测试,测试前需要暂停ntp,chrony,openntpd
sudo service ntp stop
sudo service chrony stop
sudo service openntpd stop
开启启动NTPsec服务器
sudo ./build/main/ntpd/ntpd -n -d -c ntp.conf