Skip to content

Instantly share code, notes, and snippets.

@seth10
Created September 27, 2016 20:55
Show Gist options
  • Save seth10/4f514762e4408d93178ca1f788779013 to your computer and use it in GitHub Desktop.
Save seth10/4f514762e4408d93178ca1f788779013 to your computer and use it in GitHub Desktop.
Make a PiStorms host an access point to control it from your phone directly
#!/bin/bash
# update list of available packages
sudo apt-get -y update
# hostapd - This is the package that allows you to use the built in WiFi as an access point
# dnsmasq - This is a combined DHCP and DNS server that's very easy to configure
sudo apt-get -y install dnsmasq hostapd
echo -e "\ndenyinterfaces wlan0" >> /etc/dhcpcd.conf
# comment out preset wlan0 interface config lines
sudo sed -i "14,16s/^/#/" /etc/network/interfaces
# configure static network
echo "
allow-hotplug wlan0
iface wlan0 inet static
address 10.21.1.1
netmask 255.255.255.0
network 10.21.1.0
broadcast 10.21.1.255" | sudo tee -a /etc/network/interfaces > /dev/null
echo "interface=wlan0
driver=nl80211
ssid=pistormsclassroom
# use the 2.4GHz band
hw_mode=g
channel=6
# enable 802.11n
ieee80211n=1
wmm_enabled=1
# enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# accept all MAC addresses
macaddr_acl=0
# use WPA authentication
auth_algs=1
# require clients to know the network name
ignore_broadcast_ssid=0
# use WPA2
wpa=2
# use a pre-shared key
wpa_key_mgmt=WPA-PSK
wpa_passphrase=pistormsclassroom
# use AES, instead of TKIP
rsn_pairwise=CCMP" | sudo tee -a /etc/hostapd/hostapd.conf > /dev/null
# tell hostapd where to look for the config file when it starts up on boot
sudo sed -i 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/' /etc/default/hostapd
# backup default dnsmasq config file
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
echo "interface=wlan0
listen-address=10.21.1.1
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv # Never forward addresses in the non-routed address spaces
dhcp-range=10.21.1.50,10.21.1.150,12h # Assign IP addresses between 10.21.1.50 and 10.21.1.150 with a 12 hour lease time" | sudo tee -a /etc/dnsmasq.conf > /dev/null
sudo sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/" /etc/sysctl.conf
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo sed -i "\$i iptables-restore < \/etc\/iptables.ipv4.nat" /etc/rc.local
sudo service hostapd start
sudo service dnsmasq start
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment