允许 ntp 的 iptables 规则是什么?

允许 ntp 的 iptables 规则是什么?

我的服务器时钟错误,因为防火墙不允许 ntp 流量。需要哪些 iptables 规则才能允许 ntp 客户端出入?

对于如何在 Ubuntu 上实施这些规则的任何建议我都表示感谢。

答案1

“出去和回来”意味着你是一个 NTP 客户端,想要与服务器对话,我猜默认情况下你可以这样做;如果你没有设置防火墙来阻止一切,并且根本没有设置 iptables,那么你将有一个“允许相关/已建立”规则,这意味着自动允许对传出请求的回复

无论如何,NTP 是 UDP 端口 123,因此,假设您是客户端并想要访问 NTP 服务器,您可以执行以下操作:

iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -j ACCEPT

这些将把规则附加到 OUTPUT 和 INPUT 链的末尾

假设你想成为一名服务员,你会这样做

iptables -A INPUT -p udp --dport 123 -j ACCEPT
iptables -A OUTPUT -p udp --sport 123 -j ACCEPT

我有一个可以实现所有防火墙规则的脚本,我从 /etc/rc.local 调用它,该脚本在我的计算机(ubuntu 8.04 LTS)启动时运行

编辑:您已澄清这是因为您是客户。在 ubuntu 的默认配置中,您不必更改任何防火墙设置即可执行此操作。您做了哪些防火墙配置?如果没有,我倾向于相信这不是防火墙问题。

答案2

# Allow NTP And Protect Port 123

iptables -A INPUT -i lo -p udp --destination-port 123 -j ACCEPT

iptables -A INPUT -p udp --source-port 123:123 -m state --state ESTABLISHED -j ACCEPT

iptables -A OUTPUT -o lo -p udp --source-port 123 -j ACCEPT

iptables -A OUTPUT -p udp --destination-port 123:123 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A INPUT -p udp --destination-port 123 -j DROP

相关内容