centos7.x 端口映射

端口映射是个好东西,最近公司网访问梯子总是行一天掉一天的,但自己有一台华为5M的服务器放着没啥用,拿来做了端口映射,我本机连到华为做了跳转,网速竟比直连还快,且还稳定

记录一下配置过程

// 开启系统路由模式功能
echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
// 使内核修改生效
sysctl -p

防火墙配置

// 开启firewalld
systemctl start firewalld

// 设置IP地址伪装
firewall-cmd --add-masquerade --permanent

// 设置端口映射(port: 本地端口  toaddr: 映射服务器的IP  toport: 映射服务器的端口)
firewall-cmd --add-forward-port=port=8888:proto=tcp:toaddr=xxx.xxx.xxx.xxx:toport=8080 --permanent

// 本地端口端口监听tcp请求
firewall-cmd --zone=public --add-port=8888/tcp --permanent

// 重启firewall 
firewall-cmd --reload

// 查看所有规则
firewall-cmd --list-all

删除规则和开放的端口

//删除转发规则
firewall-cmd --permanent --zone=public --remove-forward-port=port=8888:proto=udp:toaddr=xxx.xxx.xxx.xxx:toport=8080

//永久删除卡对外开放的端口
firewall-cmd --zone=public --remove-port=8888/tcp --permanent

这样直接使用华为服务器IP加上端口8888就能直接把流量连到指定映射的服务器上

原文地址:https://www.cnblogs.com/cnsevennight/p/13141421.html