Last active
May 9, 2017 06:11
-
-
Save corerman/4c93a820cfff467a99bfe5554485171d to your computer and use it in GitHub Desktop.
iptables 中转流量 (端口范围)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vi /etc/sysctl.conf | |
将 net.ipv4.ip_forward=0 | |
修改成 net.ipv4.ip_forward=1 | |
sysctl -p | |
iptables -L -n -t nat 看规则列表 | |
iptables -t nat -F 清空原有的nat规则 | |
iptables -t nat -Z 清空原有的nat规则 | |
iptables -F 清空所有的正常规则 | |
iptables -X 清空所有的正常规则 | |
iptables -Z 清空所有的正常规则 | |
service iptables stop 停止iptables | |
ifconfig 服务器IP(主要是看非内部循环的网卡IP) | |
iptables -t nat -A PREROUTING -p tcp --dport 端口1:端口2 -j DNAT --to-destination 外部服务器IP:端口1:端口2 | |
iptables -t nat -A POSTROUTING -p tcp -d 外部服务器IP --dport 端口1:端口2(外部服务器) -j SNAT --to-source vps网络ip | |
iptables -t nat -A PREROUTING -p udp --dport 端口1:端口2 -j DNAT --to-destination 外部服务器IP:端口1:端口2 | |
iptables -t nat -A POSTROUTING -p udp -d 外部服务器IP --dport 端口1:端口2(外部服务器) -j SNAT --to-source vps网络ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make public