Skip to content

Instantly share code, notes, and snippets.

@maurostorch
Created August 14, 2013 17:42
Show Gist options
  • Save maurostorch/6233514 to your computer and use it in GitHub Desktop.
Save maurostorch/6233514 to your computer and use it in GitHub Desktop.
#!/bin/bash
# HotSpot creating script using hostapd, dnsmasq and iptables
# Following instructions from: http://code.google.com/p/quickanddirty/wiki/CreatingWirelessHotspotWithLinux
LAN=wlan2
WAN=eth2
startap(){
# Start
# Enable routing
sysctl net.ipv4.ip_forward=1
# Cleaning NAT
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
# Configure IP address for WLAN
ifconfig $LAN down
ifconfig $LAN 192.168.0.1
iptables -A FORWARD -o $WAN -i $LAN -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
# Start DNSMasq
service dnsmasq restart
# Run access point daemon
hostapd /etc/hostapd.conf >> /var/log/hostapd 2>&1 &
}
stopap(){
# Stop
# Disable NAT
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
ifconfig $LAN down
# Disable routing
#sysctl net.ipv4.ip_forward=0
# Disable DHCP/DNS server
service dnsmasq stop
#Stop hostapd daemon
PID=`pidof hostapd || echo "not running"`
printf "Stopping hostapd..."
if [[ "$PID" != "not running" ]]; then
kill -9 $PID
printf "done\n"
else
printf "$PID\n"
fi
}
case $1 in
start)
startap
;;
stop)
stopap
;;
*)
echo "Usage: `basename ${0}` start|stop"
;;
esac
@maurostorch
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment