The cart is empty

In today's digital age, WiFi connectivity is an essential part of our lives. If you have areas in your home or office with insufficient WiFi coverage, you can utilize a Raspberry Pi to extend the range of your network. This article will guide you through the process of setting up a Raspberry Pi as a WiFi repeater.

Requirements

Before you begin, make sure you have:

  • Raspberry Pi (model 3B or newer) with Raspbian or another compatible operating system
  • Power adapter for Raspberry Pi
  • MicroSD card with the operating system installed
  • WiFi dongle (if your Raspberry Pi doesn't have built-in WiFi)
  • Access to your internet router
  • Ethernet cable (for initial setup)

Step 1: Basic Setup of Raspberry Pi

Start by connecting the Raspberry Pi to a monitor, keyboard, and power source. If you're using a Raspberry Pi without built-in WiFi, plug in the WiFi dongle to a USB port. Install the Raspbian operating system using the Raspberry Pi Imager and boot up the Raspberry Pi.

Step 2: Installing and Configuring hostapd and dnsmasq

Open the terminal and run the following commands to update your system and install necessary packages:

 

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install hostapd dnsmasq

After installation, stop the hostapd and dnsmasq services as you'll be configuring them:

sudo systemctl stop hostapd
sudo systemctl stop dnsmasq

Step 3: Setting Up a Static IP Address

Edit the /etc/dhcpcd.conf file and add the following configuration at the end:

 

interface wlan0
    static ip_address=192.168.220.1/24
    nohook wpa_supplicant

This will set a static IP address for the WiFi interface wlan0 of the Raspberry Pi.

Step 4: Configuring hostapd to Create a WiFi Network

Create a new configuration file for hostapd:

sudo nano /etc/hostapd/hostapd.conf

and insert the following configuration, adjusting ssid and wpa_passphrase according to your preferences:

interface=wlan0
driver=nl80211
ssid=MojeWiFi
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=MojeHeslo
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Modify the /etc/default/hostapd file to add the path to your configuration file:

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

Step 5: Configuring dnsmasq as a DHCP Server

Edit the /etc/dnsmasq.conf file and add the following lines to configure the DHCP range:

interface=wlan0
dhcp-range=192.168.220.2,192.168.220.20,255.255.255.0,24h

Step 6: Enabling Internet Routing

Edit the /etc/sysctl.conf file and uncomment the following line:

net.ipv4.ip_forward=1

Then, run the following commands to set up NAT using iptables:

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

Add the following line to the /etc/rc.local file before exit 0 to ensure the NAT rule is restored on every boot:

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

Step 7: Restart and Testing

Restart the Raspberry Pi:

sudo reboot

After rebooting, the Raspberry Pi should be broadcasting a WiFi network according to your configuration. Connect to this network from another device and verify that you have internet access.

By following these steps, you have successfully set up a Raspberry Pi as a WiFi repeater. Your Raspberry Pi is now extending the range of your home or office network.