Setting up a Wi-Fi Access Point¶
Setup a Wi-Fi Access Point in the Raspberry¶
Assign a static ip address to wlan0
sudo nano /etc/network/interfaces
Set the following lines of code:
# for Internet Connection Sharing
auto wlan0
iface wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
gateway 10.0.0.1
Install dnsmasq server¶
Dnsmasq provides network infrastructure for small networks: DNS, DHCP and network boot
Install dnsmasq server package
sudo apt-get install dnsmasq
Setup the dnsmasq server We set the range of the IPs that will be assigned to the clients
sudo nano /etc/dnsmasq.conf
# ADD THE FOLLOWING LINES
interface=wlan0
dhcp-range=10.0.0.10,10.0.0.240,255.255.255.0,6h
Edit the file Hosts
sudo nano /etc/hosts
#ADD THE FOLLOWING LINES AT THE BOTTOM
10.0.0.1 local.mazizone.eu
10.0.0.1 portal.mazizone.eu
Restart the dnsmasq server
sudo service dnsmasq restart
Install hostapd¶
Hostapd (Host access point daemon) is a user space software access point capable of turning normal network interface cards into access points and authentication servers.
Install hostapd package
sudo apt-get install hostapd
Ιnitialize hostapd
sudo nano /etc/hostapd/hostapd.conf
add these lines of code:
interface=wlan0
driver=nl80211
ssid=THE_NAME_OF_YOUR_WIFI_NETWORK
hw_mode=g
channel=11
wpa=1
wpa_passphrase=SECRETPASSWORD
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
wpa_ptk_rekey=600
macaddr_acl=0
Caution
You should change the ssid and wpa_passphrase to your preferences
Note
In case you want an access point without password add a # in front of all the lines starting with wpa
Start the access point by running hostapd
sudo ifdown wlan0
sudo hostapd -d /etc/hostapd/hostapd.conf
Or run hostapd in the background
sudo ifdown wlan0
sudo hostapd -B /etc/hostapd/hostapd.conf
Note
In case the hostapd is not starting, you should bring down the wlan0 interface, then bring it up again and restart the dnsmasq server.
sudo ifdown wlan0
sudo ifup wlan0
sudo service dnsmasq restart
Start everything at boot¶
Add the following lines of code to the rc.local file before exit 0. This is a mechanism to not turn on the WiFi Access Point on boot, unless the installation of dependencies during an update is finished.
sudo nano /etc/rc.local
FILE="/etc/mazi/update-lock"
x=0
#### Wait the Update to finish before you setup the Hostapd ####
#### timeout in 1800sec=30min ####
while [ $x -lt 1800 ] && [ -e $FILE ]; do
x=$((x+1))
sleep 1
done
if [ ! -f $FILE ]
then
echo "Update finished"
bash /root/back-end/mazi-wifi.sh start
else
echo "Update is not properly finished"
fi
echo '-------------------------------------------------------'
MAZI backend¶
mazi-wifiap.sh¶
Note
For the configuration of the Wi-Fi Access Point you can also use the MAZI backend script mazi-wifiap.sh. Check more info here.
Examples:
- Set the Wi-Fi SSID to mazizone, the channel to 6 and the password to “mazizone”.
sudo sh mazi-wifiap.sh -s mazizone -c 6 -p mazizone
- Set the Wi-Fi SSID to John
sudo sh mazi-wifiap.sh -s John
- Change the password of the Wi-Fi network to pass
sudo sh mazi-wifiap.sh -p pass
- You can simply start (or restart the Wi-Fi Access Point if it is already started) without passing any argument
sudo sh mazi-wifiap.sh
mazi-antenna.sh¶
Note
After connecting an external USB Wi-Fi Adapter (check here for compatible products), you can configure it using the MAZI backend script mazi-antenna.sh. Check more info here.
Examples:
- List the available Wi-Fi networks in range of the toolkit
sudo sh mazi-antenna.sh -l
- Connect to the Wi-Fi “mazi-network” with password “mazi-pass”
sudo sh mazi-antenna.sh -s mazi-network -p mazi-pass
- Connect to hidden Wi-Fi network “mazi-test”
sudo sh mazi-antenna.sh -h -s mazi-test
mazi-router.sh¶
Note
After connecting an external OpenWRT Wireless Router (check here for compatible products), you can use it as a Wi-Fi Access Point instead of the on-board Wi-Fi antenna of the Raspberry for better network characteristics (coverage, speed etc.). The corresponding MAZI backend script is mazi-router.sh. Check more info here.
First, install requirements
sudo apt-get install sshpass
Examples:
- Display the status of the router (connected or not)
sudo sh mazi-router.sh -s
- Activate the Router with the current hostapd settings
sudo sh mazi-router.sh -a
- Deactivate the Router and move the Access Point the on-board Wi-Fi antenna
sudo sh mazi-router.sh -d