How to use your Raspberry Pi 3 as a wireless access point
The Raspberry Pi can do a lot, especially now that the new Raspberry Pi comes with wireless capabilities already on board. It can take the place of a ton of different (and more expensive) devices – including a router! If you turn your Raspberry Pi into a wireless access point, you can make it act as a router. It’s not the most powerful thing in the world, but it does work, and the project is a lot of fun.
How to use your Raspberry Pi as a wireless access point
We’re going to get into the command line a bit here, but this project isn’t really all that difficult. All we’re really doing is using Raspbian and installing a couple packages that give the Pi the ability to do router-like things like assign IP addresses to devices that connect to it.
Step 1: Install and update Raspbian
Step 2: Install hostapd and dnsmasq
These are the two programs we’re going to use to make your Raspberry Pi into a wireless access point. To get them, just type these lines into the terminal:
Both times, you’ll have to hit y to continue. hostapd is the package that lets us create a wireless hotspot using a Raspberry Pi, and dnsmasq is an easy-to-use DHCP and DNS server.
We’re going to edit the
programs’ configuration files in a moment, so let’s turn the
before we start tinkering:
Step 3: Configure a static IP for the wlan0 interface
For our purposes here, I’m assuming that we’re
using the standard home network IP addresses, like
192.168.###.###. Given that
assumption, let’s assign the IP address to the wlan0
interface by editing the dhcpcd configuration file. Start editing with this command:
Now that you’re in the file, add the following lines at the end:
(The last two lines are needed in order to make our bridge work –- but more on that in
After that, press , then, then to save the file and exit the editor.
Step 4: Configure the DHCP server (dnsmasq)
We’re going to use dnsmasq
as our DHCP server. The idea
of a DHCP server is to
dynamically distribute network configuration parameters, such as IP addresses, for
interfaces and services.
dnsmasq’s default configuration
file contains a lot of unnecessary
it’s easier for us to start from scratch. Let’s rename the default configuration file and
write a new one:
You’ll be editing a new file now, and with the old one renamed, this is the config file that dnsmasq will use. Type these lines into your new configuration file:
The lines we added mean that we’re going to provide IP addresses between 192.168.22.11 and 192.168.22.30 for the wlan0 interface.
Step 5: Configure the access point host software (hostapd)
Another config file! This time, we’re messing with the hostapd config file. Open ‘er up:
This should create a brand new file. Type in this:
Note that where I have “NETWORK” and “PASSWORD,” you should come up with your own names. This is how you’ll join the Pi’s network from other devices.
We still have to show the system the location of the configuration file:
In this file, track down the line that says #DAEMON_CONF=”” – delete that and put the path to our config file in the quotes, so that it looks like this:
The # keeps the line from being read as code, so you’re basically bringing this line to life here while giving it the right path to our config file.
Step 6: Set up traffic forwarding
The idea here is that when you connect to your Pi, it will forward the traffic over your Ethernet cable. So we’re going to have wlan0 forward via Ethernet cable to your modem. This involves editing yet another config file:
Now find this line:
…and delete the “#” – leaving the rest, so it just reads:
Step 7: Add a new iptables rule
Next, we’re going to add IP masquerading for outbound traffic on eth0 using iptables:
…and save the new iptables rule:
load the rule on boot, we need to edit
the file /etc/rc.local and add
line just above the line exit 0:
Step 8: Enable internet connection
Now the Raspberry Pi is acting as an access point to which other devices can connect. However, those devices can’t use the Pi to access the internet just yet. To make the possible, we need to build a bridge that will pass all traffic between the wlan0 and eth0 interfaces.
To build the bridge, let’s install one more package:
We’re ready to add a new bridge (called br0):
Next, we’ll connect the eth0 interface to our bridge:
Finally, let’s edit the interfaces file:
…and add the following lines at the end of the file:
Step 9: Reboot
Now that we’re ready, let’s reboot with
Now your Pi should be working as a wireless access point. Try it out by hopping on another device and looking for the network name you used back in step 5.
Problem with hostapd on Rasbian Stretch
Failed to start hostapd.service: Unit hostapd.service is masked.
The latest update to Raspbian (2019-03-09) has changed hostapd "wpa (2:2.6-10)".
To ensure hostapd runs on boot run the following commands: