首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用主机作为ntp客户端,lxc路由器作为ntp-服务器。

使用主机作为ntp客户端,lxc路由器作为ntp-服务器。
EN

Server Fault用户
提问于 2017-10-18 21:05:08
回答 2查看 3.3K关注 0票数 1

我在Debian主机上安装了ntpd,以保持硬件RTC“最新”。通过共享系统的时钟,时间将自动传播到所有已安装的容器(lxc)。其中一个容器运行我的路由器。

我想用这个路由器把它的时间传播给我网络中所有感兴趣的设备,这样他们就不需要自己的互联网连接了。我不想将主机用作服务器(希望被interface ignore all禁用)。

如何在容器中安装和配置一个纯ntp服务器,该容器只以系统的时钟作为它的唯一引用?它永远不能自己定时钟。

如何安装和配置一个纯ntp客户端,它不接受来自其他对等点的传入连接,并且泄漏尽可能少的信息?

EN

回答 2

Server Fault用户

回答已采纳

发布于 2017-10-20 22:06:56

NTP的配置偏离了我所说的直觉。默认情况下,它安装一个客户机,该客户端读取和写入系统时钟,并开始侦听所有接口和桥接器,并急切地使用它们提供有关其状态的信息,而无需身份验证。

我花了很长时间收集所有的信息和文档,以使(希望)正确。即使是默认配置文件也包含了手册页没有涵盖的几个语句。

下面的配置似乎很好,没有提供过多的信息和服务。

这是要安装在主机上的配置,以强制执行仅限客户端的操作:

代码语言:javascript
复制
>> my-host:/etc/ntp.conf

# stop listening for incoming connections an all interfaces including 0.0.0.0 and [::]
interface ignore all
interface ignore wildcard

# only allow listening on the interface used to contact the time servers
interface listen 10.2.20.2

# your pools or servers
pool 0.debian.pool.ntp.org iburst
pool 1.debian.pool.ntp.org iburst
pool 2.debian.pool.ntp.org iburst
pool 3.debian.pool.ntp.org iburst

# by default drop all incoming connections on all interfaces
restrict default ignore

# unrestriced control for local connections
restrict 127.0.0.1
restrict ::1

# Needed for adding pool entries
restrict source notrap nomodify noquery

重新启动服务将为我们提供一个可理解的侦听套接字列表。(my-host:ntp无法避免,因为NTPd的工作方式。)

代码语言:javascript
复制
my-host:# netstat -a|grep ntp
udp        0      0 my-host:ntp   0.0.0.0:*
udp        0      0 localhost:ntp 0.0.0.0:*
udp6       0      0 localhost:ntp [::]:*

这是要安装在路由器容器上的配置,以强制执行服务器专用操作(由于@BillThor,以系统时钟作为时间来源):

代码语言:javascript
复制
>> router:/etc/ntp.conf

# don't update the system's clock
disable kernel

# local clock as preferred and only source
server 127.127.1.0 prefer

# stop listening for incoming connections an all interfaces including 0.0.0.0 and [::]
interface ignore all
interface ignore wildcard

# whitelist addresses to listen on for NTP clients
interface listen 10.1.2.1
interface listen 10.2.2.2
interface listen 10.3.2.3
interface listen 10.4.2.4
interface listen 10.5.2.5

# set "serve" as the only permission given to all listening interfaces per default
restrict default kod notrap nomodify nopeer noquery limited

# unrestriced control for local connections
restrict 127.0.0.1
restrict ::1

# broadcast time (optional)
broadcast 10.1.255.255
broadcast 10.2.255.255
broadcast 10.3.255.255
broadcast 10.4.255.255
broadcast 10.5.255.255

重新启动服务将本地时钟作为首选源和(可选)广播目标列表。

代码语言:javascript
复制
router:# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           5 l   16   64    3    0.000    0.000   0.000
 10.1.255.255    .BCST.          16 B    -   64    0    0.000    0.000   0.000
 10.2.255.255    .BCST.          16 B    -   64    0    0.000    0.000   0.000
 10.3.255.255    .BCST.          16 B    -   64    0    0.000    0.000   0.000
 10.4.255.255    .BCST.          16 B    -   64    0    0.000    0.000   0.000
 10.5.255.255    .BCST.          16 B    -   64    0    0.000    0.000   0.000

..。以及为本地网络服务的可理解的侦听套接字列表。

代码语言:javascript
复制
router:# netstat -a|grep ntp
udp        0      0 router-lan5:ntp 0.0.0.0:*
udp        0      0 router-lan4:ntp 0.0.0.0:*
udp        0      0 router-lan3:ntp 0.0.0.0:*
udp        0      0 router-lan2:ntp 0.0.0.0:*
udp        0      0 router-lan1:ntp 0.0.0.0:*
udp        0      0 localhost:ntp   0.0.0.0:*
udp6       0      0 localhost:ntp   [::]:*

disable kernel (感谢@PaulGear)禁止守护进程设置在典型容器中不允许的系统时钟。否则,它会淹没日志中的以下内容:

代码语言:javascript
复制
ntpd[1568]: adj_systime: Operation not permitted

在初创公司,仍然有一些无害的小故障,我不知道如何摆脱:

代码语言:javascript
复制
ntpd[1568]: start_kern_loop: ntp_loopfilter.c line 1119: ntp_adjtime: Operation not permitted
ntpd[1568]: set_freq: ntp_loopfilter.c line 1082: ntp_adjtime: Operation not permitted
票数 2
EN

Server Fault用户

发布于 2017-10-18 23:30:01

只需添加本地时钟作为服务器,并禁用所有服务器。篡改优先级,这样,如果有人将您的主机作为服务器,他们就不会认为您正在运行和原子钟。这是我为服务器使用的配置:

代码语言:javascript
复制
# Fallback to local clock if all else fails
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

若要防止服务时间,请使用限制子句。

代码语言:javascript
复制
restrict 192.168.0.0    mask 255.255.0.0     notrap nomodify nopeer noserve

文档在ntp.org

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/879164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档