11/2/23, 14:24 Using a Raspberry Pi 3 as a Wifi access point and bridge · GitHub
Instantly share code, notes, and snippets.
umardx / Pi3_as_WiFi_AP_Bridge.md
Last active 2 days ago
Star
Code Revisions 5 Stars 12 Forks 5
Using a Raspberry Pi 3 as a Wifi access point and bridge
Pi3_as_WiFi_AP_Bridge.md
The specificity of my setup, is that the Raspberry won’t be a router but a bridge. DHCP
is thus delegated to the main ADSL router and all devices connected to the AP will
appear on the same network than other devices. The instructions below are based on a
fresh Raspbian lite install so that it can be reproduced easily.
Install the required packages :
$ sudo apt-get install -y bridge-utils hostapd
To create a bridge, we need to enable ip_forward in the kernel, for that, edit
/etc/sysctl.conf and remove comment ( # ) from the following line :
net.ipv4.ip_forward=1
Then configure your network to create a bridge with eth0 , in
/etc/network/interfaces :
auto lo
iface lo inet loopback
# Disable eth0 / wlan0 config, handled by bridge
auto eth0
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
# Create a bridge with static IP
https://gist.github.com/umardx/23cc3ad93119151a16f486c7cf01096c 1/3
11/2/23, 14:24 Using a Raspberry Pi 3 as a Wifi access point and bridge · GitHub
auto br0
iface br0 inet dhcp
bridge_ports eth0
You may have noticed that wlan0 is not configured in bridge br0. This is because
hostapd will handle this once the access point is ready. So, next step is to configure the
access point. For this, edit the file /etc/hostapd/hostapd.conf :
# First part is about configuring the access point and is copied from
reference 1
interface=wlan0
driver=nl80211
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
# This part is about setting SSID and WPA2 password
ssid=wifi_ssid
wpa_passphrase=wifi_password
# This line ask hostapd to add wlan0 to the bridge br0
bridge=br0
Now we need to tell hostapd to use our config. For that, edit /etc/default/hostapd
and set:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Ok, here we go, just reboot the Pi and waaaw!
sudo reboot
asimonrose commented on Apr 14, 2020
Hello. Thank you for the approach above. This worked best for me, having looked at a couple of other
solutions, including the routing options.
A couple of observations following your instructions above:
https://gist.github.com/umardx/23cc3ad93119151a16f486c7cf01096c 2/3
11/2/23, 14:24 Using a Raspberry Pi 3 as a Wifi access point and bridge · GitHub
I had to unmask and enable hostapd for this to work:
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
I also needed to add in country_code=GB to the hostapd.conf file
I think because I'd not unmasked and enabled hostapd initially, I got a "soft block" on the wlan0 interface
- that needed unblocking using :
rfkill unblock all
tempeet commented on Apr 26, 2020
is it possible to make wlan1 the client and wlan0 the ap?
siard-y commented on Oct 11, 2020
Good lord I've tried to get this to work for many hours and this one works immediately. Thanks a ton!
guyromb commented on Jan 14, 2021
is there a way to route the RPi connected devices via VPN on top?
Radiokot commented on Jan 16, 2021
Thank you for the config. allow-hotplug wlan0 is really an important thing I've missed
PabloL007 commented on Feb 5, 2022
Thanks for sharing this, I've also spent a while trying to get this to work on a pi 4 and this is the first thing
that worked (used my own hostapd.conf though).
https://gist.github.com/umardx/23cc3ad93119151a16f486c7cf01096c 3/3