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就能直接把流量連到指定映射的服務器上

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM