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 / 问题 / 655039
Accepted
ndemou
ndemou
Asked: 2014-12-28 14:20:48 +0800 CST2014-12-28 14:20:48 +0800 CST 2014-12-28 14:20:48 +0800 CST

如何让 ntpd 仅服务于我的本地子网

  • 772

我有几台具有公共 Internet IP 地址的服务器,例如A.B.C.x. 我的一位主机 ( A.B.C.10) 运行 ntpd,我让它从 europe.pool.ntp.org 同步它的时间。

现在我只想让我的子网( A.B.C.x) 中的主机能够同步到A.B.C.10. 默认情况下,全世界都可以同步到我的 NTP 服务器。我该如何做到这一点?


我能找到的所有示例都假设我正在同步到特定的 IP 地址,但我同步到了 DNS 名称,并且据我所知,DNS 名称x.europe.pool.ntp.org 指向的 IP 地址是可变的。所以我不能在我的防火墙中设置例外,也不能restrict在 ntp.conf 中使用该选项,因为它也只接受IP 地址而不接受DNS 名称(哦!并且restrict像防火墙规则一样适用于客户端和服务器!)

iptables
  • 3 3 个回答
  • 5743 Views

3 个回答

  • Voted
  1. Kondybas
    2014-12-28T15:00:19+08:002014-12-28T15:00:19+08:00

    localnet 服务的基本ntp.conf看起来像这样

    ####
    driftfile       /etc/ntp.drift
    disable         monitor
    restrict -4     default kod nomodify nopeer noquery notrap
    restrict -6     default kod nomodify nopeer noquery notrap
    restrict        127.0.0.1
    restrict        127.127.1.0
    restrict -6     ::1
    
    restrict        10.0.0.0    mask 255.0.0.0
    restrict        172.16.0.0  mask 255.240.0.0
    restrict        192.168.0.0 mask 255.255.0.0
    
    server          0.pool.ntp.org       iburst
    server          1.pool.ntp.org       iburst
    server          2.pool.ntp.org       iburst
    ####
    

    默认情况下,最长的两条线拒绝对服务器的任何访问,然后其他restric指令仅允许特定的主机和子网。

    • 6
  2. Best Answer
    Wesley
    2014-12-28T14:35:33+08:002014-12-28T14:35:33+08:00

    您有多种选择,这取决于防火墙的放置位置和/或您喜欢使用哪些防火墙。理想情况下,您将拥有可以在子网上控制的防火墙。不太理想的是,您将只处理 NTP 服务器上的主机级防火墙。无论哪种方式,概念都是相同的。

    对于子网防火墙:

    • 仅允许来自子网的 UDP 端口 123A.B.C.10
    • 拒绝其他所有的 UDP 端口 123。

    对于 NTP 服务器上的主机防火墙:

    • 允许来自您的子网(和来自本地主机)的 UDP 端口 123
    • 拒绝来自其他任何地方的 UDP 端口 123(链中稍后的拒绝所有规则)。

    例如允许 10.0.0.0/8:

    # allow 10.0.0.0/8
    iptables -A INPUT -s 10.0.0.0/8 -p udp -m udp --dport 123 -j ACCEPT
    # allow localhost
    iptables -A INPUT -s 127.0.0.0/8 -p udp -m udp --dport 123 -j ACCEPT
    # allow NTP packets _from_ your host to everyone else
    iptables -A OUTPUT -p udp --sport 123 --dport 123 -m state --state NEW,ESTABLISHED -j ACCEPT
    # allow replies from hosts you've sent NTP packets to
    iptables -A INPUT  -p udp --sport 123 --dport 123 -m state --state ESTABLISHED -j ACCEPT
    # the following is only useful if you have a policy ACCEPT for INPUT
    iptables -A INPUT  -p udp -m udp --dport 123 -j DROP
    
    • 2
  3. adam
    2018-04-09T12:27:49+08:002018-04-09T12:27:49+08:00

    我没有发现这些答案非常有帮助,所以这对我有用。这是在运行 NTP 4.2.6p5 的机器上

    driftfile        /var/lib/ntp/ntp.drift
    statsdir /var/log/ntpstats/
    
    restrict    default ignore
    
    restrict        127.0.0.1
    restrict        127.127.1.0
    restrict -6     ::1
    
    restrict -4     <whitelist.ip.0>    mask    255.255.255.255
    restrict -4     <whitelist.ip.1>    mask    255.255.255.255
    restrict -4     <whitelist.ip.2>    mask    255.255.255.255 
    
    server      0.pool.ntp.org  iburst nomodify notrap nopeer noquery
    restrict    0.pool.ntp.org  iburst nomodify notrap nopeer noquery
    server      1.pool.ntp.org  iburst nomodify notrap nopeer noquery
    restrict    1.pool.ntp.org  iburst nomodify notrap nopeer noquery
    server      2.pool.ntp.org  iburst nomodify notrap nopeer noquery
    restrict    2.pool.ntp.org  iburst nomodify notrap nopeer noquery
    
    
    statistics loopstats peerstats clockstats
    filegen loopstats file loopstats type day enable
    filegen peerstats file peerstats type day enable
    filegen clockstats file clockstats type day enable
    

    我知道这是一个旧线程,但认为它可能会对某人有所帮助。在示例中,您应该将 whitelist.ip.0、whitelist.ip.1、whitelist.ip.2 替换为您的白名单主机。您显然也可以修改掩码参数以允许,例如 /24 网络

    • 0

相关问题

  • OpenVPN 的 Linux IP 转发 - 正确的防火墙设置?

  • iptables 单个规则中的多个源 IP

  • 存储 iptables 规则的规范方法是什么

  • 使用 iptables 和 dhcpd 进行端口转发

  • 根据 Apache 日志数据自动修改 iptables 以阻止行为不良的客户端

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