Setting up a Raspberry Pi as a Wi-Fi extender can be a cost-effective solution to improve Wi-Fi coverage, its alaso a fun little project if your looking for something to do with a Raspberry Pi.
This involves configuring the Raspberry Pi as both a Wi-Fi receiver (to connect to your main router) and a Wi-Fi access point (to extend the network).
Here’s a step-by-step guide:
Requirements
- A Raspberry Pi (Raspberry Pi 3, 4,5 or Zero W recommended for built-in Wi-Fi).
- Raspberry Pi OS (Lite or Desktop version).
- A suitable power supply for the Raspberry Pi you have.
- A microSD card (8GB or larger) with Raspberry Pi OS installed.
- Ethernet cable (optional, for initial setup or bridging).
- A second USB Wi-Fi adapter (optional, for higher performance).
Step 1: Prepare the Raspberry Pi
Install Raspberry Pi OS
- Download and install the Raspberry Pi Imager.
- Use the imager to install Raspberry Pi OS (Lite is sufficient) onto the microSD card.
- Enable SSH:
- After flashing, place a file named ssh (no extension) in the boot partition.
- Enable Wi-Fi (if using Lite version):
- Add a file named wpa_supplicant.conf to the boot partition with the following content:
country=US ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="Your_SSID" psk="Your_PASSWORD" }
Replace Your_SSID and Your_PASSWORD with your Wi-Fi credentials.
- Add a file named wpa_supplicant.conf to the boot partition with the following content:
- Insert the microSD card into the Raspberry Pi and power it on.
Access the Pi
- Find the Raspberry Pi’s IP address using your router or a network scanner.
- SSH into the Raspberry Pi:
ssh pi@<IP_ADDRESS>
Default username: pi, password: raspberry.
- Update the system:
sudo apt update && sudo apt upgrade -y
Step 2: Install Required Software
Now we Install the necessary tools for configuring the Pi as a Wi-Fi extender:
sudo apt install hostapd dnsmasq iptables-persistent
Disable the services until configured:
sudo systemctl stop hostapd sudo systemctl stop dnsmasq
Step 3: Configure the Access Point
Edit hostapd Configuration
Create and edit the hostapd configuration file:
sudo nano /etc/hostapd/hostapd.conf
Add the following:
interface=wlan0 driver=nl80211 ssid=Pi-WiFi-Extender hw_mode=g channel=6 wmm_enabled=1 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=ExtenderPassword wpa_key_mgmt=WPA-PSK rsn_pairwise=CCMP
- Replace ssid with your desired network name.
- Replace wpa_passphrase with a secure password.
Set the hostapd configuration path:
sudo nano /etc/default/hostapd
Uncomment and update:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Configure dnsmasq
Backup the original configuration:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
Create a new configuration:
sudo nano /etc/dnsmasq.conf
Add the following:
interface=wlan0 dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
Step 4: Set Up Network Forwarding
Enable IPv4 forwarding:
sudo nano /etc/sysctl.conf
Uncomment the line:
net.ipv4.ip_forward=1
Apply the changes:
sudo sysctl -p
Add iptables rules for network forwarding:
sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE sudo iptables -A FORWARD -i wlan1 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i wlan0 -o wlan1 -j ACCEPT
Save the rules:
sudo sh -c "iptables-save > /etc/iptables/rules.v4"
Step 5: Configure the Wireless Interface
Edit the dhcpcd configuration:
sudo nano /etc/dhcpcd.conf
Add the following:
interface wlan0 static ip_address=192.168.4.1/24 nohook wpa_supplicant
Restart dhcpcd:
sudo systemctl restart dhcpcd
Step 6: Start the Services
Enable and start hostapd and dnsmasq:
sudo systemctl unmask hostapd sudo systemctl enable hostapd sudo systemctl start hostapd sudo systemctl restart dnsmasq
Step 7: Test the Wi-Fi Extender
- Connect to the new network (Pi-WiFi-Extender or your chosen name) using the configured password.
- Check internet connectivity.
Step 8: Optional Steps
You may want to monitor your network performance, here is an option.
Monitor Performance
- Use tools like nload or htop to monitor network performance.
sudo apt install nload nload
Improve Coverage
- Use an external Wi-Fi adapter for better range.
- Adjust the channel in hostapd.conf to avoid interference.
Secure the Setup
- Change the default pi password.
- Regularly update the system:
sudo apt update && sudo apt upgrade -y
By following these steps, your Raspberry Pi should now function as a Wi-Fi extender, improving coverage and performance in your home or office.