阻止所有内部流量,除了来自单个端口上特定 ip 的传入流量
blocking all internal traffic except incoming traffic from a specific ip on a single port
我正在尝试使用 IPtables 来阻止除一台服务器之外的所有内部流量,这是我的规则,但是当我从另一个实例远程登录时,我仍然可以连接....
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION-STAGE-1
-N DOCKER-ISOLATION-STAGE-2
-N DOCKER-USER
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -o br-383efc983cd2 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o br-383efc983cd2 -j DOCKER
-A FORWARD -i br-383efc983cd2 ! -o br-383efc983cd2 -j ACCEPT
-A FORWARD -i br-383efc983cd2 -o br-383efc983cd2 -j ACCEPT
-A DOCKER -d 172.18.0.3/32 ! -i br-383efc983cd2 -o br-383efc983cd2 -p tcp -m tcp --dport 1080 -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -i br-383efc983cd2 ! -o br-383efc983cd2 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -o br-383efc983cd2 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -s 10.0.1.253/32 -i eth1 -p tcp -m tcp --dport 22 -j ACCEPT
-A DOCKER-USER -m state --state ESTABLISHED -j ACCEPT
-A DOCKER-USER -i eth1 -j REJECT --reject-with icmp-port-unreachable
-A DOCKER-USER -j RETURN
调试iptables时我一般:
- 重置所有计数器 - 'iptables -Z'
- 建立联系
- 然后查看规则命中 - 'iptables -L -v -n |more'
这应该会给您一些关于哪个规则正在传递连接的指示
我正在尝试使用 IPtables 来阻止除一台服务器之外的所有内部流量,这是我的规则,但是当我从另一个实例远程登录时,我仍然可以连接....
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N DOCKER
-N DOCKER-ISOLATION-STAGE-1
-N DOCKER-ISOLATION-STAGE-2
-N DOCKER-USER
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -o br-383efc983cd2 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o br-383efc983cd2 -j DOCKER
-A FORWARD -i br-383efc983cd2 ! -o br-383efc983cd2 -j ACCEPT
-A FORWARD -i br-383efc983cd2 -o br-383efc983cd2 -j ACCEPT
-A DOCKER -d 172.18.0.3/32 ! -i br-383efc983cd2 -o br-383efc983cd2 -p tcp -m tcp --dport 1080 -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -i br-383efc983cd2 ! -o br-383efc983cd2 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -o br-383efc983cd2 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -s 10.0.1.253/32 -i eth1 -p tcp -m tcp --dport 22 -j ACCEPT
-A DOCKER-USER -m state --state ESTABLISHED -j ACCEPT
-A DOCKER-USER -i eth1 -j REJECT --reject-with icmp-port-unreachable
-A DOCKER-USER -j RETURN
调试iptables时我一般:
- 重置所有计数器 - 'iptables -Z'
- 建立联系
- 然后查看规则命中 - 'iptables -L -v -n |more'
这应该会给您一些关于哪个规则正在传递连接的指示