Home / Tutorials / Raspberry Pi Tutorial / How to Turn a Raspberry Pi into a WiFi Repeater/Extender
pcbway
Raspberry Pi WiFi Repeater

How to Turn a Raspberry Pi into a WiFi Repeater/Extender

In this tutorial, we’ll walk you through the steps to turn your Raspberry Pi into a WiFi repeater or extender. Each step includes explanations to help you understand why the commands and configurations are necessary.

Step 1: Set Up Raspberry Pi OS

Before turning your Raspberry Pi into a WiFi repeater, you need a working operating system. Raspberry Pi OS is lightweight and optimized for the Pi, making it ideal for this project.

Install Raspberry Pi OS:

Download the latest Raspberry Pi OS Lite (or Desktop) from the official website.

Flash the OS to your microSD card using a tool like Raspberry Pi Imager or Balena Etcher.

Enable SSH:

SSH allows you to remotely access your Raspberry Pi’s terminal. This is especially useful if you’re running the Lite version (headless) without a graphical interface.

Create an empty file named ssh (no extension) in the boot partition of the microSD card to enable SSH.

Boot the Raspberry Pi:

Insert the microSD card into the Raspberry Pi, connect it to power, and boot it up.

Connect to the Raspberry Pi:

Use SSH to connect to your Raspberry Pi. If you’re using the desktop version, you can also use the terminal directly.

ssh pi@raspberrypi.local

The default password is raspberry.

Update the system:

Updating the system ensures that you have the latest security patches and software updates.

sudo apt update
sudo apt upgrade -y

Step 2: Install Required Software

 To create a WiFi repeater, you need software to manage the access point (hostapd) and handle DHCP assignments (dnsmasq).

Install the necessary packages:

sudo apt install hostapd dnsmasq -y

hostapd: Creates a wireless access point.

dnsmasq: Manages DHCP and DNS services for the devices connecting to your repeater.

Stop the services for now:

sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

We stop the services temporarily to configure them properly before starting them again.

Step 3: Configure the WiFi Interfaces

 The Raspberry Pi needs to know how to handle its WiFi interfaces. We configure one interface (wlan0) to act as the access point and another (wlan1, if available) to connect to the main WiFi network.

Identify your WiFi interfaces:

Run the following command to see your wireless interfaces:

iwconfig

Typically, the built-in WiFi interface is named wlan0.

Edit the network interfaces file:

Open the network interfaces configuration file:

sudo nano /etc/network/interfaces

Add the following lines to configure wlan0:

auto wlan0
iface wlan0 inet static
    address 192.168.42.1
    netmask 255.255.255.0

This assigns a static IP address to wlan0, which will act as the access point.

Save and exit (Ctrl+X, then Y, then Enter).

 

Step 4: Configure hostapd

hostapd is responsible for creating the WiFi access point. We configure it to broadcast a WiFi network with a specific SSID and password.

Create a configuration file for hostapd:

sudo nano /etc/hostapd/hostapd.conf

Add the following configuration (adjust the SSID and password as needed):

interface=wlan0
driver=nl80211
ssid=MyRPiRepeater
hw_mode=g
channel=6
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MySecurePassword
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP

interface=wlan0: Specifies the WiFi interface to use.

ssid=MyRPiRepeater: The name of the WiFi network.

wpa_passphrase=MySecurePassword: The password for the WiFi network.

Point hostapd to the configuration file:

sudo nano /etc/default/hostapd

Find the line #DAEMON_CONF=”” and replace it with:

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

This tells hostapd where to find its configuration file.

 

Step 5: Configure dnsmasq

 dnsmasq assigns IP addresses to devices connecting to your repeater and handles DNS requests.

Edit the dnsmasq configuration file:

sudo nano /etc/dnsmasq.conf

Add the following lines:

interface=wlan0
dhcp-range=192.168.42.10,192.168.42.100,255.255.255.0,24h

interface=wlan0: Specifies the interface to manage.

dhcp-range: Defines the range of IP addresses to assign to connected devices.

 

Step 6: Enable IP Forwarding

IP forwarding allows the Raspberry Pi to route traffic between the WiFi repeater and the main network.

Enable IP forwarding by editing the sysctl.conf file:

sudo nano /etc/sysctl.conf

Uncomment or add the following line:

net.ipv4.ip_forward=1

This enables IP forwarding at the kernel level.

Apply the changes:

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

Set up NAT (Network Address Translation):

sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

NAT allows devices connected to the repeater to access the internet through the main network.

Make the iptables rule persistent:

Edit the rc.local file:

sudo nano /etc/rc.local

Add the following line before exit 0:

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

This ensures the NAT rule is applied on boot.

 

Step 7: Start the Services

 Starting hostapd and dnsmasq activates the WiFi repeater functionality.

Start and enable hostapd and dnsmasq:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl start dnsmasq

Reboot the Raspberry Pi:

sudo reboot

Step 8: Connect to Your WiFi Repeater

 Once the Raspberry Pi is set up, you need to connect your devices to the new WiFi network.

After the Raspberry Pi reboots, it will act as a WiFi repeater.

Search for the SSID you configured (e.g., MyRPiRepeater) on your devices and connect using the password you set.

Optional: Automate the Process

If you want the Raspberry Pi to automatically connect to your main WiFi network and extend it, you can configure wpa_supplicant.

Edit the wpa_supplicant configuration:

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add the following lines (replace YourMainSSID and YourMainPassword with your network details):

network={
    ssid="YourMainSSID"
    psk="YourMainPassword"
}

Reboot the Raspberry Pi to apply the changes.

Conclusion

By following these steps, you’ve turned your Raspberry Pi into a WiFi repeater/extender. Each step is designed to configure the necessary components (access point, DHCP, IP forwarding, etc.) to ensure seamless operation. If you encounter issues, double-check the configuration files and ensure all services are running properly. Enjoy your extended WiFi coverage!

Check Also

raspberry pi pico hc-sr04 ultrasonic sensor wiring

Interfacing HC-SR04 Ultrasonic Sensor with Raspberry Pi Pico

Introduction Beginner tutorials on the web often use the HC-SR04 ultrasonic sensor. Why? Because it’s …

Index