Centos7 配置端口转发

场景: 有两台服务器主机,希望通过A主机的8080端口间接访问B主机的80 端口。

#开启系统路由模式功能
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
#运行这个命令会输出上面添加的那一行信息,意思是使内核修改生效
sysctl -p
#开启firewalld
systemctl start firewalld
#开启8080端口监听tcp请求
firewall-cmd --zone=public --add-port=8080/tcp --permanent
#设置IP地址伪装
firewall-cmd --add-masquerade --permanent
#设置端口映射
firewall-cmd --add-forward-port=port=8080:proto=tcp:toaddr=192.168.2.100:toport=80--permanent
firewall-cmd --add-masquerade --permanent
#重启firewall
firewall-cmd --reload

发布了192 篇原创文章 · 获赞 254 · 访问量 76万+

猜你喜欢

转载自blog.csdn.net/yulei_qq/article/details/102786533