Skip to content

Instantly share code, notes, and snippets.

@cburbridge
Created January 21, 2015 11:54
Show Gist options
  • Save cburbridge/3ee13fb45a4f05ea7e1e to your computer and use it in GitHub Desktop.
Save cburbridge/3ee13fb45a4f05ea7e1e to your computer and use it in GitHub Desktop.
#!/bin/bash
# Echo commands and abort on errors
set -x
set -e
# Define network interfaces:
IFACE_WAN=wlan0
IFACE_LAN=eth0
# Clean
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables -t nat -F
# Do masquerade
iptables -A FORWARD -i $IFACE_WAN -o $IFACE_LAN -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $IFACE_LAN -o $IFACE_WAN -j ACCEPT
iptables -t nat -A POSTROUTING -o $IFACE_WAN -j MASQUERADE
# Enable packet forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
# Allow DNS requests from LAN
iptables -A INPUT -p udp -i $IFACE_LAN --dport 53 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment