Skip to content

Instantly share code, notes, and snippets.

@atlury
Forked from Lewiscowles1986/rPi3-ap-setup.sh
Created March 20, 2016 09:20
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atlury/fe0ea8b91a981c103df7 to your computer and use it in GitHub Desktop.
Save atlury/fe0ea8b91a981c103df7 to your computer and use it in GitHub Desktop.
Raspberry Pi 3 access-point-setup
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Must be root"
exit
fi
if [[ $# -ne 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 ]];
$APSSID=$2
fi
apt-get remove --purge hostapd -y
apt-get install hostapd dnsmasq -y
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=$APNAME
EOF
sed -i -- 's/exit 0/ /g' /etc/rc.local
cat >> /etc/rc.local <<EOF
ifconfig wlan0 down
ifconfig wlan0 10.0.0.1 netmask 255.255.255.0 up
iwconfig wlan0 power off
service dnsmasq restart
hostapd -B /etc/hostapd/hostapd.conf & > /dev/null 2>&1
exit 0
EOF
echo "All done!"
@GHsubroto
Copy link

Dear Atlury,

I have just loaded noobs and have created a media server. Now I want to use the PI3 wifi as Access point. The code looks very useful. Now please tell me,

  1. how should I use this code in Terminal of PI3. Should I copy and paste the entire code in terminal?
  2. It seems you have created IP address of PI-AP as 10.0.0.1 is it correct? Will remail static IP for PI-AP?

I am novice in PI coding etc. If I am asking some silly question, please forgive me.

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