建立与阻塞端口的连接,这是什么意思?

建立与阻塞端口的连接,这是什么意思?

我对系统管理还很陌生,我一直在尝试熟悉 netsat 之类的工具。如果我netstat -n在服务器上运行,我会看到以下行:

tcp        0      0 xxx.xxx.xxx.xxx:44573          xxx.xxx.xxx.xxx:443         ESTABLISHED

但是,我使用的 iptables 默认策略为 DROP,而 44573 不是我允许流量通过的端口之一。我在 iptables 中的规则如下所示:

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:pcsync-https state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:21022 state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ftp state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpts:65500:65534
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:webcache state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:https state ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            icmp echo-reply
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request
ACCEPT     all  --  anywhere             anywhere
ACCEPT     udp  --  anywhere             anywhere            udp spt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:smtp state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http limit: avg 25/min burst 100

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:pcsync-https state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:21022 state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:https state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:ftp state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:webcache state ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https state NEW,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere            icmp echo-request
ACCEPT     icmp --  anywhere             anywhere            icmp echo-reply
ACCEPT     all  --  anywhere             anywhere
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:smtp state ESTABLISHED

有人能解释一下吗?我理解错了吗?

答案1

最可能的解释是,您看到从您的计算机到 HTTPS 端口的出站连接。端口 44573 是临时端口当您的计算机上的某个程序发出出站 HTTPS 请求时,该程序就被赋予了该权限。

netstat没有具体显示出站与入站,但由于您没有任何程序在端口 44573 上侦听,端口 44573 在临时端口范围内,并且远程计算机的端口(443)不在临时端口范围内(并且是用于通用服务器协议的端口),因此可以合理地保证它是一个出站连接。

答案2

埃文说得很正确。

顺便说一句,你有:

链输出(策略接受)

然后是OUTPUT链中的一系列ACCEPT规则,而没有REJECT规则,因此除了会计输出之外是完全开放的。

如果这是您想要的,那就没问题。。但我希望看到一个 LOG 规则,以便您可以在 OUTPUT 规则中看到“意外但仍允许的流量”,在 INPUT 规则中看到“意外和被拒绝的流量”。

另外,如果你对数据包记账不是特别感兴趣,你可以在 INPUT/OUTPUT 的顶部添加一条综合规则“--state RELATED,ESTABLISHED -j ACCEPT”

相关内容