Skip to content

Instantly share code, notes, and snippets.

@jameshilliard
Created December 16, 2014 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshilliard/45d4bcf840533116bf07 to your computer and use it in GitHub Desktop.
Save jameshilliard/45d4bcf840533116bf07 to your computer and use it in GitHub Desktop.
#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -t nat -F
iptables -X
YourIP=myip
YourPort=3333
TargetIP=destip
TargetPort=3333
iptables -t nat -A PREROUTING --dst $YourIP -p tcp --dport $YourPort -j DNAT \
--to-destination $TargetIP:$TargetPort
iptables -t nat -A POSTROUTING -p tcp --dst $TargetIP --dport $TargetPort -j SNAT \
--to-source $YourIP
iptables -t nat -A OUTPUT --dst $YourIP -p tcp --dport $YourPort -j DNAT \
--to-destination $TargetIP:$TargetPort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment