Skip to content

Instantly share code, notes, and snippets.

@dsabanin
Created May 23, 2014 14:55
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 dsabanin/e53abc60fe8d7136d5a1 to your computer and use it in GitHub Desktop.
Save dsabanin/e53abc60fe8d7136d5a1 to your computer and use it in GitHub Desktop.
Script for setting up redirect for a local port to a remote host's port (root or sudo needed)
#!/bin/sh
TARGET_HOST=9.9.9.9
TARGET_PORT=22
PROXY_PORT=23
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $PROXY_PORT -j DNAT --to $TARGET_HOST:$TARGET_PORT
iptables -t nat -A PREROUTING -p tcp --dport $PROXY_PORT -j DNAT --to $TARGET_HOST:$TARGET_PORT
iptables -t nat -A POSTROUTING -p tcp -d $TARGET_HOST --dport $TARGET_PORT -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment