我想问一下关于firewalld转发端口规则的问题。
我正在使用的操作系统是,
CentOS Linux release 7.3.1611 (Core)
将请求转发给127.0.0.1:80上的httpd监听
[root@development /]# netstat -atunp | grep httpd tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 2601/httpd
我已经设置了firewalld规则如下。
[root@development /]# firewall-cmd --list-all --zone=external external (active) target: default icmp-block-inversion: no interfaces: eth0 sources: services: ssh ports: protocols: masquerade: yes forward-ports: sourceports: icmp-blocks: rich rules: rule family="ipv4" forward-port port="8080" protocol="tcp" to-port="80"
但是,如果我从外部主机发送请求,则firewalld将拒绝对端口8080的请求。
在这种情况下,
192.168.11.2(客户端)——-> 192.168.11.13(8080)
[root@dellinspiron13z asset]# curl -XGET 192.168.11.13:8080 curl: (7) Failed to connect to 192.168.11.13 port 8080: Connection refused
如果该进程运行为0.0.0.0:80 ,则完美运行。
有没有办法将请求redirect到localhost端口?
你必须在地址92.168.11.13的接口上更改sysctl中的route_localnet,或者如果你懒惰
在幸运的巧合,我有新的CentOS与相同的版本,所以默认这个旋钮是禁用的
[root@tesla ~]# cat /etc/centos-release CentOS Linux release 7.3.1611 (Core) [root@tesla ~]# sysctl -a | grep route_localnet net.ipv4.conf.all.route_localnet = 0 net.ipv4.conf.default.route_localnet = 0 net.ipv4.conf.enp0s5.route_localnet = 0 net.ipv4.conf.lo.route_localnet = 0