Raspberry Pi WiFi ExtenderA Raspberry Pi WiFi Extender is a cheap and power efficient way of increasing the total range of your WiFi Network. A WiFi extender differs a fair bit from a WiFi access point.

The main difference being that instead of getting its network connection from Ethernet, it instead gets its network connection from a WiFi adapter.
For this reason, to complete this tutorial you will require two WiFi adapters, one of these must be access point capable.

You will face a fair bit of degradation in the speed of your network connection when connecting to the Wi-Fi repeater. The main reason for this is that you must wait for the traffic to go over your initial Wi-Fi connection then be repeated from your Raspberry Pi for devices to connect to.

This tutorial can be combined well with our VPN Access Point tutorial, you can find 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 traffic through that client.

Please note however, this tutorial will require some slight changes, we will explain those changes needed at the end of this tutorial.

Equipment List

Below are all the bits and pieces that I used for this Raspberry Pi WiFi Extender tutorial, you will need two WiFi dongles to be able to complete this tutorial, at least one must be able to act as an access point.

Recommended:

Raspberry Pi 2 or 3

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

Wifi dongle * 2 (The Pi 3 has WiFi inbuilt)

Optional:

Raspberry Pi Case

Setting up the WiFi Extender

To setup our Raspberry Pi Wi-Fi Extender we will need to utilize the dnsmasq package, this package handles most of the grunt work for this tutorial as it acts as both our DNS and DHCP server for our connections. We will also need to utilize the hostapd package, this is the package that will allow us to setup one of our Wi-Fi modules as an access point.

Remember for this tutorial you will need to have an active Wi-Fi router to connect to and an ethernet device you intend on bridging the Wi-Fi connection to.

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

sudo apt-get update
sudo apt-get upgrade

2. With that done we can now install the two packages that we will be utilizing, run the following command to install dnsmasq and hostapd.

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

3. Before we get to far ahead of ourselves, we should setup the wlan0 connection that we plan on using. If you have already setup your wireless connection then you can skip ahead to step 5.

Otherwise open up the wpa-supplicant.conf file by running the following command on your Raspberry Pi:

sudo nano  /etc/wpa_supplicant/wpa_supplicant.conf

4. Within this file add the following, making sure you replace the ssid with the name of the network you want to connect to and replace the psk value with the password for that network.

network={
        ssid="networkname"
        psk="networkpassword"
}

Once you have entered your network name and network password you can save the file by pressing Ctrl + X then Y and then press Enter.

5. With the packages now installed and our Wi-Fi setup we will want to deny any interfaces from using our wlan1 connection, this will help ensure it is free to be used as our access point. To do this we need to edit our dhcpd configuration file with the following command on our Raspberry Pi:

sudo nano /etc/dhcpcd.conf

6. Within this file we need to add the following line to the bottom. However, if you have any interfaces there, then make sure you place it above those as it is needed to override them.

NOTE: If you have upgraded to Raspbian Stretch then wlan0 and wlan1 may need to be changed throughout this tutorial. Use the ifconfig command to see what the new names are, they’re likely quite long and will contain the MAC address.

denyinterfaces wlan1

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

7. With our wireless network now set up to correctly connect we can proceed with setting up our wlan1 interface. This will basically force the operating system to use a static IP address for the wlan1 interface. Not setting this up can cause several issues.

sudo nano /etc/network/interfaces

8. Within the interfaces file we will need to modify the wlan1 section so it looks something like what we have displayed below, this will setup the static up address and allow hot plugging on the wlan1 connection.

allow-hotplug wlan1  
iface wlan1 inet static  
    address 192.168.220.1
    netmask 255.255.255.0
    network 192.168.220.0
    broadcast 192.168.220.255

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

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

sudo service dhcpcd restart
sudo ifdown wlan1; sudo ifup wlan1

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

10. Next, we need to adjust our hostapd configuration, to do this we need to begin editing the config file by running the following command on your Raspberry Pi.

sudo nano /etc/hostapd/hostapd.conf

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

NOTE: You may have to change the driver= line to the best driver for your device, as some Wi-Fi devices have very specific driver requirements. Google will be helpful for looking up what driver you should be using.

interface=wlan1
driver=nl80211

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

auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

ssid=Pi3-Extender
wpa_passphrase=raspberry

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 WiFi extender.

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

12. With that done we should now modify our hostapd files in /etc/default/ and /etc/init.d/. These files are what hostapd will read to find our new configuration file that we created previously.

To begin editing the first of these two files run the following command:

sudo nano /etc/default/hostapd

13. In this file, we need to find 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 file by pressing Ctrl + X then pressing Y and then Enter.

14. Now we need to edit the second configuration file, this file is located within the init.d folder. We can edit the file with the following command:

sudo nano /etc/init.d/hostapd

15. In this file, we need to find 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 file by pressing Ctrl +X then pressing Y and then Enter.

16. With hostapd now setup we need to move onto setting up dnsmasq, before we begin editing its configuration 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

17. Now that the original configuration file is moved out of the way we can begin by creating our own new configuration file. We will create and edit the new file with the following command:

sudo nano /etc/dnsmasq.conf

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

interface=wlan1       # Use interface wlan1  
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 file by pressing Ctrl +X then pressing Y and then Enter.

19. Next, we need to configure our Raspberry Pi so that it will forward all traffic from our wlan1 connection over to our wlan0 connection. First we must enable it through the sysctl.conf configuration file, so let’s begin editing it with the following command:

sudo nano /etc/sysctl.conf

20. Within this file you need to find the following line, and remove the # from the beginning of it.

Find:

#net.ipv4.ip_forward=1

Replace with:

net.ipv4.ip_forward=1

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

21. 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"

22. With IPv4 Forwarding now enabled we can configure a NAT between our wlan0 interface and our wlan1 interface. Basically, this will forward all traffic 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 wlan0 -j MASQUERADE  
sudo iptables -A FORWARD -i wlan0 -o wlan1 -m state --state RELATED,ESTABLISHED -j ACCEPT  
sudo iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT

Note: If you get errors when entering the above lines simply reboot the Pi using sudo reboot.

23. Of course iptables are flushed 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"

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

Run the following command to begin editing the file:

sudo nano /etc/rc.local

25. Now we are in this file, 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 file and loads them into the iptables.

Find:

exit 0

Add ABOVE:

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

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

26. 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

27. Now you should finally 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 its 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

Setting up the Raspberry Pi WiFi Extender with a VPN

This tutorial is fully compatible with our VPN Access Point tutorial. However there is one small change you will have to make in step 13, rather than using the commands showcased there, run the commands below.

Basically the main change you will see here is that instead of redirecting the traffic from wlan0 through the tunnel we will be redirecting the traffic from our wlan1 connection to the tunnel.

sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
sudo iptables -A FORWARD -i tun0 -o wlan1 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan1 -o tun0 -j ACCEPT

The rest of the VPN Access Point tutorial can be done without any other changes.

Hopefully by now you should have a fully operational Raspberry Pi WiFi Extender. If you come across any issues or have some feedback related to this tutorial, then please don’t hesitate to leave a comment below.

The Raspberry Pi Crash Course

The Raspberry Pi Crash Course

Enter your email address below to get the

Raspberry Pi crash course delivered straight to your inbox

Please check your inbox for a confirmation email!