A Raspberry Pi WiFi bridge is one of the best ways to provide Internet access to a device that only supports an Ethernet connection.

In this tutorial, we'll show you how to set up a WiFi bridge and configure dnsmasq correctly so that any device can connect through your Pi without any problems.
You have to keep in mind that the speed will not be as high as when it is connected directly to your router. Since the connection must be made through the Raspberry Pi, there is some overhead.
Remember that for this tutorial you will need a WiFi dongle or aRaspberry Pi 3 with built-in WiFi module.
This tutorial can be combined with our basic VPN hotspot. You can find the setup tutorial right after this tutorial. It basically shows how to set up an OpenVPN client and route all traffic through this client.
Note: This tutorial requires some minor modification if you decide to go the VPN route. We will explain the necessary changes at the end of this tutorial.
team list
Below are all the little things I used for this Raspberry Pi Wi-Fi Bridge tutorial. You need a wireless Internet connection to complete this tutorial.
recommended
- raspberry pi
- micro SD card
- W-LAN
- cabo ethernet
Optional
- raspberry pi case
Wi-Fi Bridge Configuration
To configure the Raspberry Pi Wifi Bridge, we will beUsing the dnsmasq package, this package does most of the basic work of this tutorial.
Dnsmasq is a package that acts as a local DHCP server and a local DNS server. We use this package so that we can assign IP addresses and handle DNS requests through the Raspberry Pi itself and act as a router.
One of the use bonuses.dnsmasq
is that it is very easy to set up and is lightweight compared to somethingisc-dhcp-servidor
mibinden9
Package.
Please note that for this tutorial you will need an active WiFi router that you can connect to and an Ethernet device that you want to connect the WiFi connection to.
1.Before we start installing and configuring our packages, we will first update the Raspberry Pi by typing the following two commands in terminal.
sudo apt-Updatesudo apt-Update
2.With that, we can now install the two packages that we are going to use.
Run the following command to installdnsmasq
miiptables
. We use iptables to manage the firewall on our device.
sudo apt-get install dnsmasq iptables
3.Before we get too far, we should set this up.WLAN0connection we want to use.
if you already haveSet up your wireless connectionthen you can continue with step 5.
Otherwise, open thewpa_supplicant
file by running the followingnano command:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
4.In this file, add the following, making sure to replace the ssid with the name of the network you want to connect to, and replace the psk value with the password for that network.
network={ ssid="network name" psk="network password"}
5.Now that the wireless network is configured to connect correctly, we can proceed to configure oureth0
Interface.
Basically, this forces you to use a static IP address. If this is not configured, various problems can occur.
To do this, we need to change it.dhcpcd.conf
file by running the following command:
sudo nano /etc/dhcpcd.conf
Important note:If you are using Raspbian Stretch or newerWLAN0
mieth0
it may need to be changed if predictable network names are enabled.
use theifconfig
command to see the new names, they are probably too long and contain the MAC address.
Be sure to update them for all the commands in this tutorial.
6.Inside this file we need to add the following lines, make sure to replace themeth0
with the correct interface of your Ethernet.
Interface eth0static ip_address=192.168.220.1/24router estático=192.168.220.0
Now we can save the file and exit by pressingCONTROL+Xthen pressYand thenFORBIDDEN.
7.With our changes to the dhcpcd configuration, we now need to restart the service by running the following command:
Restart the service sudo dhcpcd
8.Before we start changing the dnsmasq configuration, let's first create a backup of the original configuration by running the following command.
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
9.With the original configuration now backed up and out of the way, we can now go ahead and create our new configuration file by typing the following command in terminal.
sudo nano /etc/dnsmasq.conf
10Now that we've created our new file, we want to add the following lines.
These lines basically tell the dnsmasq package how to handle DNS and DHCP traffic.
interface=eth0 # Use interface eth0 listen-address=192.168.220.1 # Specify address to listen on bind-dynamic # Bind interface server=8.8.8.8 # Use required Google DNS domain # Do not forward aliases bogus-priv # Exclude non-routed address spaces. dhcp-range=192,168,220,50,192,168,220,150,12h # IP range and lease duration
Now we can save the file and exit by pressingCONTROL+Xthen pressYand thenFORBIDDEN.
11Now we need to configure the Raspberry Pi's firewall to forward all traffic from our eth0 connection to our wlan0 connection.
Before doing this, we must first enable ipv4p IP forwarding through thesysctl.conf
configuration file, so let's start editing with the following command:
sudo nano /etc/sysctl.conf
12Inside this file you should find the following line and remove the # from the beginning.
Meet:
#net.ipv4.ip_forward=1
Replace with:
net.ipv4.ip_forward=1
Now we can save the file and exit by pressingCONTROL+Xthen pressYand thenFORBIDDEN.
13Now that we don't have to wait until the next reboot to load the configuration, we can run the following command to activate it immediately.
sudo sh -c "eco 1 > /proc/sys/net/ipv4/ip_forward"
14Now that IPv4 forwarding is enabled, we can reconfigure our firewall to forward traffic from oureth0
interface with ourWLAN0
Connection.
Basically this means that anyone connecting to ethernet can use our wlan0 internet connection.
Run the following commands to add our new rules to iptable:
sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADEsudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED, ESTABLISHED -j ACCEPT sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
Observation:If you get errors typing the lines above, just reboot your Pi withsudo restart
.
15.Of course, the iptables are flushed every time the Raspberry Pi boots, so we need to save our new rules somewhere so they're reloaded every time we boot.
To save our new set of rules, run the following command.
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sixteen.Now that our new rules are safely stored somewhere, we need to make sure that this file is reloaded on every reboot.
The easiest way to deal with this is to change therc.local
Archive.
Run the following command to start editing the file.
sudo nano /etc/rc.local
17Now that we're in this file, we need to add the following line.
Make sure this line above "salida 0
“.
This line basically reads the configuration of ouriptables.ipv4.nat
file and uploads it to iptables.
Meet:
salida 0
Add above:
restore iptables < /etc/iptables.ipv4.nat
Now we can save the file and exit by pressingCONTROL+Xthen pressYand thenFORBIDDEN.
18Finally, all we have to do is start our dnsmasq service.
All you have to do is run the following command:
sudo-service start dnsmasq
19You should now finally have a fully functional Raspberry Pi WiFi bridge. You can make sure this works by connecting any device to your Ethernet port. The bridge must provide an Internet connection for the device you connect it to.
To make sure everything runs smoothly, it's best to try a reboot now.
This will ensure that everything is successfully reactivated when the Raspberry Pi boots up again.
Run the following command to reboot the Raspberry Pi:
sudo restart
Configuring the Raspberry Pi WiFi Bridge with a VPN
This tutorial is fully compatible withBasic VPN Router Tutorial.
However, there is one small change you need to make.paso 13, instead of using the commands shown there, run the following commands.
Basically, the main change you'll see here is that we're redirecting traffic from our eth0 connection to the tunnel, instead of redirecting traffic from wlan0 through the tunnel.
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASKSUDO iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED, SET -j ACCEPTsudo iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT
The rest of the VPN hotspot tutorial can be done without further modification.
Hopefully, you now have a fully functional Raspberry Pi WiFi bridge. If you run into any issues or have any feedback on this tutorial, feel free to leave a comment below.
recommended
Enabling SPI on the Raspberry Pi
Run or Redis on Raspberry Pi
Global variables in Python
Block ads with AdGuard Home on your Raspberry Pi
Reproductor multimedia Raspberry Pi Plex
Run Pi-Hole as a Docker container