Created
June 4, 2017 21:48
-
-
Save JamesHagerman/49c8264b0968aa449a97d5ae521691e6 to your computer and use it in GitHub Desktop.
Simple script to enable ip forwarding for basic routing
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 | |
logger "Telling kernel to turn on ipv4 ip_forwarding" | |
echo 1 > /proc/sys/net/ipv4/ip_forward | |
logger "Done. Setting up iptables rules to allow FORWARDING" | |
DOWNSTREAM=wlan0 # wlan0 is client network (running hostapd) | |
UPSTREAM=eth0 # eth0 is upstream network (internet) | |
# Allow IP Masquerading (NAT) of packets from clients (downstream) to upstream network (internet) | |
iptables -t nat -A POSTROUTING -o $UPSTREAM -j MASQUERADE | |
# Forward packets from downstream clients to the upstream internet | |
iptables -A FORWARD -i $DOWNSTREAM -o $UPSTREAM -j ACCEPT | |
# Forward packers from the internet to clients IF THE CONNECTION IS ALREADY OPEN! | |
iptables -A FORWARD -i $UPSTREAM -o $DOWNSTREAM -m state --state RELATED,ESTABLISHED -j ACCEPT | |
logger "Done setting up iptables rules. Forwarding enabled" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment