Raspberry Pi as a WiFi repeater - how it works
In this practical tip you will learn how you can use your Raspberry Pi as a WiFi repeater. So you have the best WiFi reception in your home.
Raspberry Pi as a WiFi repeater: the accessories you need
In order to be able to use your Raspberry Pi as a WiFi repeater, you need - in addition to the Raspberry Pi with Raspbian - the following accessories.
- Two WLAN sticks with Ralink RT5370 chipset
- A power supply for the Raspberry Pi
Prepare Raspberry Pi for WLAN: Install Hostapd and dnsmasq
First install hostapd and dnsmasq so that you can use your Raspberry Pi as an AP and DHCP server. Hostapd is a so-called authenticator, which ultimately creates the WLAN access point, while dnsmasq is a simple DNS and DHCP server that forwards unknown name requests and stores them in the cache. To do this, run the following command:
- sudo apt-get install hostapd dnsmasq
Assign a static IP to the WLAN stick
As soon as this is done, you have to assign a static IP to the WLAN stick. To do this, edit the "/ etc / network / interfaces" file and enter the following here:
- ## / etc / network / interfaces for wlan0 device
- # Setup the device with an static IP
- iface wlan0 inet static
- # Static IP address
- address 10.0.0.1
- # Networkmask
- netmask 255.255.255.0
Configure Raspberry Pi: hostapd
Now you have to edit the hostapd configuration file ("DAEMON_CONF =" / etc / hostapd / hostapd.conf ""). Customize the file as follows:
- # Content of /etc/hostapd/hostapd.conf
- # 1.The device which will act as AP
- interface = wlan0
- driver = nl80211
- # 2.Parameters so that the daemon runs
- ctrl_interface = / var / run / hostapd
- ctrl_interface_group = 0
- # 3. The Wifi configuration
- ssid = Raspi
- channel = 6
- hw_mode = g
- ieee80211n = 1
- # 4. Security of the Wifi connection
- wpa = 2
- wpa_passphrase = VERY SECRET
- wpa_key_mgmt = WPA-PSK
- wpa_pairwise = CCMP
- rsn_pairwise = CCMP
- # 5. Other settings
- beacon_int = 100
- auth_algs = 3
- wmm_enabled = 1
Raspberry Pi as a WiFi repeater: Allow IP addresses to be assigned
Now adapt the "/etc/dnsmasq.conf" file so that the Raspberry Pi can also assign IP addresses:
- interface = wlan0
- dhcp-range = 10.0.0.2, 10.0.0.20, 255.255.255.0, 12h
Connect Raspberry Pi to the router
Use the "sudo apt-get install wpa_supplicant" command to ensure that wpa_supplicant is installed, create the configuration file "/etc/wpa.conf" and enter the following here. Don't forget to adjust "myssid" and "password" accordingly.
- network = {
- ssid = "myssid"
- psk = "password"
- priority = 0
- }
DIY WiFi repeater: Establish connection
So that the Raspberry Pi now also establishes the connection correctly, you have to edit the file "/ etc / network / interfaces".
- ## Additional lines in / etc / network / interfaces for wlan1 device
- # Start the device at system startup
- car wifi1
- # Configure the device via dhcp
- iface wlan1 inet dhcp
- # Use the given file for connecting to the internet
- wpa-conf /etc/wpa.conf
Edit the network settings of the Raspberry Pi
In order to pass on the internet signal to the devices connected to the Raspberry Pi, you have to edit the sysctl configuration file.
- In the file "/etc/sysctl.conf" remove the double cross (#) at the line "# net.ipv4.ip_forward = 1".
- Use the "sysctl -p" command to reread the sysctl.conf file.
- Install iptables with the command "sudo apt-get install iptables" so that the Raspberry Pi can send packets between the WiFi networks.
Edit the firewall in the Linux kernel
To ensure that the connection is automatically provided when the Raspberry Pi boots, create the "/etc/network/if-up.d/router.sh" file and insert the following. Don't forget to mark your file as executable (chmod + x).
$config[ads_text5] not found- iptables --table nat --append POSTROUTING --out-interface wlan1 -j MASQUERADE
- iptables --append FORWARD --in-interface wlan0 -j ACCEPT
Activate gateway to the Internet
Finally, you need to make sure that dnsmasq tells the devices that it is a gateway to the Internet. To do this, edit the file "/etc/dnsmasq.conf" and enter the following. After that, all you have to do is reboot your Raspberry Pi.
- dhcp-option = 3, 10.0.0.1