You are on page 1of 7

11/2/23, 14:37 Create wireless access point | The Raspberry Pi Guide

Networking / Create wireless access point

Set up your Raspberry Pi as wireless


access point
A great and flexible way to connect remotely to your Raspberry Pi,
especially when no networks are available, is to set it up as a wireless
access point. This is not trivial, but below I guide you through the steps
to set this up.

TA B L E OF CONTE N T S
1 Getting started
2 Configure a static IP
3 Configure the DHCP server
4 Configure the access point host software
5 Start up the wireless access point
6 Enable routing and IP masquerading
7 Stop the access point

Getting started
In order to work as an access point, the Raspberry Pi will need to have access point software installed,
along with DHCP server software to provide connecting devices with a network address.

To create an access point, we’ll need DNSMasq and HostAPD. Install all the required software in one
go with this command:

sudo apt install dnsmasq hostapd

Since the configuration files are not ready yet, we need to stop the new software from running:

sudo systemctl stop dnsmasq

sudo systemctl stop hostapd

Configure a static IP
https://raspberrypi-guide.github.io/networking/create-wireless-access-point 1/7
11/2/23, 14:37 g Create wireless access point | The Raspberry Pi Guide

We are configuring a standalone network to act as a server, so the Raspberry Pi needs to have a static
IP address assigned to the wireless port. Here I assume we are using the standard 192.168.x.x IP
addresses for our wireless network, so we will assign the server the IP address 192.168.4.1.

To configure the static IP address, edit the dhcpcd configuration file with:

sudo nano /etc/dhcpcd.conf

Go to the end of the file and edit it so that it looks like the following:

interface wlan0

static ip_address=192.168.4.1/24

nohook wpa_supplicant

Now restart the dhcpcd daemon and set up the new wlan0 configuration:

sudo service dhcpcd restart

Configure the DHCP server


The DHCP service is provided by dnsmasq . Let’s backup the old configuration file and then create a
new one:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

sudo nano /etc/dnsmasq.conf

Type the following information into the dnsmasq configuration file and save it:

interface=wlan0

dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h

This will provide IP-addresses between 192.168.4.2 and 192.168.4.20 with a lease time of 24 hours.
Now start dnsmasq to use the updated configuration:

sudo systemctl start dnsmasq

Configure the access point host software


Now it is time to configure the access point software:

https://raspberrypi-guide.github.io/networking/create-wireless-access-point 2/7
11/2/23, 14:37 Create wireless access point | The Raspberry Pi Guide

sudo nano /etc/hostapd/hostapd.conf

Add the below information to the configuration file:

country_code=DE

interface=wlan0

ssid=YOURSSID

channel=9

auth_algs=1

wpa=2

wpa_passphrase=YOURPWD

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP CCMP

rsn_pairwise=CCMP

Make sure to change the ssid and wpa_passphrase . We now need to tell the system where to find this
configuration file. Open the hostapd file:

sudo nano /etc/default/hostapd

Find the line with #DAEMON_CONF , and replace it with this:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Start up the wireless access point


Run the following commands to enable and start hostapd:

sudo systemctl unmask hostapd

sudo systemctl enable hostapd

sudo systemctl start hostapd

Enable routing and IP masquerading


You may want devices connected to your wireless access point to access the main network and from
there the internet. To do so, we need to set up routing and IP masquerading on the Raspberry Pi. We
do this by editing the sysctl.conf file:

sudo nano /etc/sysctl.conf

https://raspberrypi-guide.github.io/networking/create-wireless-access-point 3/7
11/2/23, 14:37 Create wireless access point | The Raspberry Pi Guide

And uncomment the following line:

net.ipv4.ip_forward=1

Next we need a “masquerade” firewall rule such that the IP-addresses of the wireless clients
connected to the Raspberry Pi can be substituted by their own IP address on the local area network.
To do so enter:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Now to save these firewall rules and automatically use them upon boot, we will use the netfilter-

persistent service:

sudo netfilter-persistent save

Once rebooted, if you go to another device that has wireless and search for wireless networks you
should be able to see your wireless access point and be able to connect to it using the credentials
that you configured.

Stop the access point


First stop the hostadp service:

sudo systemctl stop hostap

Edit the dhcpcd.conf file:

sudo nano /etc/dhcpcd.conf

and comment out the lines related to the static IP address. Now reboot

sudo reboot

Comments

David Marsden 27 February 2022 at 16:28

Although this is the first guide to show, it doesn't apply to Bulldog. Perhaps a mention? No
iptables in Bulldog.

https://raspberrypi-guide.github.io/networking/create-wireless-access-point 4/7
11/2/23, 14:37 Create wireless access point | The Raspberry Pi Guide

Jolle@raspberrypi-guide 2 March 2022 at 07:39

Hi David, I don't understand your comment. You mean you are struggling to use the guide
to set up a wireless access point with Raspberry pi Bullseye? If so I will look into it.

David Marsden 4 March 2022 at 15:51

From Bullseye iptables have been replaced by nftables so your instructions do not work.
These instructions:
https://tinyurl.com/mrf8mz93
worked for me. Note the use of nftables at the end.

marie 6 July 2022 at 01:51

I cannot start dnsmasq. it says bad option at line 2 of the config file when I run status.
all I have on the second line is the scope of ips.

Erick GF 21 July 2022 at 01:03

It went all well, except for 2 things:


1 - after enabling and starting the access point, raspberry will lose access to Internet, even
if connected via ethernet;
2 - even if you stop the access point and connect to you home wireless network, raspberry
still can't access Internet.

I don't know if I did something wrong or if that's the expected case, but I think that should
be covered by this tutorial.

PieterG 22 August 2022 at 14:13

Yes, I have the same issue as ¨Erick GF¨ internet for the RPi itself is gone after this.

Thus no updates nothing for the WAP RPi.

Jolle@raspberrypi-guide 25 August 2022 at 10:17


https://raspberrypi-guide.github.io/networking/create-wireless-access-point 5/7
11/2/23, 14:37 Create wireless access point | The Raspberry Pi Guide

Dear Erick and Pieter,


Sorry to hear you have not been able to access the internet via the wireless access point. It
might have to do with some updates to the system files or operating system. I will try and
recreate the issue you had and solve it and get back to you.

Ryan S 9 November 2022 at 23:10

I run into the issue once I get to the point of running sudo systemctl enable hostapd,
where I am getting an error. it says that it failed to start access point and authentication
server for Wifi an dEthernet because it finished with an exit-code failure. I am getting
status 1/failure, but it doesn't give me very much information. the process is: "2103
ExecStart=/usr/sbin/hostapd -B -P /ruyn/hostapd.pid -B ${DAEMON_CONF}

Daem 10 November 2022 at 06:28

Connected, no internet

Keshlam 28 November 2022 at 20:59

Apologies if this is answered above, but I haven't spotted it yet... as part of registering a Pi
Zero as a SmartThings IOT device, the Pi wants to run as an access point. Unfortunately, I
don't have a physical display and keyboard, or wired Ethernet, hooked to the pi -- I'm
working on it via SSH. Switching to AP mode breaks my existing SSH connection, and so
far I've been unable to reestablish one while in that mode.

I've seem rumors that an "always-on AP" configuration is possible, with hints that it may
be able to run the access point while keeping the other services live. But I haven't found
details of how to set that up. Pointer or hints would be greatly appreciated!

Add a Comment

Please leave your comment below. If you'd like to be notified of my reply, please leave your comment
here for others but also send your comment as an email to me. I will try to reply as soon as I can.
Thanks!

Name

https://raspberrypi-guide.github.io/networking/create-wireless-access-point 6/7
11/2/23, 14:37 Create wireless access point | The Raspberry Pi Guide

Comment

POST

If you use find any of the information provided on this website useful it would be great to hear from you and please consider citing the paper! All rights
reserved © 2021 Jolle Jolles. Website built using Jekyll and the Just the Docs theme.

https://raspberrypi-guide.github.io/networking/create-wireless-access-point 7/7

You might also like