我正在configuration一个服务器,我尝试了一些我认为是非常简单的iptables规则:
[root host ~] - iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere REJECT all -- anywhere loopback/8 reject-with icmp-port-unreachable ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:www ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh ACCEPT icmp -- anywhere anywhere icmp echo-request Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination [root host ~] - iptables -P INPUT DROP
这导致了我的SSH会话挂起。 现在我无法通过SSH访问机器,但所有其他的津贴(HTTP等)似乎工作正常。
事实上,我做了一些更多的研究,但对我来说这仍然是一个正确的configuration。
在我看来,我误解了过滤iptables提供的过滤。 是这样吗? 这张照片有什么问题?
编辑:我从debian的iptables文章适应我的规则,所以你可以看到那里的原始input行。
双编辑:我应该在这里做腿部的工作; 我已经重新创build了Debian文章的原始input
-A INPUT -i lo -j ACCEPT -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p tcp --dport 80 -j ACCEPT -A INPUT -p tcp --dport 443 -j ACCEPT -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
这个规则是相当可疑的:
REJECT all -- anywhere loopback/8 reject-with icmp-port-unreachable
除非你确定它不适用于loopback接口(lo),否则它可能会破坏各种各样的东西。
原来问题是我的第二条规则:
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
我愚蠢地没有仔细检查VPS上的接口,并且由于它是基于OpenVZ的,所以内部虚拟接口的地址为127.0.0.2,但是在技术上并不是在这个规则的环回。
编辑:没有; 我又错了! 事实certificate,实际上,我的VPS允许插入基于状态的规则,但从来没有匹配过它们,所以当我将策略设置为DROP时,已build立的连接正在被丢弃。