我正在尝试设置 firewalld 规则将 80/tcp 转发到 8080-8081,该规则设置正确,但似乎只是部分工作。
问题是流量总是转发到8080而不是8081,有什么问题吗?
以下是我的环境:
firewall-cmd --add-forward-port='port=80:proto=tcp:toport=8080-8081' --permanent
下面是我的 firewalld 设置:
防火墙-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens160
sources:
services: ssh dhcpv6-client
ports: 80/tcp
protocols:
masquerade: yes
forward-ports: port=80:proto=tcp:toport=8080-8081:toaddr=
source-ports:
icmp-blocks:
rich rules:
sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
最佳答案
tl;dr Firewalld 未指定 random
使用 DNAT 范围时。
端口范围传递给 iptables
/nftables
这反过来利用内核中的连接跟踪。连接跟踪实际上是在做 DNAT(转发端口)。它从范围中选择一个端口。默认情况下,它线性搜索范围。因此,如果连接跟踪当前没有元组条目(dip、sip、dprot、sport 等),则 8080
将会被使用。仅当所有 ( 8080
, 运动) 对都已在使用时,才会 dport 8081
被考虑。
您应该file an upstream firewalld issue .我想使用 random
在生成的 DNAT 规则中将给出预期的结果。
关于centos7 - centos firewall-cmd 端口转发到一系列目标端口不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50922427/