Skip to content

Instantly share code, notes, and snippets.

@pichuang
Created March 18, 2015 10:38
Show Gist options
  • Save pichuang/71f07e007c7c2d3c7da1 to your computer and use it in GitHub Desktop.
Save pichuang/71f07e007c7c2d3c7da1 to your computer and use it in GitHub Desktop.
nat and ip forwarding
#!/bin/sh
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables -X
iptables -Z
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat
iptables -A INPUT -i eth4 -s <PRIVATE_IP_SUBNET> -j ACCEPT
iptables -A INPUT -i eth0 -s <PUBLIC_IP_SUBNET> -j ACCEPT
iptables -t nat -A POSTROUTING -s <PRIVATE_IP_SUBNET> -o eth0 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 3389 -j DNAT --to-destination <TARGET_IP>:3389
iptables -A FORWARD -p tcp -d <TARGET_IP> --dport 3389 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment