Connect with us

How To

How to Use the Raspberry Pi as a Wireless Access Point?

Published

on

Raspberry Pi Wireless Access Point

The Raspberry Pi can do plenty of things, the latest Raspberry Pi comes with the built-in wireless capabilities. It acts as plenty of different devices including router! If you turn the Raspberry Pi into a wireless access point, you can make it as the router. In this article, we will provide you with the steps to turn your Raspberry Pi as the Wireless Access Point.

Raspberry Pi Wireless Access Point
Raspberry Pi Wireless Access Point

Related: How to Create a Raspberry Pi Thermometer Using Sense HAT?

How to Use the Raspberry Pi as a Wireless Access Point? | Raspberry Pi Wireless Access Point

Similar to all other previous projects, this also needs the Raspbian OS to be installed on your Raspberry Pi. You need to install some packages which give the Pi the ability to do router-like things such as IP addresses to the devices that connect to it.

Step 1: Install and update Raspbian, Check out this guide to know how to install Raspbian on your Raspberry Pi. Then plug everything in and enter into the terminal and check for updates and upgrades with the following command:

sudo apt-get update
sudo apt-get upgrade

If you get an upgrade, Its good to reboot with sudo reboot.

Raspberry Pi Wireless Access Point
Raspberry Pi Wireless Access Point

Step 2: Now Install hostapd and dnsmasq, these are the two programs, that you are going to use to make the Raspberry Pi into a Wireless Access Point. To get them, simply type the following lines into the terminal:

sudo apt-get install hostapd
sudo apt-get install dnsmasq

Both times, you have to hit y to continue. hostapd is a package enables you to create a wireless hotspot using your Raspberry Pi, and dnsmasq is an easy-to-use DHCP and DNS server.

Now you have to edit the programs’ configuration files in a moment, So now turn the programs off, before you start editing.

sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

Step 3: Now configure a static IP for the wlan0 interface, for your purpose here, you are using the standard home network IP addresses, such as 192.168.***.***.  Now assign the IP address 192.168.0.10 to the wlan0.

Interface by editing the dhcpcd configuration file. You can begin editing with the following command:

sudo nano /etc/dhcpcd.conf

Related: How to Use the Raspberry Pi as a NAS box?

Now that you are in the file, just append the following lines to the file.

interface wlan0
static ip_address=192.168.0.10/24
denyinterfaces eth0
denyinterfaces wlan0

The last two lines are required to make the bridge work

Raspberry Pi Wireless Access Point
Raspberry Pi Wireless Access Point

After doing this, you can save the file and exit the editor by pressing Ctrl+X, then Y.

Step 4: Now configure the DHCP server (dnsmasq). Here you are going to use the dnsmasq as your DHCP server. The idea of the DHCP server is to dynamically distribute the network configuration parameters, including the IP addresses, for interfaces and services.

dnsmasq’s default configuration file contains plenty of unnecessary information So that it is easier for you to start from scratch. Now rename the default configuration file and write a new one:

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

Now you can edit the new file with the old one renamed, this is the config file which dnsmasq will use. Type these lines into the new configuration file:

interface=wlan0
dhcp-range=192.168.0.11,192.168.0.30,255.255.255.0,24h

The lines you added mean that you are going to provide the IP addresses between 192.168.0.11 and 192.168.0.30 for wlan0 interface.

Step 5: Then configure the access point host software (hostapd), Another config file! This time, you are messing with the hostapd config file. Open ‘er up:

sudo nano /etc/hostapd/hostapd.conf

The following command will create a brand new file. Type in this:

interface=wlan0
bridge=br0
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=NETWORK
wpa_passphrase=PASSWORD

Note that I have a “NETWORK” and “PASSWORD,” you have to come up with your own names. This is how you can join your Pi’s network from other devices.

Raspberry Pi Wireless Access Point
Raspberry Pi Wireless Access Point

Now we have to show the system location of the configuration file:

sudo nano /etc/default/hostapd

In this file, you can track down the line which says #DAEMON_CONF=”” – delete that # and then put the path to your config file in the quotes, so that it looks like this:

DAEMON_CONF=”/etc/hostapd/hostapd.conf”

The # keeps the line from being read as code so that you are basically bringing this line to work here while giving it the right path to your config file.

Step 6: Now set up the traffic forwarding. If you connect to your Pi, then it will forward the traffic through your Ethernet cable. So that you are going to have the wlan0 forward through the Ethernet cable to the modem. This involves editing another config file:

sudo nano /etc/sysctl.conf

Now find this line:

#net.ipv4.ip_forward=1

and delete the “#” – leave the rest, so it only reads:

net.ipv4.ip_forward=1

Related: How to Setup Your Raspberry Pi as a VPN Router?

Step 7: Then add the new iptables rule, Next, you are going to add the IP masquerading for the outbound traffic on eth0 using iptables:

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

Then save the new iptables rule:

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

To load the rule on boot, you need to edit the file /etc/rc.local and add the following line just above the line exit 0:

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

Raspberry Pi Wireless Access Point
Raspberry Pi Wireless Access Point

Step 8: Now enable the internet connection then the Raspberry Pi is acting as an access point to which other devices can connect. But, those devices cannot use Raspberry Pi to access the internet yet. To make it possible, we have to build a bridge, which will pass all the traffic between the wlan0 and eth0 interfaces.

To build a bridge, You have to install one more package:

sudo apt-get install bridge-utils

Now you are ready to add the new bridge (called br0):

sudo brctl addbr br0

Next, you can connect the eth0 interface to your bridge:

sudo brctl addif br0 eth0

Finally, you can edit the interfaces file:

sudo nano /etc/network/interfaces

Then add the following lines at the end of the file:

auto br0
iface br0 inet manual
bridge_ports eth0 wlan0

Step 9: Now you are ready, you can reboot with the sudo reboot. Now your Raspberry Pi should be working as the wireless access point. You can try it out by entering into another device and looking for the network name, which you used on step 5.

Raspberry Pi Wireless Access Point
Raspberry Pi Wireless Access Point

Now your Raspberry 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.

Thank you for reading this post.

Facebook

Trending

Would you like to receive notifications on latest updates? No Yes