Skip to content

Instantly share code, notes, and snippets.

@MitchRatquest
Last active April 17, 2019 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MitchRatquest/ecede20f243bc92b422abde67dc3b3c3 to your computer and use it in GitHub Desktop.
Save MitchRatquest/ecede20f243bc92b422abde67dc3b3c3 to your computer and use it in GitHub Desktop.
iptables forwarding script, basic and working
#!/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