添加防火墙规则会产生多个条目

添加防火墙规则会产生多个条目

我正在尝试向我的 Ubuntu 14 iptables 添加一条规则以允许 NTP (123),尽管使用以下命令允许特定端口上的传入流量 基本 iptables 怎样操作?

这是我的命令:

sudo iptables -A INPUT -p tcp --dport ntp -j ACCEPT

运行该命令后,我在 iptables -L 中看到如下条目:

ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ntp

因此,我使用两个外部站点对该端口进行端口扫描,结果都显示该端口已关闭。因此我重新启动,没有任何变化。然后我想从 iptables 中删除该条目:

DROP       tcp  --  anywhere             anywhere             tcp dpt:ntp

这并没有产生预期的效果,因为现在我有类似这样的东西:接受 tcp -- 任何地方 tcp dpt:ntp 接受 tcp -- 任何地方 tcp dpt:ntp 丢弃 tcp -- 任何地方 tcp dpt:ntp 接受 tcp -- 任何地方 tcp dpt:ntp

我决定就此打住,因为我不确定我做错了什么。我需要运行什么命令才能真正打开端口?

答案1

据我所知,NTP 适用于 UDP。因此,您可以尝试以下操作:

sudo iptables -A OUTPUT -p udp --dport 123 --sport 1024:65535 -j ACCEPT
sudo iptables -A INPUT -p udp --sport 123 --dport 1024:65535 -j ACCEPT

相关内容