Raspberry Pi Wirless Access Point
Features
- Access Point Server: (ap0) : LAN
- Accept WiFi Clients
- Provied IP address via DHCP (Allows reserved IPs/MAC binding)
- Provied Internet access via NAT
- WiFi Client: (wlan0) : WAN
- Able to connect to other Access Points via its WAN (wlan0)
- Obtain IP address via DHCP client from External Access Point
Configuration
Access Point
Interface: ap0
SSID: Pi-0-WiFi-AP
WPA2: 20pa33w0rd20
Network: 10.0.66.0/24
IP Address: 10.0.66.1
ap0 MAC:
WiFi Client
Interface: wlan0
Setting it Up
Disable IPv6
ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 2: wlan0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
Add New 802.11 Interface
Note the 1st line must match the real MAC of wlan0 otherwise ap0 will not initialize.
sudo nano /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="ieee80211", ACTION=="add|change", ATTR{macaddress}=="b8:27:eb:ff:ff:ff", KERNEL=="phy0", \ RUN+="/sbin/iw phy phy0 interface add ap0 type __ap", \ RUN+="/bin/ip link set ap0 address b8:27:eb:ff:ff:ff"
sudo reboot
ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 2: wlan0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 3: ap0: mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
Install Dnsmasq & Hostapd
DNSMasq will be used as a DHCP Server and HostAPD as a WiFi Access Point
sudo apt install dnsmasq hostapd -y
After this operation, 2,666 kB of additional disk space will be used. Do you want to continue? [Y/n] y
sudo systemctl status dnsmasq
dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server Loaded: loaded (/lib/systemd/system/dnsmasq.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2099-13-33 00:01:53 BST; 1min 53s ago Main PID: 677 (dnsmasq) CGroup: /system.slice/dnsmasq.service └─677 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -r /run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service --tru
Modify /etc/dnsmasq.conf
sudo nano /etc/dnsmasq.conf
interface=lo,ap0
no-dhcp-interface=lo,wlan0
bind-interfaces
server=8.8.8.8
domain-needed
bogus-priv
dhcp-range=192.168.99.50,192.168.99.150,12h
dhcp-host=ee:ee:ee:33:33:33,reservedhostname,192.168.99.151
Modify /etc/hostapd/hostapd.conf
Care is needed with hostapd.conf. Many problems were encountered while trying to set this up. Just to name a few issues ssid was too short, so was the password, a blank line at the end also. The errors that will get thrown are very generic and make troubleshooting difficult.
sudo nano /etc/hostapd/hostapd.conf
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
interface=ap0
driver=nl80211
ssid=PiAccessPoint
hw_mode=g
channel=11
wmm_enabled=0
macaddr_acl=0
auth_algs=1
wpa=2
wpa_passphrase=pipassword1
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
Modify /etc/default/hostapd
sudo nano /etc/default/hostapd
DAEMON_CONF=”/etc/hostapd/hostapd.conf”
sudo systemctl status hostapd
hostapd.service Loaded: masked (Reason: Unit hostapd.service is masked.) Active: inactive (dead)
sudo systemctl unmask hostapd.service
sudo systemctl enable hostapd.service
Removed /etc/systemd/system/hostapd.service. Synchronizing state of hostapd.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable hostapd
Populate Networks
WPA supplicat is used to define the networks that the WAN interface (wlan0) will connect to.
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Or you can do this via
sudo raspi-config>Network Options>Wireless LAN
Modify /etc/network/interfaces
sudo nano /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and ‘man dhcpcd.conf’
#Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
auto ap0
auto wlan0
iface lo inet loopback
allow-hotplug ap0
iface ap0 inet static
address 192.168.99.1
netmask 255.255.255.0
hostapd /etc/hostapd/hostapd.conf
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface AP1 inet dhcp
iface AP2 inet dhcp
Unreliable Results
Automated Workaround
touch fix-ap-wifi.sh
chmod +x fix-ap-wifi.sh
nano fix-ap-wifi.sh
#!/bin/bash
sleep 30
sudo ifdown –force wlan0 && sudo ifdown –force ap0 && sudo ifup ap0 && sudo ifup wlan0
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -s 192.168.99.0/24 ! -d 192.168.99.0/24 -j MASQUERADE
sudo systemctl restart dnsmasq
Related
- Raspberry Pi Links
- Raspberry Pi Problems and Fixes
- Auto Update Raspberry Pi Using a Script and Cron
- What is taking up space on Raspberry Pi
- Enable Two Factor Authentication on Raspberry Pi
- New Raspberry Pi Desktop Setup
- VNC Access to Raspberry Pi from Ubuntu
- Install WireGuard on Raspberry Pi Zero W
- Pi Camera Essentials
Links
- https://www.raspberrypi.org/products/raspberry-pi-zero/