iptables forwarding script, basic and working
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 | |
if [ $UID != 0 ]; then echo "Please run as root"; exit 1; fi | |
SUBNET_ADDRESS='10.0.0.1' | |
SUBNET_RANGE='10.0.0.2,10.0.0.100,12h' | |
INTERNET="eno1" #upstream | |
SUBNET="enp7s0f0" #downstream | |
ifconfig "$SUBNET" "$SUBNET_ADDRESS" #set your ip for downstream | |
#ip addr add "$SUBNET_ADDRESS" dev "$SUBNET" | |
dnsmasq --interface="$SUBNET" --except-interface=lo --bind-interfaces --dhcp-range="$SUBNET_RANGE" #host a lil dhcp guy | |
echo 1 > /proc/sys/net/ipv4/ip_forward | |
iptables -A FORWARD -i "$SUBNET" -o "$INTERNET" -j ACCEPT | |
iptables -A FORWARD -i "$INTERNET" -o "$SUBNET" -m state --state ESTABLISHED,RELATED -j ACCEPT | |
iptables -t nat -A POSTROUTING -o "$INTERNET" -j MASQUERADE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment