Skip to content

Instantly share code, notes, and snippets.

@gearhead
Created December 26, 2023 12:08
Show Gist options
  • Save gearhead/1941ae3a0efcf219efa97de7be2e9bc2 to your computer and use it in GitHub Desktop.
Save gearhead/1941ae3a0efcf219efa97de7be2e9bc2 to your computer and use it in GitHub Desktop.
How to use iwd ap mode instead of hostapd/dnsmasq for RPi wireless config
Previously using hostapd/dnsmask to have the RPi boot up in AP mode so that it can be configured.
iwd is faster and smoother than hostapd. I was getting kicked off before I could configure the RPi
This capability has been in iwd since 2022
connman can be used with iwd in tethering mode, but this does not allow for any configuration of the AP.
Another way is to use iwd in ap mode on a virtual nic.
I got my ideas from here:
https://lore.kernel.org/linux-wireless/87k0dhdg0d.fsf@bang-olufsen.dk/
https://iwd.wiki.kernel.org/ap_mode
# make sure that /etc/iwd/main.conf has this line in it
EnableNetworkConfiguration=true
# create a virtual interface on wlan0
iw dev wlan0 interface add ap0 type __ap
# give this virtual interface a different MAC than the wlan0
# you could index the existing wlan0 MAC by 1, but this works
ip link set dev ap0 address b8:27:eb:00:00:00
# restart iwd
systemctl restart iwd
# use iwctl to set it in ap mode
iwctl device ap0 set-property Mode ap
# create an AP config in /var/lib/ap/testAP.ap with these contents
[General]
DisableHT=true
[Security]
Passphrase=password123
[IPv4]
Address=192.168.250.1
Gateway=192.168.250.1
Netmask=255.255.255.0
DNSList=8.8.8.8
# start ap
iwctl ap ap0 start-profile testAP
# if you need NAT run this
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -s 192.168.250.0/24 -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment