# Setting up a Raspberry Pi as a WiFi Access Point

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/009/048/medium800/raspberry_pi_pi_ap.jpg?1396881587)

Would you like to use your Pi as a WiFi router? Or maybe have it as a special filtering access point? Setting up a Pi as an access point (AP) is a bit more advanced than using it as a client, but still only a half hour of typing to configure. This tutorial will make it so the Pi broadcasts a WiFi service and then routes internet traffic to an Ethernet cable. Since its all Linux you can go in and update or configure it&nbsp;however you like.

_This guide is a streamlined version of [instructions from the official Raspberry Pi Documentation](https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-routed-wireless-access-point). If you encounter problems with our directions, check that link, some steps may have changed since this was written. We’ll update periodically!_

These directions create a _routed_ wireless access point: wireless devices connecting to the Raspberry Pi can access the internet and other devices on the network, but the reverse isn’t necessarily true. This is the most common “hotspot” WiFi network approach.&nbsp;If you specifically require a _bridged_ access point instead—where the Pi extends your current network and address assignment to wireless devices, and connections can work either way—[these alternate directions from the Raspberry Pi Documentation](https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-bridged-wireless-access-point) will get you going.

# Setting up a Raspberry Pi as a WiFi Access Point

## What you'll need

The following are **required** for this tutorial:

- [Raspberry Pi](https://www.adafruit.com/category/176)&nbsp;computer, preferably one with both **Ethernet** and **WiFi** built-in. The classic form-factor Pi 3 B+ or Pi 4 are ideal. Other Pi models can certainly work with the addition of dongles or IO boards, but this guide focuses on the basics.
- Ethernet internet connectivity is _required;_ that’s where we’ll be routing wireless traffic.
- [Ethernet cable](http://www.adafruit.com/products/730)
- microSD card (4GB or larger) for Raspberry Pi OS. _Early Pi models use a full-size SD card or a microSD adapter._
- Power supply for your Pi. Some also require a USB cable if not attached, either USB-C or Micro-B depending on Pi model.

The following are **optional** or required only in particular circumstances:

- A USB [WiFi adapter](http://www.adafruit.com/products/814)&nbsp;is required for earlier Pi models that don’t have WiFi built-in.&nbsp; **Not all WiFi adapters work, we know for sure the ones in the Adafruit shop are compatible!**
- A [USB Console cable](http://www.adafruit.com/products/954 "Link: http://www.adafruit.com/products/954")&nbsp;can be used for logging in and configuring the system, or you can remote log in via ssh over Ethernet, whichever you prefer.
- [Case for your Pi](https://www.adafruit.com/category/395).
- [A SD or MicroSD card reader](http://www.adafruit.com/products/939).

Our [Pi starter packs](https://www.adafruit.com/?q=raspberry%20pi%20starter%20pack) have all you need and come with more fun stuff you can play with.

# Setting up a Raspberry Pi as a WiFi Access Point

## Preparation

Let’s set up the SD card using [Raspberry Pi Imager (downloadable here)](https://www.raspberrypi.com/software/). There are other options for this, but we _really_ like Imager these days…you can configure most system essentials before the card is even written; no need for a post-boot setup round.

The “ **CHOOSE OS** ” button pops up a menu of choices. Select “**Raspberry Pi OS (other)**”&nbsp;and then download one of the “ **Lite** ” versions: 32-bit works across _every_ Pi model, or optionally (Pi 3 and later) can use 64-bit, though don’t expect any dramatic difference for this particular use. Make sure to download the OS **Lite** , _not_ Full…we’ll be using the system “headless” without a display.

Insert the **SD card** in a reader and click “ **CHOOSE STORAGE** ” to select it.

Once the above steps are done, this **gear icon** &nbsp;appears, which brings up the **Advanced options** menu…

![learn_raspberry_pi_pi-imager-1.png](https://cdn-learn.adafruit.com/assets/assets/000/114/402/medium640/learn_raspberry_pi_pi-imager-1.png?1660864457)

![learn_raspberry_pi_pi-imager-2.png](https://cdn-learn.adafruit.com/assets/assets/000/114/403/medium640/learn_raspberry_pi_pi-imager-2.png?1660864474)

The first four **Advanced options** settings are essential:

- **Set hostname** to something unique for your network _(prior versions of Raspberry Pi OS used_ raspberrypi.local _by default, but for security they recommend against that now)._
- **Enable SSH** if using **Ethernet** for later setup. This is _not_ strictly required if using a **serial console cable** , but you might have other use for it later.
- Set **username and password**. _These used to default to_ pi _and_ raspberry, _but again they recommend against this now. Pick something distinct._
- **DO NOT** select “Configure wireless LAN.” After some software installation, **we’ll configure WiFi manually later…** selecting this now would interfere.

Other settings like time zone and keyboard layout are optional…you can set these as you like, or not.

Click “ **SAVE** ” when done, then the “ **WRITE** ” button to write the OS to the SD card.

![learn_raspberry_pi_pi-imager-3.png](https://cdn-learn.adafruit.com/assets/assets/000/114/405/medium640/learn_raspberry_pi_pi-imager-3.png?1660865538)

**While _Imager_ works, get the Pi ready by connecting an Ethernet cable and…if using an earlier Pi (without WiFi)…insert a USB WiFi adapter into any available USB port. This is best done now when the Pi is powered off.**

After the card is **written** and **verified** , safely **eject** it, move it over to the Pi and **connect power** &nbsp;to the system.&nbsp; **Allow a few minutes for first boot** as the filesystem is expanded and ssh keys are generated.

If your Pi is connected to the Ethernet network and **ssh** is enabled, you can log in remotely from another computer with an ssh client, providing the hostname, user name and password you set earlier.

Or, if using a **serial console cable** : connect it&nbsp;as in the following diagram. Notice the red wire is _not_ connected. You can now log in from another computer with a serial terminal program, providing the username and password you set earlier.

![](https://cdn-learn.adafruit.com/assets/assets/000/035/703/medium800/raspberry_pi_piconsole_bb.png?1473740177)

# Setting up a Raspberry Pi as a WiFi Access Point

## Check Ethernet & Wifi

 **At this point, the Pi should be booted and you should be logged in via ssh or serial console.**

Confirm you can “ **ping** ” out from the Pi to the internet at large:

```auto
ping 8.8.8.8
```

![](https://cdn-learn.adafruit.com/assets/assets/000/009/019/medium800/raspberry_pi_ifconfigtestether.gif?1448056715)

If using the **serial cable** , and the ping does not respond, check that the Ethernet cable is properly seated at both ends, and that the router (or cable or DSL modem, etc.) are powered on and working for any other devices on the network.

Although WiFi is not yet configured, we can check for the existence of that hardware (e.g. if using a USB WiFi adapter):

```auto
ifconfig -a
```

![](https://cdn-learn.adafruit.com/assets/assets/000/009/020/medium800/raspberry_pi_ifconfiga.gif?1448056709)

If you see “wlan0” in the output, you’re in good shape.

# Setting up a Raspberry Pi as a WiFi Access Point

## Install software

A lot of persnickety typing follows, so you’ll probably want to use the “copy code” button to get these commands and settings exact.

Lets make sure the Pi’s operating system and utilities are fresh and up-to-date:

```auto
sudo apt update
sudo apt -y upgrade
```

The second line in particular may take a little while; perhaps 10 minutes. Take a moment to stretch or get a drink of water.&nbsp;Then:

```auto
sudo apt install -y hostapd dnsmasq
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
sudo reboot
```

The [official Pi directions](https://www.raspberrypi.com/documentation/computers/configuration.html#setting-up-a-routed-wireless-access-point) omit the reboot step, but it _does_ seem to be necessary before certain commands later. The system will kick you off at this point. Allow a minute or so for the reboot, then log back in for more commands…

```auto
sudo nano /etc/dhcpcd.conf
```

 **Here we’re using the _nano_ editor, but you can substitute another editor of your choice. That goes for other files being edited later as well.**

There’s a few dozen lines of stuff in **dhcpcd.conf**. Go to the **end of the file** and add the following at the bottom:

```auto
interface wlan0
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant
```

(The latter two lines are indented by four spaces. This is correct and normal; do not “clean up.”)

Save the changes and exit _nano_ (if that’s what you’re using) by pressing CTRL-O and CTRL-X. Then we’ll edit another:

```auto
sudo nano /etc/sysctl.d/routed-ap.conf
```

This file is likely empty, so you’ll simply be filling it with:

```auto
# Enable IPv4 routing
net.ipv4.ip_forward=1
```

Save and exit, then edit another:

```auto
sudo nano /etc/dnsmasq.conf
```

Everything in this file is _commented out_ by default,&nbsp;so you can insert the following lines _anywhere…_beginning, end, or delete everything there and replace with just these lines, it’s all good:

```auto
interface=wlan0 # Listening interface
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
                # Pool of IP addresses served via DHCP
domain=wlan     # Local wireless DNS domain
address=/gw.wlan/192.168.4.1
                # Alias for this router
```

Save and exit that, then there’s _one more_ file to edit:

```auto
sudo nano /etc/hostapd/hostapd.conf
```

This one’s likely empty too. Begin with the following:

```auto
country_code=US
interface=wlan0
ssid=WirelessNetworkName
hw_mode=a
channel=48
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=WirelessNetworkPassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
```

 **This is just a starting point, and several lines should be changed:**

**WirelessNetworkName** is the name (or “SSID”) one sees in the WiFi network selection menu on your computer or phone; replace with something descriptive.

**WirelessNetworkPassword** is the corresponding password for the above.

**country\_code=US** _must_ be edited with the 2-letter country code for your location; the default here is for the United States. 5 GHz WiFi will not work correctly without it! [Here is a list of country codes on Wikipedia](https://en.wikipedia.org/wiki/ISO_3166-1#Current_codes).

The lines **hw\_mode=a** and **channel=48** probably will need to be edited…

**hw\_mode** can be **a** , **b** or **g** , corresponding to different 802.11 WiFi generations. 802.11a is 5 GHz (Pi 3 B+ onwards), the others are 2.4 GHz; for USB WiFi dongles, try **g**.

**channel** will depend on **hw\_mode** and your country. If it’s a 2.4 GHz mode ( **b** or **g** ), this is 1–11 (and up to 14 in some places) ([List of 2.4 GHz channels](https://en.wikipedia.org/wiki/List_of_WLAN_channels#2.4_GHz_(802.11b/g/n/ax))). If 5 GHz ( **hw\_mode=a** only), the range is much larger and a bit confusing ([List of 5 GHz channels](https://en.wikipedia.org/wiki/List_of_WLAN_channels#5_GHz_(802.11a/h/j/n/ac/ax)) — look for ones with a “Yes” in your country/region’s column). **48** worked for me in the **US** , but you might need to try a few different channels before one sticks, rebooting each time.

If using a non-Adafruit USB WiFi adapter, you might need to add a line:&nbsp; **driver=nl80211** or similar, depends on the WiFi chip used within. Check documentation for the item, also there’s no guarantee all such dongles can work with the Pi.

Save and exit, then enter the following commands to finalize everything and restart the system, hopefully bringing up the WiFi network with it.

**If outside the United States, change the “US” on the first line here to the 2-letter country code you previously entered in hostapd.conf.**

```auto
sudo raspi-config nonint do_wifi_country US
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo netfilter-persistent save
sudo reboot
```

These directions are in a slightly different sequence than the canonical Pi documentation, to minimize going back-and-forth between editing files and entering commands. End result should be the same though.

# Setting up a Raspberry Pi as a WiFi Access Point

## Test and Troubleshooting

After rebooting the Pi, allow a minute or two for it to start up and manifest the wireless network.&nbsp;Look for it using another computer, a phone or a tablet…it should appear under the WiFi network list, with the name you assigned earlier.

If the Pi’s wireless network does _not_ appear…

- If using 5 GHz mode (802.11 **a** ), edit the **hostapd.conf** file and try a different channel, using the list mentioned earlier for recommendations. Reboot, wait and check for it again.
- Also if using 5 GHz: does the 2-letter&nbsp; **country\_code** value match what you passed to **raspi-config nonint**? If not, fix one or the other.
- If the device you’re testing from only supports the earlier 2.4 GHz WiFi modes, a 5 GHz network won’t be visible _at all._ You may need to go back in and set **hw\_mode=g** and **channel=11** or something else.


## Featured Products

### Raspberry Pi 4 Model B - 1 GB RAM

[Raspberry Pi 4 Model B - 1 GB RAM](https://www.adafruit.com/product/4295)
The Raspberry Pi 4 Model B is the newest Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 4 better than the 3? How about a&nbsp;_faster_ processor, USB 3.0 ports, and updated Gigabit Ethernet chip with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4295)
[Related Guides to the Product](https://learn.adafruit.com/products/4295/guides)
### Official Raspberry Pi Foundation Raspberry Pi 4 Case - Red White

[Official Raspberry Pi Foundation Raspberry Pi 4 Case - Red White](https://www.adafruit.com/product/4301)
Keep your Raspberry Pi® 4 Model B&nbsp;computer safe and snug in this solid ABS acrylic enclosure. Y[ou can even pick up an official case fan + heatsink kit](https://www.adafruit.com/product/4794) to super-charge your Pi 4 projects and keep them cool even under computational...

In Stock
[Buy Now](https://www.adafruit.com/product/4301)
[Related Guides to the Product](https://learn.adafruit.com/products/4301/guides)
### Official Raspberry Pi Power Supply 5.1V 3A with USB C

[Official Raspberry Pi Power Supply 5.1V 3A with USB C](https://www.adafruit.com/product/4298)
The official Raspberry Pi USB-C power supply is here! And of course, we have 'em in classic Adafruit black! Superfast with just the right amount of cable length to get your Pi 4 projects up and running!

Best for use with Pi 4 series, [Pi...](https://www.adafruit.com/product/5814)

In Stock
[Buy Now](https://www.adafruit.com/product/4298)
[Related Guides to the Product](https://learn.adafruit.com/products/4298/guides)
### Ethernet Cable - 10 ft long

[Ethernet Cable - 10 ft long](https://www.adafruit.com/product/730)
We have so many Internet-connected goodies in the shop, we figured it's time to carry a cable so you can easily connect them up! This cable is 10 feet long, black and has all 8 wires installed. Perfect for use with the [BeagleBone](http://www.adafruit.com/products/513), <a...></a...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/730)
[Related Guides to the Product](https://learn.adafruit.com/products/730/guides)
### SD/MicroSD Memory Card (8 GB SDHC)

[SD/MicroSD Memory Card (8 GB SDHC)](https://www.adafruit.com/product/1294)
Add mega-storage in a jiffy using this 8 GB class 4 micro-SD card. It comes with a SD adapter so you can use it with any of our shields or adapters. Preformatted to FAT so it works out of the box with our projects. Tested and works great with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/1294)
[Related Guides to the Product](https://learn.adafruit.com/products/1294/guides)
### USB MicroSD Card Reader/Writer - microSD / microSDHC / microSDXC

[USB MicroSD Card Reader/Writer - microSD / microSDHC / microSDXC](https://www.adafruit.com/product/939)
This is the cutest little microSD card reader/writer - but don't be fooled by its adorableness! It's wicked fast and supports up to 64 GB SDXC cards! Simply slide the card into the edge and plug it into your computer. No drivers are required, it shows up as a standard 'Mass...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/939)
[Related Guides to the Product](https://learn.adafruit.com/products/939/guides)
### USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi

[USB to TTL Serial Cable - Debug / Console Cable for Raspberry Pi](https://www.adafruit.com/product/954)
The cable is easiest way ever to connect to your microcontroller/Raspberry Pi/WiFi router serial console port. Inside the big USB plug is a USB\<-\>Serial conversion chip and at the end of the 36" cable are four wire - red power, black ground, white RX into USB port, and green TX out...

In Stock
[Buy Now](https://www.adafruit.com/product/954)
[Related Guides to the Product](https://learn.adafruit.com/products/954/guides)
### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)

## Related Guides

- [Raspberry Pi Care and Troubleshooting](https://learn.adafruit.com/raspberry-pi-care-and-troubleshooting.md)
- [Pi Hole Ad Detection Display with PiTFT](https://learn.adafruit.com/pi-hole-ad-pitft-tft-detection-display.md)
- [Onion Pi](https://learn.adafruit.com/onion-pi.md)
- [Raspberry Pi WiFi Radio](https://learn.adafruit.com/pi-wifi-radio.md)
- [Playing sounds and using buttons with Raspberry Pi](https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi.md)
- [Introducing the Raspberry Pi 2 - Model B](https://learn.adafruit.com/introducing-the-raspberry-pi-2-model-b.md)
- [Monitor Your Home With the Raspberry Pi B+](https://learn.adafruit.com/monitor-your-home-with-the-raspberry-pi-b-plus.md)
- [Radio FeatherWing](https://learn.adafruit.com/radio-featherwing.md)
- [Holiday Lights: Easy DIY Christmas Wreath & Garland with WLED](https://learn.adafruit.com/holiday-garland-decor-app-control-with-no-coding.md)
- [Adafruit PiTFT 3.5" Touch Screen for Raspberry Pi](https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi.md)
- [Introducing the Raspberry Pi Model B+](https://learn.adafruit.com/introducing-the-raspberry-pi-model-b-plus-plus-differences-vs-model-b.md)
- [Raspberry Pi Thermal Printer One Time Pads](https://learn.adafruit.com/raspberry-pi-thermal-printer-one-time-pads.md)
- [Adafruit Feather M0 Radio with RFM69 Packet Radio](https://learn.adafruit.com/adafruit-feather-m0-radio-with-rfm69-packet-radio.md)
- [Wireless UNTZtrument Using BLE MIDI ](https://learn.adafruit.com/wireless-untztrument-using-ble-midi.md)
- [Naughty or Nice Machine](https://learn.adafruit.com/naughty-or-nice-machine.md)
- [Raspberry Pi Analog to Digital Converters](https://learn.adafruit.com/raspberry-pi-analog-to-digital-converters.md)
