Dual Band Access Point Using Raspberry Pi
How to use Raspberry Pi 3B+/4 as a Dual Band Wireless Access Point.
There’s a lot of tutorials in the internet on how to setup raspberry pi as a wireless access point, but I haven’t seen anything about using it as a dual band.
Requirements
- A Raspberry Pi 3B+ or 4
- You know the basics of Rasberry Pi and you have Raspbian installed.
- USB WiFi Dongle N ( I used TP-Link TL-WN725N V3)
- An Existing LAN connection
Raspberry Pi 3B+ or 4 supports both 2.4 and 5 GHz but it does not allow using both bands simultaneously. We’ll be using the built in 5 GHz(A/C) and a USB WiFi dongle for 2.5Ghz(N) support.
Also make sure that the USB WiFi Dongle you are using is compatible with Raspberry Pi, in my case i had to setup my dongle using these drivers.
Interface Naming
On Raspberry Pi, we can access the interfaces by executing iwconfig. In normal situations that there’s nothing plugged in with the device, we should be able to see eth0 and wlan0 with the same hardware address (MAC) every time. But this behavior changes when we start to plugin the USB WiFi Dongle. We need to setup the interface names to be static so that they would not change when we reboot the raspberry pi.
Disable Predictable Names
Ironically, this feature makes it more unpredictable that it should be. We need to make sure it’s disabled on raspberry pi config.
- sudo raspi-config
- Choose Network Options
- Select N3 Network interface names
- Disable Predicable Names
Manual Interface Naming Rules
Once predictable naming is disabled, we now need to create a mapping for the interface names and their corresponding hardware address. To do this, we need to create a rule by running:
sudo nano /etc/udev/rules.d/70-persistent-net.rules
Add these entries and make sure you update the address values.
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:00:00:00:00:00", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:00:00:00:00:00", NAME="wlan1"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:00:00:00:00:00", NAME="wlan0"
You can get the address values by executing ifconfig. Also note, that in this tutorial we use wlan1 for the USB WiFi Dongle.
Setting Up the Access Point
Now we’ve setup our network interfaces, we can now proceed on setting up our access point and networking.
Installation
There’s a couple of packages we need to install. I’ll summarize what each package does, but feel free to check their full documentation.
hostapd — handles running the actual access point and its configurations like SSID and password.
dnsmasq — for handling DNS and DHCP
netfilter-persistent/iptables-persistent — for making firewall rules persistant even when we reboot.
sudo apt install hostapdsudo apt install dnsmasqsudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
Interface, Routing, and Firewall Configuration
Edit the dhcpd configuration file:
sudo nano /etc/dhcpcd.conf
At the end of the file, add the following then save:
interface wlan1
static ip_address=192.168.2.1/24
nohook wpa_supplicantinterface wlan0
static ip_address=192.168.3.1/24
nohook wpa_supplicant
We also need to enable routing and IP masquerading, this allows wireless clients to access the internet. To begin, let’s create another file with this command:
sudo nano /etc/sysctl.d/routed-ap.conf
Add the following content then save:
# https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md
# Enable IPv4 routing
net.ipv4.ip_forward=1
And for the firewall rules, we need to execute:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo netfilter-persistent save
DHCP and DNS Configuration
As for the dhcp rules, rename the default configuration file for backup and edit a new one:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
Add the following content, then save:
interface=wlan1
dhcp-range=192.168.2.2,192.168.2.10,255.255.255.0,24h
interface=wlan0
dhcp-range=192.168.3.2,192.168.3.10,255.255.255.0,24h
In this case for wlan1 its range 192.168.2.2–192.168.2.10 is equal to 9 wireless devices with a lease time of 24 hours. You can adjust these values based on what you need.
Access Point Configuration
This is the last step, we’ll need to edit hostapd’s config file by running:
sudo nano /etc/hostapd/hostapd.conf
Add the following configuration then save:
# the interface used by the AP
interface=wlan1
# "g" simply means 2.4GHz band
hw_mode=g
# the channel to use
channel=1
# limit the frequencies used to those allowed in the country
ieee80211d=1
# the country code
country_code=US
# 802.11n support
ieee80211n=1
# QoS support, also required for full speed on 802.11n/ac/ax
wmm_enabled=1# the name of the AP
ssid=Alternate_Network
# 1=wpa, 2=wep, 3=both
auth_algs=1
# WPA2 only
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=MyPassword123
But that’s only for 2.4 GHz, we’ll need to create another configuration for our 5 GHz Access Point, create a new config by executing:
sudo nano /etc/hostapd/hostapd-5g.conf
Add the following configuration and save, notice the difference from the first configuration.
# the interface used by the AP
interface=wlan0
# "a" simply means 5GHz band
hw_mode=a
# the channel to use
channel=36
# limit the frequencies used to those allowed in the country
ieee80211d=1
# the country code
country_code=US
# 802.11ac support
ieee80211ac=1
# QoS support, also required for full speed on 802.11n/ac/ax
wmm_enabled=1# the name of the AP
ssid=Alternate_Network_5G
# 1=wpa, 2=wep, 3=both
auth_algs=1
# WPA2 only
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=MyPassword123
Make sure you update the wpa_passphrase and ssid for both config.
country_code is set to US to support 5GHz.
By default, hostapd only runs the first configuration. So we’ll need to override it’s service config, we do this by:
sudo cp /lib/systemd/system/hostapd.service /etc/systemd/system/hostapd.service
Then edit the file:
sudo nano /etc/systemd/system/hostapd.service
Update it with the following changes then save:
[Unit]
Description=Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
After=network.target[Service]
Type=forking
PIDFile=/run/hostapd.pid
Restart=on-failure
RestartSec=2
#Environment=DAEMON_CONF=/etc/hostapd/hostapd.conf
EnvironmentFile=-/etc/default/hostapd
#ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF}
ExecStart=/usr/sbin/hostapd -B -P /run/hostapd.pid -B $DAEMON_OPTS /etc/hostapd/hostapd.conf /etc/hostapd/hostapd-5g.conf[Install]
WantedBy=multi-user.target
Lastly edit the hostapd environment file:
sudo nano /etc/default/hostapd
Comment some lines, makes sure it looks like this:
# Location of hostapd configuration file
#DAEMON_CONF="/etc/hostapd/hostapd.conf"# Additional daemon options to be appended to hostapd command:-
# -d show more debug messages (-dd for even more)
# -K include key data in debug messages
# -t include timestamps in some debug messages
#
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.
#
DAEMON_OPTS=" -f /tmp/hostapd.log"
Now if you reboot your Raspberry Pi, the newly created 2.4GHz and 5GHz access points should appear in your wireless devices with the SSID and Password similar to the one you setup.