How to Turn Your Raspberry Pi into a Wi-Fi Bridge

Raspberry Pi Wifi Bridge Ethernet

Today, it’s tempting to assume every device supports Wi-Fi, but not all devices are capable of connecting to the Internet wirelessly. This is where a Raspberry Pi can come in handy: by turning it into a Wi-Fi bridge.

If you want to repurpose an old, Ethernet-only desktop computer and need a quick and easy way to convert a Wi-Fi signal into an Ethernet connection, you can use a Raspberry Pi.

Turn your Raspberry Pi into a Wi-Fi bridge

In this tutorial you’ll learn how to transform your Raspberry Pi into a Wi-Fi bridge that connects to your network wirelessly and converts this signal into a wired connection. You can then attach any device to the Raspberry Pi via an Ethernet cable, and that device will instantly have access to your network.

Your Raspberry Pi bridge can convert a Wi-Fi connection, into an ethernet connection.

Before going further, it’s worth noting that a device that’s connected to Wi-Fi via your Raspberry Pi is unlikely to enjoy the same speeds as a device that’s connected to your network directly. However, if it’s not possible to physically connect your Ethernet-only device to your router, then a Raspberry Pi is a quick, easy and relatively inexpensive way to get that device online.

What you’ll need

To complete this tutorial, you’ll need:

  • Raspberry Pi model with Wi-Fi module (Raspberry Pi zero, 3 and 4) running Raspberry Pi OS
  • Power cable that’s compatible with your Raspberry Pi
  • External keyboard and a way to attach it to your Raspberry Pi
  • HDMI or micro HDMI cable, depending on your model of Raspberry Pi
  • External monitor
  • Ethernet cable

Update your Pi

If you haven’t already, attach your external keyboard, monitor, and any other peripherals to your Raspberry Pi, then attach your Pi to a power source.

Before you begin, check that your Raspberry Pi is up to date. Open a new Terminal by clicking the “Terminal” icon in Raspbian’s toolbar, then run the following commands:

Set up your network services: installing dnsmasq

Next, install dnsmasq, which provides Domain Name System (DNS) caching and a Dynamic Host Configuration Protocol (DHCP) server. Use this package to process DNS requests, which will allow your Raspberry Pi to act as a mini-router for an Ethernet-only device.

To install dnsmasq, run the following command:

Configure your ethernet connection

Next, set up the eth0 interface to use a static IP address by modifying the “dhcpcd.conf” file. To open this configuration file, run the following command:

The “dhcpcd.conf” file will now open in the Nano text editor. In this file, add the following:

Save your changes by pressing Ctrl + O. To close the configuration file, press Ctrl + X.

These changes can be live by restarting the dhcpcd service:

Replacing the dnsmasq configuration file

The dnsmasq package provides a default configuration file, but you need to replace this with your own custom settings that tell dnsmasq how to handle DHCP and DNS traffic.

Before making any changes, rename and relocate the original dnsmasq.conf file:

Open the replacement configuration file for editing:

You should now be looking at the dnsmasq.conf file in the Nano text editor. In Nano, add the following:

You can use the Nano text editor to create a custom dnsmasq.conf file.

Save your changes, by pressing Ctrl + O. To close the configuration file, press Ctrl + X.

Enable IP forwarding

Next, enable IP forwarding so that your Raspberry Pi can accept network packets from the Ethernet connection and forward them to your router.

To enable ipv4p IP forwarding, edit the “sysctl.conf” configuration file:

The “sysctl.conf” file will now launch in the Nano text editor. In this file, find the following line:

Remove the # so that this line becomes:

Setup port forwarding on your Raspberry Pi.

Save your changes by pressing Ctrl + O. To close the configuration file, press Ctrl + X.

Now, bring your new “sysctl.conf” configuration file into effect:

Start forwarding traffic from Ethernet to Wi-Fi

Now that you have successfully enabled IP forwarding, you can configure your firewall to forward traffic from the Ethernet interface (eth0) to the Wi-Fi connection. With this forwarding in place, any device that connects to the Raspberry Pi over Ethernet will gain access to the Pi’s Wi-Fi (wlan0) connection.

Add some rules that tell how your Raspberry Pi how to forward all the data packets that it receives:

Save these new rules:

These rules will get flushed every time your Raspberry Pi reboots, so make sure they’re reloaded at startup.

Define what happens at startup by editing the “rc.local” file:

The rc.local file will now open in the Nano text editor. In the editor, find the following:

Add the following directly above the “exit” line:

Save your changes by pressing Ctrl + O. To close the configuration file, press Ctrl + X.ter.”

Test your Wi-Fi bridge

The final step is starting the dnsmasq service:

You can now put your Wi-Fi bridge to the test! Attach any Ethernet-only device to your Raspberry Pi via an Ethernet cable. Your Raspberry Pi will now provide an Internet connection to this Ethernet-only device.

Conclusion

You have learned how to share your Raspberry Pi’s Wi-Fi with any wired device by converting its Wi-Fi connection into an Ethernet connection. You can also use your Raspberry Pi as a Captive Portal Wi-Fi hotspot or as a personal web server. Let us know if this is useful to you.

Read on for other Raspberry Pi projects you can do on your own.

Related:

3 comments

  1. That’s … That’s not a bridge. You are describing a router. A bridge is something fundamentally different.
    This is an O.K. router tutorial that unfortunately has nothing to do with a bridge.

  2. I’m recently bought a rpi4 just to do this. This is the fourth tutorial I’ve tried! The end result is, no eth0 IP address, dhcpcd lost, and no interface found. I’m sure I’m doing something wrong. Is there a way I can get help?

  3. I don’t need help! Working great. I did a small change for the, to replace dnsmasq. Added mv and removed nano. sudo mv /etc.
    I also had to redirect wlan0 with eth0.
    But now I can’t use my Raspberry for any thing else. Can’t connect headless, and no internet for browser.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.