Setting up a Raspberry Pi as a WiFi access point using
hostapd allows you to create a dedicated wireless network for devices that lack internet connectivity or require a local-only environment. This configuration enables mobile devices to discover the SSID, associate with the Pi, and obtain IP addresses via DHCP while ensuring proper DNS resolution if upstream routing is required.
Prerequisites and Hardware Selection
Before configuring the software stack, ensure your Raspberry Pi model supports the necessary wireless standards. Most modern models, including the Raspberry Pi 3, 4, and 5, have built-in dual-band WiFi capabilities. However, older models like the Raspberry Pi Zero W may only support 2.4 GHz networks. If you are using an external USB WiFi adapter, verify that it supports Access Point (AP) mode by checking its chipset compatibility. Adapters based on the Realtek RTL8812AU or similar chipsets often provide better performance for AP duties than standard integrated modules in high-density scenarios.
You will need a fresh installation of Raspberry Pi OS (either Lite or Desktop). The Lite version is preferred for server-like roles to reduce overhead. Ensure your system is fully updated before proceeding by running
sudo apt update && sudo apt upgrade -y. This step resolves potential dependency issues with
hostapd and
dnsmasq, which are the core components for this setup.
Configuring the Network Interface
The first technical hurdle is assigning a static IP address to the WiFi interface so that connected clients can route traffic back to the Pi. By default, the interface may use DHCP from another router, which conflicts with the AP role. You must edit the network configuration file located at
/etc/dhcpcd.conf.
Add the following lines to the end of the file, replacing
wlan0 with your specific interface name if different:
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
The
nohook wpa_supplicant directive is critical. It prevents the system from trying to manage the WiFi connection as a client, freeing the interface for
hostapd to control. After saving the file, restart the dhcpcd service with
sudo systemctl restart dhcpcd. Verify the interface has the correct IP by running
ip addr show wlan0.
Installing and Configuring Hostapd
Hostapd acts as the authentication server, allowing devices to connect to the network. Install it using
sudo apt install hostapd. Once installed, disable the service temporarily to prevent it from interfering with our manual configuration:
sudo systemctl stop hostapd and
sudo systemctl disable hostapd.
Create a new configuration file at
/etc/hostapd/hostapd.conf. A minimal secure configuration looks like this:
interface=wlan0
driver=nl80211
ssid=MyRaspberryPiAP
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=YourStrongPassword123
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Key parameters include
hw_mode=g for 2.4 GHz 802.11g/n support,
channel=7 to select a non-overlapping channel, and
wpa_passphrase for security. For WPA3 support, additional drivers and kernel versions may be required, but WPA2 remains the most compatible standard for general consumer devices. Save the file and test the configuration syntax with
sudo hostapd -d /etc/hostapd/hostapd.conf. If no errors appear, press Ctrl+C to exit.
To make
hostapd persistent, edit
/etc/default/hostapd and uncomment the line
DAEMON_CONF="/etc/hostapd/hostapd.conf". Enable the service again with
sudo systemctl enable hostapd.
Setting Up DHCP and DNS with Dnsmasq
Clients connecting to the AP need IP addresses.
Dnsmasq provides lightweight DHCP and DNS services. Install it with
sudo apt install dnsmasq. Stop and disable the default service to avoid conflicts:
sudo systemctl stop dnsmasq and
sudo systemctl disable dnsmasq.
Create a backup of the original config:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig. Then create a new
/etc/dnsmasq.conf with these settings:
interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
This range assigns IPs from .2 to .20 to clients, leaving .1 for the Pi itself. The lease time is set to 24 hours. Restart the service with
sudo systemctl start dnsmasq and enable it with
sudo systemctl enable dnsmasq. Now, when a device connects, it should receive an IP and be able to ping
192.168.4.1.
If you intend to share the Pi's internet connection with these clients, you must enable IP forwarding and configure NAT rules. Add
net.ipv4.ip_forward=1 to
/etc/sysctl.conf and apply it with
sudo sysctl -p. Then, add an iptables rule:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE. Replace
eth0 with your upstream internet interface. Without this step, clients will have network access but no internet. For more details on traffic forwarding issues, see
Unable to Forward Receive Internet Traffic on Raspberry Pi 4 Wifi AP.
Troubleshooting Common Issues
If devices cannot connect, check the system logs with
sudo journalctl -u hostapd. Common errors include driver mismatches or permission issues. Ensure the
wlan0 interface is not managed by NetworkManager, which can override
hostapd settings. In some cases, disabling WiFi power management helps stability. Create a file at
/etc/NetworkManager/conf.d/default-wifi-powersave-on.conf with content
[connection] wifi.powersave = 2.
For persistent disconnections, consider adjusting the
ignore_broadcast_ssid parameter or checking for interference on channel 7. If you experience intermittent drops, review
Wifi Keep Disconnecting After Sometime for hardware-specific diagnostics. Finally, if you plan to connect IoT devices like ESP32s, ensure the encryption settings match their capabilities. See
ESP32 Micropython: Failing to Connect to Raspberry Pi's Access Point for embedded device compatibility tips.
Frequently Asked Questions
Can I use both WiFi and Ethernet simultaneously?
Yes, the Raspberry Pi can function as a bridge between wired and wireless networks. You must enable IP forwarding and configure iptables NAT rules to route traffic from the WiFi subnet to the Ethernet interface, effectively turning the Pi into a router rather than just an access point.
Why do my devices get an IP but have no internet?
This indicates that DHCP is working but routing is missing. You must enable IP forwarding in the kernel and set up a masquerade rule in iptables to translate private IP addresses to the public IP of the upstream connection.
Is WPA3 supported on all Raspberry Pi models?
WPA3 support depends on the kernel version and the WiFi driver. Older models or those running outdated OS versions may only support WPA2. Check your driver documentation for WPA3 compatibility flags in the
hostapd configuration.
How do I change the SSID after setup?
Simply edit the
/etc/hostapd/hostapd.conf file, update the
ssid line, and restart the hostapd service using
sudo systemctl restart hostapd. Connected clients will need to re-authenticate with the new network name.
Can I run this setup on a headless Raspberry Pi?
Absolutely. Since all configurations are handled via command-line tools and text editors, no graphical interface is required. You can SSH into the Pi to perform every step outlined in this guide.