Family Encyclopedia >> Electronics

How to turn your Raspberry Pi into a wireless access point

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

ContentsWhat you'll needGetting started:Configure your Raspberry PiInstall hostapd, dnsmasq and firewall pluginsAssign a static IP addressEnable routingConfigure your DHCP and DNS servicesCreate a network name and passwordConnect to your point of wireless access

Once your hotspot is up and running, anyone with the password will be able to connect to your Raspberry Pi as if it were a "mini router", ideal for any café owner who wants to offer their customers with free Wi-Fi, 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 will need:

  • Raspberry Pi 3/4 which runs Raspbian. If you don't already have Raspbian, you can grab the latest version and flash it using Burner.
  • Power cable compatible with your Raspberry Pi
  • External keyboard and way to attach it to your Raspberry Pi
  • HDMI or micro HDMI cable, depending on Raspberry Pi model
  • External monitor
  • Ethernet cable. Since you're turning your Raspberry Pi into a wireless access point, you'll need to connect via Ethernet rather than Wi-Fi. This also means it won't work with Raspberry Pi 2 or Raspberry Pi Zero as they lack the Ethernet port or the wireless card.

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

Getting started:configuring your Raspberry Pi

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

How to turn your Raspberry Pi into a wireless access point

Enable the hotspot and set it to start automatically on startup:

sudo systemctl unmask hostapdsudo systemctl enable hostapd
How to turn your Raspberry Pi into a wireless access point

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

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

sudo apt install dnsmasq

Finally, install netfilter-persistent and the iptables-persistent plugin, which will take care of 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. In this section, you will configure a static IP address for your Raspberry Pi.

To get started, run the following command in 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, you will 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 is loaded on 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 the default dnsmasq configuration file and create a completely empty replacement file. Next, open this new "dnsmasq.conf" file in the Nano text editor and add only the configuration options we actually need.

To get started, run the following Terminal commands:

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

Add the following configuration options:

interface=wlan0dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24hdomain=wlanaddress=/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 information about your hotspot, including giving it a name and securing it with a password. To help protect your hotspot, your password should be eight or more characters long and contain a mix of letters, numbers, and symbols.

This tutorial creates a hotspot called "NetworkName" with the password "PassphrasePassphrase" - be sure to use something more secure for your own network!

interface=wlan0ssid=NetworkNamehw_mode=gchannel=7macaddr_acl=auth_algs=1ignore_broadcast_ssid=wpa=2wpa_passphrase=PassphrasePassphrasewpa_key_mgmt=WPA-PSKwpa_pairwise=TKIPrsn_pairwise=CCMP

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

Connect to your hotspot

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

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

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

How to turn your Raspberry Pi into a wireless access point

Try to connect to this network and you will 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.

How to turn your Raspberry Pi into a wireless access point

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

In this tutorial, you learned how to turn a Raspberry Pi into a wireless access point. Now you can connect to this hotspot using any Wi-Fi enabled device and allow others to access your network without sharing your router password.

Moreover, 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.