fbpx

Most orders for IN STOCK items placed by 12PM CST M-F ship SAME DAY. Orders for custom items and prints may take additional time to process.

Setup a Raspberry Pi Wireless Access Point

Did you know that the Raspberry Pi can be a wireless AP?  That’s right!  With just a few commands we can make a Raspberry Pi wireless access point that can be used to share your home internet with all of your devices! This is made especially easy now that the Raspberry Pi‘s come with built in wireless and and Ethernet port.  All of the hardware is built in and we just need to make some simple software configurations.

Now, we’re going to be honest and tell you upfront that with some of the entry level Raspberry Pi‘s this is probably not going to perform that well if you have really fast Internet.  But if you’re Internet connection is 35 megabit or slower then you won’t likely notice anyway.  If you have high speed Internet over about 50 megabit you’ll definitely need to go with a new Raspberry Pi 4 which has USB 3 and Gigabit networking.

Parts List for this Project

Here’s a quick parts list for this project to get you started quickly:

How to Setup a Raspberry Pi as Wireless Access Point

Now let’s move on and learn how to setup a Raspberry Pi as a wireless access point!  We’re going to need to install a few packages and configure them to get our RPi acting like a wireless AP.  If you haven’t already read our guide on installing Raspbian, you may want to that first if your Pi is brand new with a blank micro SD card. It’s a pretty simple process.

RELATED: Installing Raspbian on a new Raspberry Pi

As we mention at the beginning of most every article, we keep these articles updated so that they remain fresh and are accurate for the latest version of the software.  Almost every problem reported to us with out tutorials is due to an old version of Raspbian.  Please take a minute to update your Pi to the latest version before you begin.  You can use the following commands to update your Pi:

sudo apt udpate
sudo apt ugprade

Be sure to reboot your Pi after this by using the sudo reboot command to make sure everything is clean after this upgrade.

[box type=”info”] We recommend that your Raspberry Pi is connected to wired Ethernet as you perform this setup process.[/box]

NAT vs. Bridging RPi Access Points

Before we begin, we need to explain something.  There are two ways to setup a Raspberry Pi wireless access point.  NAT mode and Bridge Mode.

  • NAT mode – The RPi acts as a router and NATs all traffic behind it to a new network.  It acts as a DHCP server, and a DNS server for clients.
  • Bridge mode – The RPi simply passes traffic as-is between your wired and wireless networks.

Most of the tutorials online focus on NAT mode. This is a really bad way to go.  It basically means all wireless devices connected to your Raspberry Pi wireless access point will be invisible to wired devices on your network, as they will all be hidden behind a single IP address.

In our tutorial we’re going to do it the right way using bridge mode.  This is will make your RPi act just like a normal wireless access point and simply pass all traffic between the wired and wireless networks (unless you specifically block something with IPTables).

If you happen to need NAT mode, we will cover that in a future tutorial that will be linked here.

Installing hostapd and bridge-utils

Now its time to actually get to the meat of things and start installing packages.  The first two we are going to install are hostapd and dnsmasq.

  • hostapd – This is the magic bit of software that turns your wireless network card into an access point.  It will do most of the heavy lifting for this project.
  • bridge-utils– This software bridges two network adapters in order to pass traffic between them.

To install these, issue the following commands:

sudo apt install hostapd bridge-utils

You’ll need to answer the confirmation prompt and then the software will install.

setup a raspberry pi wireless access point

 

Configure DHCPD and Interfaces for Bridge Mode

In order to turn our Raspberry Pi into a wireless access point, we need to setup bridging.  Bridging is going to join two network interfaces together so they can pass traffic between them.  Let’s start with modifications to dhcpcd.conf.

Edit dhcpcd.conf as follows:

sudo nano /etc/dhcpcd.conf

You’ll want to add the following lines at the end of the file:

denyinterfaces eth0
denyinterfaces wlan0

This configuration will prevent both ETH0 and WLAN0 from getting addresses from the DHCP client services.  This is important, because we only want our virtual bridge interface BR0 to get an IP address.

Now we need to create that bridge and assign it our two interfaces, along with configuring how it gets its IP address.  Edit the interfaces file with the following command:

sudo nano /etc/network/interfaces

If you’d prefer your Raspberry Pi wireless access point to get its IP address automatically from your router, add the following lines:

# AP Bridge setup
auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0

This will tell our RPi AP to get its IP from the network DHCP server (most likely your router/firewall), and that eth0 and wlan0 are to the bridged interfaces.

If you’d like to use a static IP address, the configuration looks like this (replace with your address and network info):

# AP Bridge setup
auto br0
iface br0 inet static
bridge_ports eth0 wlan0

    address 192.168.1.5
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255

Setting up hostapd

The next step is to setup hostapd to off up our SSID and network to users.  To do this edit the following file:

sudo nano /etc/hostapd/hostapd.conf

And now add the following lines (it should be empty):

interface=wlan0
driver=nl80211
ssid=YourSSIDHere
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=YourWPA2PasswordHere
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Now we need to tell hostapd where its configuration is.  Edit the following file:

sudo nano /etc/default/hostapd

Add the following line to the end of the file:

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

That’s all the heavy lifting, let’s enable and start up the hostapd services!  Enter the following commands:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

At this point, you’ll be able to see the SSID being broadcast, as well as connect to it from your smartphone, tablet, or laptop.  However, traffic will not yet pass.

First. we need to enable IP forwarding by editing this file:

sudo nano /etc/sysctl.conf

Uncomment this following line (remove the # sign from the front of the line.

net.ipv4.ip_forward=1

Now we need to add masquerading for the Eth0 interface so that it can pass traffic for others:

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

And permanently save it so that it works on reboot:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

And edit rc.local with following command:

iptables-restore < /etc/iptables.ipv4.nat

and add the following line just above “Exit 0”.

iptables-restore < /etc/iptables.ipv4.nat

Now reboot your Raspberry Pi with sudo reboot to make sure everything takes effect on each reboot.

Connecting to Your Raspberry Pi Wireless Access Point

On any device except your Raspberry Pi, open your wireless settings.  You should see your new wireless network SSID available in your listing.  Connect to it and enter the password you chose in the config file above.

connecting to the raspberry pi wireless access point

It should only take a few seconds and you should be on the network and able to browse the internet!

I was only able to get about 55 megabit with a Raspberry Pi 3 Model B+.  However, with my Raspberry Pi 4 I was able to achieve over 150 megabit!  That’s quite amazing.

Now there are definitely some cons to using a Raspberry Pi as an access point.  Let’s talk about a few of them:

  • It won’t be as fast as a real access point.
  • Limited capacity to handle multiple users.
  • The Pi antenna is limited.
  • No support for MIMO or any other advanced handling of clients.

But there is one huge pro.  Its super cheap and super fast to setup.  If you’ve got a Raspberry Pi sitting around and need to add wireless coverage, it only takes about 5 minutes to get it going.

Upgrade to Premium

If you like our content maybe consider upgrading to Premium. You’ll get access to

  • Free access to all plans
  • Member only videos
  • Early access to content
  • Ad free Experience
  • Discounts on store merch
  • Direct hotline contact form

20 Responses

  1. Hi, thanks for the tutorial. I can see and connect the wifi hotspot on my Pi, but when I connect to it from other devices like a phone I get “no internet available” but I am able to connect to the internet through my PI. I want to use dinamic IP’s. Any suggestions?

  2. Hello Mike, nice tutorial, quick question I cannot connect to via SSH to ma raspberry, any suggestions to get that working?

  3. Would this work for a Camper moving from 1 place to another. An A.P. requires that I connect all WiFi Units with the new password. What would be preferable would be to log the Raspberry to the new network and everything else would be logged onto it already. Most Campground WiFis are slow
    so speed is not the issue. Any Thoughts on this? TY

  4. When I run the command to permanently save the iptables rules I get an error:
    sh: 1: gt: not found

    Even if I run the iptables command manually my Android phone will authenticate fine but it does not get a DHCP address from the DSL router.

  5. This comes from a display problem in the article, in which the html code is displayed instead of the > (“greater than”) or < ("less than") redirection character.

  6. Amplifying my preceding reply, here are a couple of additions to an otherwise great piece.

    1) The iptables commands inside the quotation marks in the article need to read

    iptables-save > /etc/iptables.ipv4.nat

    and

    iptables-restore < /etc/iptables.ipv4.nat

    2) To avoid the problem reported by Pete above, the hostapd.conf should start without the "driver" line but with a "bridge" line (thanks to github.com/SurferTim/documentation/configuration/wireless/access-point.md):

    interface=wlan0
    #driver=nl80211
    bridge=br0

  7. Cool… Would either method be better if I want to play with R Pi robots talking to themselves? I assume that as an access point one connected device can still http or other protocol into the pi acting as the access point. Is that correct?

  8. Still doesn’t work for me. I connect and get a proper IP, but tells me it can’t connect to the Internet. After a few seconds it ends up just dropping the connection. Every time I try to join after that it immediately drops.

  9. Could a WPS button be added? I’m trying to connect a TV which doesn’t let me enter a code. I think the TV is faulty, but I want to give this a go.

  10. OK, so I did a fresh install of Raspbian and when through this again. It works fine with my iPhone and a Win10 PC. But everything takes a dump the moment I connect my Pixel 3 to it. The Pixel 3 connect, but claims to have no Internet. Then the wifi disappears and I can’t do anything until I reboot the Pi. So appears something doesn’t play nice with Android.

Leave a Reply