为什么 iptables 不阻塞任何端口?

Buv*_*inJ 1 firewall iptables port

我运行了 iptables 并应用了最新的规则(即我重新启动了服务,它说一切都“正常”)。

我只使用 system-config-firewall 来编辑/定义任何规则,所以我不应该有手动创建的错误。如果我可以避免它,我不想手动编辑它。

我以为我已经配置了它,以便我的 Apache 端口80443将打开,但不是 Tomcat 正在侦听的端口(即80808443)。然而,事实并非如此......我可以在任何机器上毫无问题地浏览它们。

最终我确实希望可以访问 Tomcat 端口,但我不明白为什么它们已经存在。我希望我需要明确打开它们。

此外,在我添加规则以显式打开它们之前,我的所有邮件端口也都可以访问(110, 143, 587, 993, 995...)同样,我确实希望打开它们,但我不明白为什么它们总是如此?

这是我的 iptables 输出。为什么一切似乎都是开放的?可能是因为没有OUTPUT规则?另外,为什么会有看似重复的规则?system-config-firewall 不控制此类重复项吗?我怎样才能清理它?我想只能通过手动编辑...

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1     2834  692K ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2        5   511 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0
3       14   990 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
4      114  6717 ACCEPT     all  --  eth0   *       0.0.0.0/0            0.0.0.0/0
5        0     0 ACCEPT     all  --  eth1   *       0.0.0.0/0            0.0.0.0/0
6        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
7        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
8        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443
9        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25
10       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:993
11       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:995
12       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22
13       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80
14       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:443
15       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:993
16       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:995
17       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:110
18       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:143
19       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:587
20       0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:465
21       0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination
1        0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2        0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0
3        0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
4        0     0 ACCEPT     all  --  eth0   *       0.0.0.0/0            0.0.0.0/0
5        0     0 ACCEPT     all  --  eth1   *       0.0.0.0/0            0.0.0.0/0
6        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 3208 packets, 1537K bytes)
num   pkts bytes target     prot opt in     out     source               destination
Run Code Online (Sandbox Code Playgroud)

Ond*_*idr 5

请参见 INPUT 链中的第 3、4 和 5 行 - 这些规则允许来自接口 eth0、eth1 和 lo 的任何端口的任何数据包通过。IPTables 与 first-match-rule 一起使用,因此当数据包获得允许/拒绝它的第一个规则时,它会被应用。您应该只设置精确端口的规则并拒绝任何其他流量。