Skip to content

Instantly share code, notes, and snippets.

@aceberg
Created March 19, 2012 06:35
Show Gist options
  • Save aceberg/2099109 to your computer and use it in GitHub Desktop.
Save aceberg/2099109 to your computer and use it in GitHub Desktop.
Port forwarding in iptables
#!/bin/bash
IPTABLES="/sbin/iptables"
GW_IP="X.X.X.X"
SERVER_IP="10.0.2.15"
GW_PORT=7080
S_PORT=8080
$IPTABLES -t nat -A PREROUTING -p tcp --dst $GW_IP --dport $GW_PORT -j DNAT --to-destination $SERVER_IP:$S_PORT
$IPTABLES -t nat -I POSTROUTING -p tcp --dst $SERVER_IP --dport $S_PORT -j SNAT --to $GW_IP
echo 1 > /proc/sys/net/ipv4/ip_forward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment