![Centos 7 Firewalld 更改本地连接的源地址](https://linux22.com/image/1535152/Centos%207%20Firewalld%20%E6%9B%B4%E6%94%B9%E6%9C%AC%E5%9C%B0%E8%BF%9E%E6%8E%A5%E7%9A%84%E6%BA%90%E5%9C%B0%E5%9D%80.png)
我的服务器上使用的是 CentOS 7。我有一个应用程序只接受来自本地主机的连接。问题在于,防火墙会将本地连接更改为使用外部地址作为源连接。这会导致应用程序拒绝连接,因为它不是本地的。
在本地主机上监听 4444 端口
$ nc 127.0.0.1 -l 4444 -v
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Listening on 127.0.0.1:4444
连接到本地主机
$ nc 127.0.0.1 4444
hello
监听 nc 实例打印
Ncat: Connection from external_address.
Ncat: Connection from external_address:45274.
hello
以下是受信任区域的防火墙配置,其中 lo 是
$ firewall-cmd --zone=trusted --list-all
trusted (active)
interfaces: lo
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
这是有意为之还是一个错误?有没有什么简单的解决方案可以修复它?
编辑:
IP 地址设置
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:25:90:7d:8a:96 brd ff:ff:ff:ff:ff:ff
inet 173.234.39.178/29 brd 173.234.39.183 scope global enp2s0
valid_lft forever preferred_lft forever
inet 173.234.39.179/16 brd 173.234.255.255 scope global enp2s0
valid_lft forever preferred_lft forever
inet 173.234.39.180/16 brd 173.234.255.255 scope global secondary enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::225:90ff:fe7d:8a96/64 scope link
valid_lft forever preferred_lft forever
3: enp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:25:90:7d:8a:97 brd ff:ff:ff:ff:ff:ff
4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
link/none
inet 10.2.0.1 peer 10.2.0.2/32 scope global tun0
valid_lft forever preferred_lft forever
路由
$ ip route list
default via 173.234.39.177 dev enp2s0 proto static metric 100
10.2.0.0/24 via 10.2.0.2 dev tun0
10.2.0.2 dev tun0 proto kernel scope link src 10.2.0.1
173.234.0.0/16 dev enp2s0 proto kernel scope link src 173.234.39.179 metric 100
173.234.39.176/29 dev enp2s0 proto kernel scope link src 173.234.39.178 metric 100
信任区域的防火墙配置
$ firewall-cmd --zone=trusted --list-all
trusted (active)
interfaces: lo
sources:
services:
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules: