Skip to content

Instantly share code, notes, and snippets.

@seanhsu0102
Last active January 27, 2016 10:17
Show Gist options
  • Save seanhsu0102/a4040fd58413703f23c4 to your computer and use it in GitHub Desktop.
Save seanhsu0102/a4040fd58413703f23c4 to your computer and use it in GitHub Desktop.
iptables foward port to other IP
```bash
# 啟用 IP forward 預設為 0 = off 避免被當跳板
$ echo '1' > /proc/sys/net/ipv4/ip_forward
# 把你要導的 port 導到想導的 IP:PORT 去
$ iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination 192.168.1.1:443
# 使用你的外部 IP 當做 forward 出去所看到的 PORT
$ iptables -t nat -A POSTROUTING -j MASQUERADE
# 清空 iptable NAT規則
$ iptables -t nat -F
# 請小心使用避免你自己被關在 server 外永遠進不去
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment