Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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