-
-
Save dsprenkels/64afb363f9dc78aede4ea7879d0c1104 to your computer and use it in GitHub Desktop.
This file contains 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 | |
function print_help() { | |
echo "Easy 4-step NAT tool" | |
echo "Usage: $0 internal-dev external-dev ip-range" | |
echo "" | |
echo "internal-dev e.g. eth0" | |
echo "external-dev e.g. wlan0" | |
echo "ip-range e.g. 192.168.0.1/24" | |
} | |
if [[ $BASH_ARGC < 3 ]]; then | |
print_help | |
else | |
echo -n "Enabling ip_forward in /proc/sys/net/" | |
echo 1 > /proc/sys/net/ipv4/ip_forward | |
echo "." | |
echo -n "Setting firewall rules... " | |
iptables -A FORWARD -i "$2" -o "$1" -m state --state RELATED,ESTABLISHED -j ACCEPT | |
iptables -A FORWARD -i "$1" -o "$2" -j ACCEPT | |
iptables -t nat -A POSTROUTING -s "$3" -o "$2" -j MASQUERADE | |
echo "done." | |
echo "You have just enabled NAT from $1 to $2 using range $3" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment