INPUT 链中的过滤不适用于 docker 转发端口

INPUT 链中的过滤不适用于 docker 转发端口

我有一台运行 docker 应用程序的 Linux 服务器,它将 docker 内的 80 端口暴露给主机上的 20080。

服务器有 IP 地址10.10.10.10,我需要阻止10.10.10.11访问该10.10.10.10:20080端口。

然而,在 INPUT 链上添加 DROP 不起作用,端口仍然可以访问。有任何想法吗?

附完整的 iptables 规则:

# iptables-save
# Generated by iptables-save v1.8.7 on Thu Jul  6 22:26:24 2023
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:DOCKER - [0:0]
:DOCKER-ISOLATION-STAGE-1 - [0:0]
:DOCKER-ISOLATION-STAGE-2 - [0:0]
:DOCKER-USER - [0:0]
-A INPUT -p tcp -m tcp --dport 20080 -j DROP
-A FORWARD -p tcp -m tcp --dport 20080 -j DROP
-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-643859f655c0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o br-643859f655c0 -j DOCKER
-A FORWARD -i br-643859f655c0 ! -o br-643859f655c0 -j ACCEPT
-A FORWARD -i br-643859f655c0 -o br-643859f655c0 -j ACCEPT
-A DOCKER -d 172.17.0.4/32 ! -i docker0 -o docker0 -p tcp -m tcp --dport 80 -j ACCEPT
-A DOCKER -d 172.17.0.4/32 ! -i docker0 -o docker0 -p tcp -m tcp --dport 22 -j ACCEPT
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -i br-643859f655c0 ! -o br-643859f655c0 -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-643859f655c0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
COMMIT
# Completed on Thu Jul  6 22:26:24 2023
# Generated by iptables-save v1.8.7 on Thu Jul  6 22:26:24 2023
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
-A POSTROUTING -s 172.18.0.0/16 ! -o br-643859f655c0 -j MASQUERADE
-A POSTROUTING -s 172.17.0.4/32 -d 172.17.0.4/32 -p tcp -m tcp --dport 80 -j MASQUERADE
-A POSTROUTING -s 172.17.0.4/32 -d 172.17.0.4/32 -p tcp -m tcp --dport 22 -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
-A DOCKER -i br-643859f655c0 -j RETURN
-A DOCKER ! -i docker0 -p tcp -m tcp --dport 20080 -j DNAT --to-destination 172.17.0.4:80
-A DOCKER ! -i docker0 -p tcp -m tcp --dport 20022 -j DNAT --to-destination 172.17.0.4:22
COMMIT
# Completed on Thu Jul  6 22:26:24 2023

相关内容