AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 879164
Accepted
Kai Giebeler
Kai Giebeler
Asked: 2017-10-19 13:05:08 +0800 CST2017-10-19 13:05:08 +0800 CST 2017-10-19 13:05:08 +0800 CST

使用主机作为 ntp-client 和 lxc-router 作为 ntp-server

  • 772

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

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

如何在容器中安装和配置纯 ntp-server,它以系统时钟为唯一参考?它永远不会自己设置时钟。

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

debian
  • 2 2 个回答
  • 3029 Views

2 个回答

  • Voted
  1. Best Answer
    Kai Giebeler
    2017-10-21T14:06:56+08:002017-10-21T14:06:56+08:00

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

    我很难收集所有信息和文档来(希望)正确地做到这一点。甚至默认配置文件也包含一些手册页未涵盖的语句。

    在不提供过多信息和服务的情况下,以下配置似乎可以正常工作。

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

    >> 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 的工作方式,无法避免。)

    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):

    >> 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
    

    重新启动服务为我们提供了本地时钟作为首选源和(可选)广播目标列表

    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
    

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

    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)禁止守护程序设置系统时钟,这在典型容器中是不允许的。否则,它会用以下内容淹没日志:

    ntpd[1568]: adj_systime: Operation not permitted
    

    在启动时仍然有一些无害的故障,我不知道如何摆脱:

    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
  2. BillThor
    2017-10-19T15:30:01+08:002017-10-19T15:30:01+08:00

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

    # Fallback to local clock if all else fails
    server  127.127.1.0     # local clock
    fudge   127.127.1.0 stratum 10
    

    为了防止服务时间使用限制子句。

    restrict 192.168.0.0    mask 255.255.0.0     notrap nomodify nopeer noserve
    

    文档位于ntp.org。

    • 1

相关问题

  • 关闭 FTP

  • 如何在同一台电脑上从 putty 连接 debian vmware

  • debian- 文件到包的映射

  • Debian Ubuntu 网络管理器错误 [关闭]

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve