Skip to content

Instantly share code, notes, and snippets.

@devisnotnull
Created September 28, 2017 14:43
Show Gist options
  • Save devisnotnull/5d582e1ca38eef40fc81c5191a5f7fd1 to your computer and use it in GitHub Desktop.
Save devisnotnull/5d582e1ca38eef40fc81c5191a5f7fd1 to your computer and use it in GitHub Desktop.
Setup port forwarding
#!/bin/bash
# https://serverfault.com/questions/532569/how-to-do-port-forwarding-redirecting-on-debian
IPTBL=/sbin/iptables
IF_IN=eth0
PORT_IN=40022
IP_OUT=172.16.93.128
PORT_OUT=22
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTBL -A PREROUTING -t nat -i $IF_IN -p tcp --dport $PORT_IN -j DNAT --to-destination ${IP_OUT}:${PORT_OUT}
$IPTBL -A FORWARD -p tcp -d $IP_OUT --dport $PORT_OUT -j ACCEPT
$IPTBL -A POSTROUTING -t nat -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment