Skip to content

Instantly share code, notes, and snippets.

@Swop
Created July 17, 2013 23:37
Show Gist options
  • Save Swop/6025534 to your computer and use it in GitHub Desktop.
Save Swop/6025534 to your computer and use it in GitHub Desktop.
Sets a NAT redirection with IPTables (inline shell script, copy/paste into the terminal after replacing INPUT_INTERFACE, OUTPUT_INTERFACE & IP_DEST with the correct values)
echo 1 > /proc/sys/net/ipv4/ip_forward && \ # NAT redirections activation
iptables -A FORWARD -i INPUT_INTERFACE -j ACCEPT && \ # Accepts IN forward packets
iptables -A FORWARD -o OUTPUT_INTERFACE -j ACCEPT && \ # Accepts OUT forward packets
iptables -t nat -A POSTROUTING -o OUTPUT_INTERFACE -j MASQUERADE && \ # Activate masquerade
iptables -t nat -A PREROUTING -i INPUT_INTERFACE -p tcp --dport 80 -j LOG --log-level warn --log-prefix NAT: && \ # Forwarded packages are logged
iptables -t nat -A PREROUTING -i INPUT_INTERFACE -p tcp --dport 80 -j DNAT --to IP_DEST:80 # Incoming packets on port 80 of INPUT_INTERFACE are sent to IP_DEST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment