Skip to content

Instantly share code, notes, and snippets.

@dsabanin
Created May 23, 2014 14:55
Show Gist options
  • Select an option

  • Save dsabanin/e53abc60fe8d7136d5a1 to your computer and use it in GitHub Desktop.

Select an option

Save dsabanin/e53abc60fe8d7136d5a1 to your computer and use it in GitHub Desktop.

Revisions

  1. dsabanin created this gist May 23, 2014.
    11 changes: 11 additions & 0 deletions port_redirect.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/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