端口转发

PlanB Linux评论5,061阅读模式
yum install iptables-services 安装 iptables
echo 1 >/proc/sys/net/ipv4/ip_forward 或者 编辑文件/etc/sysctl.conf,修改net.ipv4.ip_forward = 0为net.ipv4.ip_forward = 1
iptables -t nat -A PREROUTING -p tcp --dport 8000:65535 -j DNAT --to-destination xx.xx.xx.xx
iptables -t nat -A POSTROUTING -p tcp -d xx.xx.xx.xx --dport 8000:65535 -j SNAT --to-source xx.xx.xx.xx
iptables -I FORWARD -p tcp --dport 8000:65535 -j ACCEPT
iptables -I FORWARD -p tcp --sport 8000:65535 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 8000:65535 -j ACCEPT
iptables -I INPUT -p udp -m udp --dport 8000:65535 -j ACCEPT
service iptables save
service iptables restart

TCP&UDP转发
iptables -t nat -A PREROUTING -p tcp --dport 45608 -j DNAT --to-destination xx.xx.xx.xx:xx
iptables -t nat -A POSTROUTING -p tcp -d xx.xx.xx.xx --dport 443 -j SNAT --to-source yy.yy.yy.yy
iptables -t nat -A PREROUTING -p udp --dport 45608 -j DNAT --to-destination xx.xx.xx.xx:xx
iptables -t nat -A POSTROUTING -p udp -d xx.xx.xx.xx --dport 443 -j SNAT --to-source yy.yy.yy.yy
iptables -I FORWARD -p tcp --dport 80:65535 -j ACCEPT
iptables -I FORWARD -p tcp --sport 80:65535 -j ACCEPT
iptables -I FORWARD -p udp --dport 80:65535 -j ACCEPT
iptables -I FORWARD -p udp --sport 80:65535 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 80:65535 -j ACCEPT
iptables -I INPUT -p udp -m udp --dport 80:65535 -j ACCEPT
service iptables save
service iptables restart

转发本地端口
iptables -t nat -A PREROUTING -p tcp --dport 38650 -j REDIRECT --to-ports 443
iptables -t nat -A PREROUTING -p udp --dport 38650 -j REDIRECT --to-ports 443

weinxin
我的微信
我的微信
微信扫一扫
 
PlanB
  • 本文由 PlanB 发表于 2021年12月17日12:16:43
  • 转载请务必保留本文链接:https://kper.net/889.html
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖动滑块以完成验证