Created
March 11, 2015 19:41
-
-
Save cutaway/1358f4d458c3fee99411 to your computer and use it in GitHub Desktop.
setup_wpe.sh is a bash script to prepare a system to run hostapd-wpe.
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 | |
################ | |
# setup_wpe.sh | |
# Author: Don C. Weber (@cutaway) | |
# Purpose: Setup interfaces for hostapd-wpe. This will enable dnsmesq so that the interfaces are ready to serve up an Internet | |
# connection for any clients that maintain a connection to the system. Additional configuration of dnsmasq and | |
# hostapd-wpe required. | |
# | |
################ | |
######################################################## | |
# Settings for /etc/dnsmasq | |
# Source: https://nims11.wordpress.com/2013/05/22/using-hostapd-with-dnsmasq-to-create-virtual-wifi-access-point-in-linux/ | |
######################################################## | |
# # Disable checking /etc/resolv.conf | |
# no-resolv | |
# # Interface to provide DHCP | |
# interface=wlan1 | |
# # DHCP Address Range and lease time | |
# # Interface should be assigned 192.168.5.1/24 | |
# dhcp-range=192.168.5.2,192.168.5.254,12h | |
# # DNS Servers | |
# server=8.8.8.8 | |
# server=8.8.4.4 | |
######################################################## | |
# Run using sudo | |
# Make sure only root can run our script | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
on() { | |
echo "Disabling Network Manager's Wireless Control." | |
nmcli nm wifi off | |
sleep 1 | |
rfkill unblock wlan | |
sleep 1 | |
ifconfig eth0 down | |
sleep 1 | |
ifconfig wlan0 down | |
sleep 1 | |
ifconfig wlan1 down | |
sleep 1 | |
ifconfig wlan2 down | |
sleep 1 | |
ifconfig eth0 up | |
sleep 1 | |
dhclient eth0 | |
sleep 1 | |
ifconfig wlan0 up | |
sleep 1 | |
ifconfig wlan1 up | |
sleep 1 | |
ifconfig wlan1 192.168.5.1 netmask 255.255.255.0 | |
sleep 1 | |
ifconfig wlan2 up | |
sleep 1 | |
echo "Setting up IP_Forwarding." | |
sysctl -w net.ipv4.ip_forward=1 | |
sleep 1 | |
###########Start dnsmasq, modify if required########## | |
if [ -z "$(ps -e | grep dnsmasq)" ] | |
then | |
dnsmasq | |
fi | |
########### | |
sleep 1 | |
#Enable NAT | |
iptables --flush | |
iptables --table nat --flush | |
iptables --delete-chain | |
iptables --table nat --delete-chain | |
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE | |
iptables --append FORWARD --in-interface wlan1 -j ACCEPT | |
return 0 | |
} | |
off() { | |
echo "Enabling Network Manager's Wireless Control." | |
killall dnsmasq | |
sleep 1 | |
echo "Disabling IP_Forwarding." | |
sysctl -w net.ipv4.ip_forward=0 | |
sleep 1 | |
iptables --flush | |
iptables --table nat --flush | |
iptables --delete-chain | |
iptables --table nat --delete-chain | |
iptables --flush | |
sleep 1 | |
nmcli nm wifi on | |
sleep 1 | |
ifconfig eth0 down | |
sleep 1 | |
ifconfig wlan0 down | |
sleep 1 | |
ifconfig wlan1 down | |
sleep 1 | |
ifconfig wlan2 down | |
sleep 1 | |
ifconfig eth0 up | |
sleep 1 | |
dhclient eth0 | |
sleep 1 | |
ifconfig wlan0 up | |
sleep 1 | |
ifconfig wlan1 up | |
sleep 1 | |
ifconfig wlan2 up | |
return 0 | |
} | |
restart() { | |
on | |
sleep 3 | |
off | |
} | |
case "$1" in | |
off) | |
off | |
;; | |
on) | |
on | |
;; | |
restart) | |
restart | |
;; | |
*) | |
echo "Usage: $0 {off|on|restart}" | |
exit 1 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment