- Device: Raspberry Pi 3B
- OS: Raspberry Pi OS (bookworm)
- No extra WiFi adapter or shield
- An existing upstream WiFi connection
On the single integrated chip of RPi3, the existing WiFi network will be re-broadcasted as another WiFi network. The resulting setup will act not exactly as an access point (which converts ethernet to wireless), but as a repeater or an extender.
The aim is to extend an existing connection to dead zones, or in my case, to convert settings (e.g. changing from WPA2-Enterprise to WPA2-Personal).
Caution
Works but limited throughput and may sometimes drop connections.
We will use the built-in WiFi for both upstream and created networks. The dependencieas are nl80211, hostapd, dnsmasq and nftables.
- Start with setting up the reqired packages.
sudo apt update
sudo apt install hostapd dnsmasq nftables
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl enable dnsmasq
sudo systemctl enable nftables- Built-in WiFi (or upstream) connects to
wlan0interface. We will create another interface asap0on the same adapter chip with a static IP192.168.4.1. To configure the packages, update following files as given in the attached files here:
/etc/hostapd/hostapd.conf- Configures AP definition. Insert desired network name and password here./etc/default/hostapd- Point to default config file forhostapdservice/etc/dnsmasq.conf- Defines DNS masking address range (DHCP for the AP subnet).
It is best to backup the original file for dnsmasq package by:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig- We will create a virtual interface
ap0and assign a static IP to it by establishing the related service in the following steps. Here, we are tellingNetworkManagerto ignoreap0so it won't assign DHCP IPs.
sudo nano /etc/NetworkManager/conf.d/unmanaged.conf- Enable IP forwarding as
bookwormusesnftablestool. Apply the changes you made and add set of rules to NAT.
sudo nano /etc/sysctl.d/routed-ap.conf
sudo sysctl --system
sudo nano /etc/nftables.conf
sudo nft -f /etc/nftables.conf
sudo systemctl restart nftablesYou can check the changed ruleset by nft list ruleset.
- The built-in chip can do AP + client only if you create a virtual interface. So here in this step, we will create one named
ap0and wrap it in a system service for convenience. The configuration given guaranteesap0exists beforehostapdlaunches.
sudo nano /etc/systemd/system/ap0.service
sudo systemctl daemon-reload
sudo systemctl enable ap0.service- Finally, arrange system service order of the rest of the packages. So that, system will do:
wlan0device exists β createap0(addsap0, assigns static IP and brings it up) βhostapd(binds toap0) βdnsmasq(binds toap0) βnftables(sets NAT rules)
- Update
sudo systemctl edit hostapdwith:
[Unit]
Requires=ap0.service
After=ap0.service- Update
sudo systemctl edit nftableswith:
[Unit]
Requires=hostapd.service
After=hostapd.service- Update
sudo systemctl edit dnsmasqwith:
[Unit]
Requires=hostapd.service
After=hostapd.serviceLast step is to apply changes above sudo systemctl daemon-reload. After rebooting the system, the order of services may be checked by sudo systemd-analyze blame.
Use sudo raspi-config or the GUI to connect wlan0 to your WiFi as usual. Don't forget to check WiFi country code selection. Finally, check your incoming internet connection:
iwgetid
ping -c3 8.8.8.8Then, reboot once to be apply effects - sudo reboot or restart the pipeline that has just been configured:
sudo systemctl restart ap0
sudo systemctl restart hostapd
sudo systemctl restart dnsmasq
sudo systemctl restart nftablesAt this point, you should have wlan0 connected to your upstream Wi-Fi (internet) and ap0 broadcasting the indicated SSID network via 192.168.4.1/24. Please check IP addresses and desired UP flag with ip addr command.
Those can be helpful in case you encountered an issue:
ip addrshould show both interfacesUPwith correct IPs.iw listandiw devmust show AP mode support onap0and managed onwlan0. Also, they should be on the same channel with normal transmit power ratings.journalctl -u <package> | tail -n20orsudo systemctl status -l <package>will show why a certain service failed (wrong channel, interface missing, etc.). For example, look for the following lines inhostapdlog:
ap0: interface state UNINITIALIZED->ENABLED
ap0: AP-ENABLED- Ensure correct system service ordering by
sudo systemd-analyze blame. It is convenient to...| grep <service>to easily observe CPU starting time of the given service. Also,sudo systemctl list-dependencies <service>should output desired dependencies for that service. - Do not use automatic channel selection by
channel=0withhostapdsettings as it takes forever. - The following checks should unmanaged
ap0(static IP) andwlan0connected to upstream network.
nmcli dev status
iwgetid- There should be no block on the adapters, if so, unblock them:
sudo rfkill list all
sudo rfkill unblock all- Lastly, check firmware and driver issues for Broadcomm. If necessary, update them. Although, usually, the error you get here roots from the running order of the services.
lsmod | grep -E "brcmfmac|brcmutil|cfg80211|mac80211"
dmesg | grep -iE "brcm|bcm|wlan|cfg80211" | tail -n50