Last active
September 11, 2019 08:00
-
-
Save tsertkov/5470c501ef37275eddb3a15cd4b4e95a to your computer and use it in GitHub Desktop.
Forward ports through a Linux gateway with iptables
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
#!/usr/bin/env bash | |
i_in=en0 | |
i_out=en1 | |
dport=1234 | |
dst=1.2.3.4 | |
src=4.3.2.1 | |
iptables -A FORWARD -i $i_in -o $i_out -p tcp --syn --dport $dport -m conntrack --ctstate NEW -j ACCEPT | |
iptables -A FORWARD -i $i_out -o $i_in -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | |
iptables -t nat -A PREROUTING -i ens5 -p tcp --dport $dport -j DNAT --to-destination $dst | |
iptables -t nat -A POSTROUTING -o ens5 -p tcp --dport $dport -d $dst -j SNAT --to-source $src |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment