Skip to content

Instantly share code, notes, and snippets.

@walchko
Forked from Lewiscowles1986/rPi3-ap-setup.sh
Last active May 20, 2018 03:04
Show Gist options
  • Save walchko/6c247bd60a7a0ca267a6714beb6a0777 to your computer and use it in GitHub Desktop.
Save walchko/6c247bd60a7a0ca267a6714beb6a0777 to your computer and use it in GitHub Desktop.
Raspberry Pi 3 access-point-setup
#!/bin/bash
#
# This version uses September 2016 rpi jessie image, please use this image
# Modified to:
# setup access point on wlan1
# network is 10.10.10.x
# SSID is hostname
# password is robotsarecool
#
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit 1
fi
# if [[ $# -lt 1 ]];
# then echo "You need to pass a password!"
# echo "Usage:"
# echo "sudo $0 yourChosenPassword [apName]"
# exit
# fi
APPASS="robotsarecool"
APSSID=`uname -n`
# if [[ $# -eq 2 ]]; then
# APSSID=$2
# fi
apt-get remove --purge hostapd -y
apt-get install hostapd dnsmasq -y
# double check /etc/init.d/hostapd is not there, if so delete it
cat > /etc/systemd/system/hostapd.service <<EOF
[Unit]
Description=Hostapd IEEE 802.11 Access Point
After=sys-subsystem-net-devices-wlan1.device
BindsTo=sys-subsystem-net-devices-wlan1.device
[Service]
Type=forking
PIDFile=/var/run/hostapd.pid
ExecStart=/usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/hostapd.pid
[Install]
WantedBy=multi-user.target
EOF
cat > /etc/dnsmasq.conf <<EOF
interface=wlan1
dhcp-range=10.10.10.5,10.10.10.100,255.255.255.0,24h
EOF
cat > /etc/hostapd/hostapd.conf <<EOF
interface=wlan1
hw_mode=g
channel=10
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=$APPASS
ssid=$APSSID
EOF
# delete previous wlan1 entry, note, wpa-conf get wipped out everywhere
sed -i -- 's/allow-hotplug wlan1//g' /etc/network/interfaces
sed -i -- 's/iface wlan1 inet manual//g' /etc/network/interfaces
sed -i -- 's/ wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf//g' /etc/network/interfaces
# need to add back wpa-conf
cat >> /etc/network/interfaces <<EOF
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
# Added by setup-access-point.sh
allow-hotplug wlan1
iface wlan1 inet static
address 10.10.10.1
netmask 255.255.255.0
network 10.10.10.0
broadcast 10.10.10.255
EOF
echo "denyinterfaces wlan1" >> /etc/dhcpcd.conf
systemctl enable hostapd
echo "All done! Please reboot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment