WiFi Extender

This page will help building a Wifi Extender with a Raspberry Pi. The various commands are detailed below:

sudo apt update && sudo apt upgrade -y
sudo rpi-update

We will use dnsmasq and hostapd

sudo apt install dnsmasq hostpad

Then we will create the wpa_supplicant.conf file

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

The file should have the following structure:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=SG
network={
ssid="yourssid"
psk="yourpsk"
key_mgmt=WPA-PSK
}

Then, open the file /etc/iptables.ipv4.nat. It should look like this:

sudo nano /etc/iptables.ipv4.nat



# Generated by iptables-save v1.6.0 on Sat Oct 27 15:04:05 2018
*nat
:PREROUTING ACCEPT [1762:115551]
:INPUT ACCEPT [1745:114531]
:OUTPUT ACCEPT [89:5463]
:POSTROUTING ACCEPT [34:1966]
-A POSTROUTING -o wlan1 -j MASQUERADE
COMMIT
# Completed on Sat Oct 27 15:04:05 2018
# Generated by iptables-save v1.6.0 on Sat Oct 27 15:04:05 2018
*filter
:INPUT ACCEPT [3322:438781]
:FORWARD ACCEPT [1844:1919091]
:OUTPUT ACCEPT [2610:260293]
-A FORWARD -i wlan0 -j ACCEPT
COMMIT
# Completed on Sat Oct 27 15:04:05 2018

sudo nano /etc/network/interfaces:

# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto wlan0
iface wlan0 inet static
address 192.168.52.1
netmask 255.255.255.0
nohook wpa_supplicant

auto wlan1
iface wlan1 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
up iptables-restore < /etc/iptables.ipv4.nat

sudo nano /etc/default/hostapd:

Replace DAEMON_CONF by:

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

sudo nano /etc/hostapd/hostapd.conf:

interface=wlan0
driver=nl80211
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=Raspberry
channel=1
hw_mode=g
ieee80211n=1
wpa=2
wpa_passphrase=passphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
country_code=SG

sudo nano /etc/dnsmasq.conf:

Replace interface= by
interface=wlan0

Replace dhcp-range= by
dhcp-range=192.168.52.10,192.168.52.30,255.255.255.0,12h 

sudo nano /etc/sysctl.conf:

#Uncomment the line
net.ipv4.ip_forward=1

Then run the following commands:

#Enable Secure Shell Service
sudo systemctl enable ssh
# Enable hostapd service
sudo systemctl enable hostapd
#Enable dnsmasq service
sudo systemctl enable dnsmasq
#Reboot the device
sudo reboot