宇筱博客

  • 解决办法
  • 学无止境
  • 记录时光
  • 百宝箱
宇筱博客
点滴记忆,汇聚成海。
  1. 首页
  2. 解决办法
  3. 正文

CentOS 6/7 开启端口转发的代码

2021年1月3日 471点热度 0人点赞 0条评论

以下代码以本机81端口转发到本机80端口为例

CentOS 6 使用iptables实现:

echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
sysctl -p
iptables -A INPUT -m tcp -p tcp --dport 81 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 81 -j REDIRECT --to-ports 80
service iptables save
service iptables restart

CentOS 7 使用firewalld实现:

echo net.ipv4.ip_forward=1>>/etc/sysctl.conf
sysctl -p
firewall-cmd --zone=public --add-port=81/tcp --permanent
firewall-cmd --add-masquerade --permanent
firewall-cmd --add-forward-port=port=81:proto=tcp:toport=80 --permanent
firewall-cmd --reload
原文链接:http://blog.cccyun.cn/post-397.html
标签: 暂无
最后更新:2022年1月25日

小渔民

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2025 宇筱博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备15017825号-2