Skip to content

Instantly share code, notes, and snippets.

@Lewiscowles1986
Last active July 16, 2023 15:33
Show Gist options
  • Save Lewiscowles1986/fecd4de0b45b2029c390 to your computer and use it in GitHub Desktop.
Save Lewiscowles1986/fecd4de0b45b2029c390 to your computer and use it in GitHub Desktop.
Raspberry Pi 3 access-point-setup
#!/bin/bash
#
# This version uses September 2017 august stretch image, please use this image
#
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
if [[ $# -lt 1 ]];
then echo "You need to pass a password!"
echo "Usage:"
echo "sudo $0 yourChosenPassword [apName]"
exit
fi
APPASS="$1"
APSSID="rPi3"
if [[ $# -eq 2 ]]; then
APSSID=$2
fi
apt-get remove --purge hostapd -yqq
apt-get update -yqq
apt-get upgrade -yqq
apt-get install hostapd dnsmasq -yqq
cat > /etc/dnsmasq.conf <<EOF
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.5,255.255.255.0,12h
EOF
cat > /etc/hostapd/hostapd.conf <<EOF
interface=wlan0
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
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
EOF
sed -i -- 's/allow-hotplug wlan0//g' /etc/network/interfaces
sed -i -- 's/iface wlan0 inet manual//g' /etc/network/interfaces
sed -i -- 's/ wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf//g' /etc/network/interfaces
sed -i -- 's/#DAEMON_CONF=""/DAEMON_CONF="\/etc\/hostapd\/hostapd.conf"/g' /etc/default/hostapd
cat >> /etc/network/interfaces <<EOF
# Added by rPi Access Point Setup
allow-hotplug wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
EOF
echo "denyinterfaces wlan0" >> /etc/dhcpcd.conf
systemctl enable hostapd
systemctl enable dnsmasq
sudo service hostapd start
sudo service dnsmasq start
echo "All done! Please reboot"
@Lewiscowles1986
Copy link
Author

@bengefferies, the dhcpcd5 should come first as you may lose internet. Same for the adapter pass-through script. They should at least be downloaded before running any script

@RCCRAFT1
Copy link

Thank you for this! I couldn't find anything else on what to do.

@dixon1e
Copy link

dixon1e commented May 28, 2020

@bkis your script calls out correctly "systemctl unmask hostapd" and for dnsmasq also are now required to start the services.

Running this script as is fails because services are now masked by default.

Thank you and thank you to the author @Lewiscowles1986.

@dixon1e
Copy link

dixon1e commented May 28, 2020

For those interested, my configuration uses a USB Wireless Adapter (Edimax which is Realtek RTL8188CUS) in addition to the built in WiFi for Raspberry Pi 3.

When executing this script, the internal WiFi is defeated and does not start. I will attempt debug and report here for those searching for such a configuration and why it stops the internal WiFi. All help is welcome if someone knows why this is happening.

@Lewiscowles1986
Copy link
Author

Lewiscowles1986 commented May 30, 2020

@bkis please link to your own blog in future.

I've edited the comment to be in a <details><summary> block. Please don't respond with long-form content, this really isn't the place for it.

It's quite enough to maintain something, without many people offering additional changes, or polluting scope with things that are separate.

There is other advice in this thread to backup if you wish to switch between AP and Original interfaces from 2016, as well as a script to keep newer raspbians connecting and a separate bridge script. They are all separate parts and not meant to be combined within the context of this Gist.

I've deliberately stayed away from dual purpose AP/NON-AP mode. It's a complication

@Lewiscowles1986
Copy link
Author

This script is actually a little old now. I will try to find time to work on it, but the debian network stack has changed.

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