How to Turn Your Raspberry Pi into a Wireless Access Point

Wireless Access Point Raspberry Pi

Are you looking to create multiple access points throughout your home without any of the latency and connectivity issues typically associated with using a Wi-Fi extender? In this article you’ll learn how to turn your Raspberry Pi into a wireless access point.

Once your wireless access point is up and running, anyone who has the password will be able to connect to your Raspberry Pi as though it’s a “mini router,” ideal for everyone from cafe owners who want to offer their customers complimentary Wi-Fi, to employers who need to create a private network for their employees, or even someone who just likes the idea of having multiple Wi-Fi networks at home!

What you’ll need

To complete this tutorial, you’ll need:

  • Raspberry Pi 3/4 that’s running Raspbian. If you don’t already have Raspbian, you can grab the latest version and flash it using Etcher.
  • Power cable that’s compatible with your Raspberry Pi
  • External keyboard and a way to attach it to your Raspberry Pi
  • HDMI or micro HDMI cable, depending on model of Raspberry Pi
  • External monitor
  • Ethernet cable. Since you’re turning your Raspberry Pi into a wireless access point, you’ll need to connect over Ethernet rather than Wi-Fi. This also means it won’t work with Raspberry Pi 2 or Raspberry Pi Zero since they are missing either the Ethernet port or wireless card.

Once you’ve assembled your tools, it’s time to create your own Wi-Fi hotspot.

Getting Started: Set Up Your Raspberry Pi

To start, connect all the peripherals to your Raspberry Pi, including the Ethernet cable.

Make sure you attach an ethernet cable to your Raspberry Pi!

Once your Raspberry Pi has booted, it’s a good idea to check that you’re running the latest version of Raspbian, so launch a Terminal by clicking the little “Terminal” icon in the toolbar. Type the following command:

sudo apt-get update

Press Enter on your keyboard and wait for the command to execute.

Type the next command and press Enter once again:

sudo apt-get upgrade

After the upgrade, it is best to reboot your Raspberry Pi for any system changes to take effect. Run the following command:

reboot

Install hostapd, dnsmasq and Firewall Plugins

Install the hostapd (host access point daemon), which is a software package that can transform network interface cards into access points.

To install hostapd on your Raspberry Pi, open a Terminal and run the following command:

sudo apt install hostapd
Install the host access point daemon, via your Raspberry Pi's Terminal.

Enable the wireless access point and set it to launch automatically at startup:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
We can now enable our wireless access point (WAP).

Next, install dnsmasq, which provides Domain Name System (DNS) caching and a Dynamic Host Configuration Protocol (DHCP) server that’s designed for small networks.

To install this software package, run the following command in the Terminal:

sudo apt install dnsmasq

Finally, install netfilter-persistent and the iptables-persistent plugin, which will be responsible for saving and loading the firewall rules on your Raspberry Pi:

sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent

Assign a Static IP Address

The Dynamic Host Configuration Protocol server requires a static IP address, so in this section you’ll configure a static IP for your Raspberry Pi.

To start, run the following command in the Terminal:

sudo nano /etc/dhcpcd.conf

Raspbian will open the configuration file for dhcpcd. Scroll to the bottom of this file and add the following lines:

interface wlan0
    static ip_address=192.168.4.1/24
    nohook wpa_supplicant

Save your changes by pressing Ctrl + O followed by Ctrl + x.

Enable routing

Your Raspberry Pi access point is now running its own standalone wireless network. However, if you want to allow clients to access computers on your Ethernet network, then you’ll need to enable routing.

To enable routing, create a “routed-ap.conf” file using the following command:

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

This creates a “routed-ap.conf” file and opens it for editing in the Nano text editor. In the text editor, type the following:

net.ipv4.ip_forward=1

Save your changes by pressing Ctrl + O followed by Ctrl + X.

Add a new firewall rule to your Raspberry Pi by running the following command:

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

Finally, use netfilter-persistent to ensure your new rule gets loaded at startup:

sudo netfilter-persistent save

Configure Your DHCP and DNS Services

The dnsmasq package provides a default configuration file, but we don’t need all the options included in this file.

To make things easier, rename dnsmasq’s default configuration file and create a replacement file that’s completely empty. Then open this new “dnsmasq.conf” file in the Nano text editor and add only the configuration options that we actually need.

To start, run the following Terminal commands:

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

Add the following configuration options:

interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
domain=wlan
address=/gw.wlan/192.168.4.1

Save your changes by pressing Ctrl + O followed by Ctrl + X.

Create a Network Name and Password

Configure your wireless access point by editing the hostapd configuration file.

To open this file for editing, run the following command:

sudo nano /etc/hostapd/hostapd.conf

Add some information about your wireless access point, including giving it a name and securing it with a password. To help protect your access point, your password should be eight characters or more and feature a mix of letters, numbers and symbols.

This tutorial creates an access point called “NetworkName” with the password “PassphrasePassphrase” – make sure you use something more secure for your own network!

interface=wlan0
ssid=NetworkName
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=PassphrasePassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Save your changes by pressing Ctrl + O followed by Ctrl + X.

Connect to Your Wireless Access Point

Congratulations, you have successfully turned your Raspberry Pi into a wireless access point.

To verify that everything is working correctly, it’s a good idea to restart your Raspberry Pi and check that you can connect to your access point following this reboot.

Once your Raspberry Pi has rebooted, grab any Wi-Fi enabled device and scan for nearby wireless networks. You should see a network that has the name you specified in your Raspberry Pi’s “hostapd.conf” file.

Your Raspberry Pi will now appear as a Wi-Fi network, and you connect to it from any Wi-Fi enabled device.

Try to connect to this network, and you’ll be prompted for a password. Enter the passphrase from your “hostapd.conf” file, and after a few moments you should be successfully connected to your wireless access point.

Enter the password that you specified in your Raspberry Pi's hostapd.conf file.

You can now surf the Internet on your Wi-Fi enabled device as though it was directly connected to your router.

In this tutorial, you learned how to turn a Raspberry Pi into a wireless access point. You can now connect to this access point using any Wi-Fi enabled device and can give third parties access to your network without sharing your router’s password.

In addition, you can also turn your Raspberry Pi into a Chromecast or stream Spotify from it. Don’t forget to check out our Raspberry Pi page for more interesting projects.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox