You are on page 1of 7

Raspberry Pi Wireless Access Point (Raspbian

Strech)
 by Gus, xed by Milan |  Apr 2, 2017 (Dec 24, 2017) |  Beginner, Network

A Raspberry Pi wireless access point is a great way to extend the length of your Wi-Fi coverage, and
provide an additional access into your network.

In this tutorial, we will show you how to setup a wireless access point, and how to con gure the
multiple packages that allow users to connect to your access point as if it was a router itself.

You will need to keep in mind that a Wi-Fi dongle most likely won’t be able to handle as much tra c
as a normal router. This means you should avoid allowing too many connections to the device to
stop it from becoming too overburdened and slow.

While you can use any Wi-Fi dongle that supports being enabled as an access point our tutorial will
directly focus on how to set this up for the Raspberry Pi 3’s Wi-Fi Module. If you are using an earlier
model of the Raspberry Pi you can purchase a Wi-Fi adapter that supports being utilized as an
access point from numerous websites, make sure you research prior to purchasing to make sure it
works on the Raspberry Pi.

This tutorial can be combined well with our VPN Access Point tutorial, you can nd the tutorial on
how to set that up located directly after this tutorial. Basically, it will show how to setup a OpenVPN
client and redirect all tra c through that client.

 Equipment List
Below are all the bits and pieces that I used for this Raspberry Pi Wireless Access Point tutorial,
there is nothing super special that you will need to be able to complete this.

Recommended:
 Raspberry Pi 2 or 3

 Micro SD Card or a SD card if you’re using an old version of the Pi.

 Wi dongle (The Pi 3 has WiFi inbuilt)

 Ethernet Connection

Optional:
 Raspberry Pi Case

 Setting up the Wireless Access Point


As with most tutorials I do, this one just uses a clean version of Raspbian that has been updated to
the latest packages.
To setup the Raspberry Pi wireless access point we will be making the use of two packages. These
two packages are hostapd and dnsmasq. hostapd is the package that allows us to utilize a Wi-Fi
device as an access point, in our case we will be utilizing this to turn the Raspberry Pi 3’s Wi-Fi into
our access point.

The other package, dnsmasq acts as both a DHCP and DNS server so that we can assign IP
addresses and process DNS requests through our Raspberry Pi itself. As a bonus dnsmasq is very
easy to con gure while being somewhat lightweight in comparison to isc-dhcp-server and bind9
packages.

Remember for this speci c Raspberry Pi tutorial we will need to be utilizing an ethernet network
connection and not the Wi-Fi connection.

1. Before we get started installing and setting up our packages, we will rst run an update on the
Raspberry Pi by running the following two commands.

sudo apt-get update


sudo apt-get upgrade

2. With that done we can now install our two packages, run the following to commands to install
hostapd and dnsmasq.

sudo apt-get install hostapd


sudo apt-get install dnsmasq

3. With the packages now installed we will want to ensure that we are actually given a static IP
address for our Raspberry Pi, one of the ways of doing this is by making some modi cations to the
dhcpcd con guration, in here we can specify a speci c IP Address we want the Raspberry Pi to sit
on as well as IP we want our routers to operate on.

To do this lets begin modifying the dhpcd.conf le by running the following command on our
Raspberry Pi.

sudo nano /etc/dhcpcd.conf

4. Within this le we need to add the following line to the bottom, this will setup our wlan0
interface to the way we want it for our tutorial.

 If you have upgraded to Raspbian Stretch then wlan0 and eth0 may need to be changed. Use the
ifconfig command to see what the new names are, they’re likely quite long. You will need to
update any reference to the new values throughout this tutorial.

interface wlan0
static ip_address=192.168.4.1/24
static routers=192.168.4.0
Now we can save and quit out of the le by pressing Ctrl +X then pressing Y and then Enter.

5. Now we need to restart our dhcpd service so it will load in all our con guration changes, we also
need to reload our wlan0 interface to make sure it’s loaded in our interface changes. Run the
following two commands to reload both:

sudo service dhcpcd restart

6. Next, we need to adjust our hostapd con guration, to do this we need to begin editing the con g
le with the following command:

sudo nano /etc/hostapd/hostapd.conf

7. In this le we need to write out the following lines, these basically set up how we want to
interact with the wlan device. The only real lines you should worry about in this le is the ssid= line
and the wpa_passphrase= line.

 NOTE: If you are doing this tutorial with a different Wi-Fi device then the inbuilt Pi 3 one, you may
have to also change the driver= line to the best driver for your device, google will be your friend for
working out what the best driver to use is.

interface=wlan0
driver=nl80211

hw_mode=g
channel=11
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
ignore_broadcast_ssid=0

# Use WPA2
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

# This is the name of the network


ssid=HLTOR
# The network passphrase
wpa_passphrase=milenovictor

Remember to change wpa_passphrase to your own password, make sure you set it to something
secure so random people can’t just connect into your Wi-Fi access point.

Now we can save and quit out of the le by pressing Ctrl +X then pressing Y and then Enter.
8. With that done we should now have our hostapd con guration, but before it can be used we
need to edit two les. These les are what hostapd will read to nd our new con guration le.

To begin editing the rst of these two les run the following command:

sudo nano /etc/default/hostapd

9. In this le, we need to nd the following line and replace it:

Find:

#DAEMON_CONF=""

Replace with:

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

Now we can save and quit out of the le by pressing Ctrl +X then pressing Y and then Enter.

10. Now we need to edit the second con guration le, this le is located within the init.d folder.
We can edit the le with the following command:

sudo nano /etc/init.d/hostapd

11. In this le, we need to nd the following line and replace it:

Find:

DAEMON_CONF=

Replace with:

DAEMON_CONF=/etc/hostapd/hostapd.conf

Now we can save and quit out of the le by pressing Ctrl +X then pressing Y and then Enter.

12. With hostapd now set up we need to move onto setting up dnsmasq, before we begin editing
its con guration we will move the default one to a new location. We can do this with the following
command:

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


13. Now that the original con guration le is moved out of the way we can begin by creating our
own new con guration le. We will create and edit the new le with the following command:

sudo nano /etc/dnsmasq.conf

14. To this le add the following lines, these lines basically tell the dnsmasq service how to
handle all the connections coming through.

interface=wlan0 # Use interface wlan0


listen-address=192.168.220.1 # Specify the address to listen on
bind-interfaces # Bind to the interface
server=8.8.8.8 # Use Google DNS
domain-needed # Don't forward short names
bogus-priv # Drop the non-routed address spaces.
dhcp-range=192.168.220.50,192.168.220.150,12h # IP range and lease time

Now we can save and quit out of the le by pressing Ctrl +X then pressing Y and then Enter.

15. Next, we need to con gure your Raspberry Pi so that it will forward all tra c from our wlan0
connection over to our ethernet connection. First we must enable it through the sysctl.conf
con guration le, so let’s begin editing it with the following command:

sudo nano /etc/sysctl.conf

16. Within this le you need to nd the following line, and remove the # from the beginning of it.

Find:

#net.ipv4.ip_forward=1

Replace with:

net.ipv4.ip_forward=1

17. Now since we are impatient and don’t want to wait for it to enable on next boot we can run the
following command to activate it immediately:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

18. With IPv4 Forwarding now enabled we can con gure a NAT between our wlan0 interface and
our eth0 interface. Basically, this will forward all tra c from our access point over to our ethernet
connection.
Run the following commands to add our new rules to the iptable:

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


sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABL
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

19. Of course iptables are ushed on every boot of the Raspberry Pi so we will need to save our
new rules somewhere so they are loaded back in on every boot.

To save our new set of rules run the following command:

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

20. Now with our new rules safely saved somewhere we need to make this le be loaded back in
on every reboot. The most simple way to handle this is to modify the rc.local le.

Run the following command to begin editing the le:

sudo nano /etc/rc.local

21. Now we are in this le, we need to add the line below. Make sure this line appears above exit
0. This line basically reads the settings out of our iptables.ipv4.nat le and loads them into the
iptables.

Find:

exit 0

Add above “exit 0”:

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

Now we can save and quit out of the le by pressing Ctrl +X then pressing Y and then Enter.

22.Extra care need to be taked for wpa_supplicant in order for everything to run normally so
modify wpa_supplicant as following:

sudo nano /etc/network/interfaces

Add at the end following:

allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Save the le with Ctrl + X and then pressing Y and then Enter to save changes.

23. Finally all we need to do is start the two services and enable them in systemctl. Run the
following two commands:

sudo service hostapd start


sudo service dnsmasq start

24. Now you should nally have a fully operational Raspberry Pi wireless access point, you can
ensure this is working by using any of your wireless devices and connecting to your new access
point using the SSID and WPA Passphrase that was set earlier on in the tutorial.

To ensure everything will run smoothly it’s best to try rebooting now. This will ensure that everything
will successfully re-enable when the Raspberry Pi is started back up. Run the following command to
reboot the Raspberry Pi:

sudo reboot

This is yet another great project for the Raspberry Pi that can be extended to make it an extremely
useful utility. As I mentioned above you can make this a WiFi access node where you can route all
the internet tra c through a VPN.

I hope this Raspberry Pi Wireless access point tutorial has helped you be able to expand your
wireless network. If you come across any issues or have some feedback related to this tutorial, then
please don’t hesitate to leave a comment below.

You might also like