-
-
Save devisnotnull/5d582e1ca38eef40fc81c5191a5f7fd1 to your computer and use it in GitHub Desktop.
Setup port forwarding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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