centos7系统firewalld环境下:
主要参考:
1. 使用非Root用户启动tomcat(使用80端口)
https://blog.csdn.net/xiaohe73/article/details/83413213
2. 腾讯云 centos 开发端口
https://www.jianshu.com/p/d457ed35563b
3. centos7配置端口转发
https://blog.csdn.net/weixin_41423450/article/details/92768221
4. centos出现“FirewallD is not running”怎么办:
https://www.cnblogs.com/rxbook/p/8110143.html
将本机的 8080端口转发至其他主机(或者本机的外网ip):
主机 IP:192.168.1.162,目标主机 IP和端口 192.168.1.163:80,方法如下:
开启防火墙伪装:firewall-cmd --add-masquerade --permanent //开启后才能转发端口
添加转发规则:firewall-cmd --add-forward-port=port=8080:proto=tcp:toport=80:toaddr=192.168.1.163 --permanent
(PS:此规则将本机8080端口转发到192.168.1.163的80端口上,配置完firewall-cmd --reload才生效)
如果配置完以上规则后仍不生效,检查防火墙是否开启80端口,如果80端口已开启,仍无法转发,可能是由于内核参数文件sysctl.conf未配置ip转发功能,具体配置如下:
vim /etc/sysctl.conf
在文本内容中添加:net.ipv4.ip_forward = 1
保存文件后,输入命令sysctl -p生效
#!/bin/bash
#开启系统路由模式功能
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
#运行这个命令会输出上面添加的那一行信息,意思是使内核修改生效
sysctl -p
#开启firewalld
systemctl start firewalld
#开启4650端口监听tcp请求
firewall-cmd --zone=public --add-port=4650/tcp --permanent
#设置IP地址伪装
firewall-cmd --add-masquerade --permanent
#设置端口映射
firewall-cmd --add-forward-port=port=4650:proto=tcp:toaddr=203.205.128.15:toport=465 --permanent
firewall-cmd --add-masquerade --permanent
#重启firewall
firewall-cmd --reload