目前我尝试使用 firewall-cmd 为 CentOS 设置端口转发。
目前我的盒子有两个接口(interface):eth0、eth1。
eth0 代表内部网络,在 zone=public(默认),
eth1 代表外网,在 zone=external
当前 eth1 连接到另一个网络,该网络包含一个通往互联网的路由器。
我的外部防火墙如下所示:
external (active)
target: default
icmp-block-inversion: no
interfaces: eth1
sources: 192.168.178.0/24
services: dhcpv6-client http https ssh
ports: 1194/udp
protocols:
masquerade: yes
forward-ports: port=1194:proto=udp:toport=:toaddr=192.168.179.4
sourceports:
icmp-blocks:
rich rules:
我也有 22 端口的规则:
firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=22:toaddr=192.168.179.8
然而,这两个规则都不起作用,1194 和端口 22 的规则都不起作用。
实际上,我测试了我们路由器的端口转发是否适用于机器,事实上它确实如此,因为如果我将 HAPROXY 设置为指向另一台 SSH 机器:
frontend sshd
bind 192.168.178.254:22
mode tcp
default_backend ssh
timeout client 1h
backend ssh
mode tcp
server static 192.168.179.8:22 check
并删除
port=22
规则,我可以连接到它。我实际上是按照宽松的 selinux 规则运行的。
公共(public)区域如下所示:
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources: 192.168.179.0/24
services: dhcpv6-client http https ssh
ports: 7583/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
有什么我想念的吗?
我的意思是我也试图让它与 iptables 一起工作,但它根本没有用。
sysctl net.ipv4.ip_forward
返回 net.ipv4.ip_forward = 1
Linux Box 不是这两个网络的默认路由器。两者都有其他路由器。
最佳答案
看起来两个网络都需要打开伪装:
firewall-cmd --zone=external --permanent --add-masquerade
firewall-cmd --zone=public --permanent --add-masquerade
firewall-cmd --reload
关于centos - firewall-cmd centos 端口转发似乎不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44670927/