我现在需要设置 iptables 为:允许 22 端口访问,然后禁止外网的访问+允许局域网访问,iptables 如下:
iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- localhost/8 anywhere
ACCEPT tcp -- 10.0.0.0/8 anywhere
ACCEPT tcp -- 172.16.0.0/12 anywhere
ACCEPT tcp -- 192.168.0.0/16 anywhere
DROP tcp -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (0 references)
target prot opt source destination
Chain DOCKER-ISOLATION-STAGE-1 (0 references)
target prot opt source destination
Chain DOCKER-ISOLATION-STAGE-2 (0 references)
target prot opt source destination
Chain DOCKER-USER (0 references)
target prot opt source destination
现在问题来了,我设置好之后发现在这台机器上无法 tcp 去访问外网,我先清空 iptables 之后用 wget 先建立 tcp 连接然后 netstat 查看连接如下:
netstat -anp | grep wget
tcp 0 0 172.23.54.173:34670 52.216.134.43:443 ESTABLISHED 7727/wget
可以看到 wget 的 source 是 172.23.54.173 的内网私有 ip,而这个私有 ip 我在 iptables 里面的ACCEPT tcp -- 172.16.0.0/12 anywhere已经覆盖了啊,为啥我无法 tcp 访问外网啊?