Raspberry Pi as an ethernet to wifi bridge


So, here’s my account of how to set up your Raspberry Pi box as an ethernet bridge.

English: Extract from Raspberry Pi board at Tr...

English: Extract from Raspberry Pi board at TransferSummit 2011 (Photo credit: Wikipedia)

First of all, for those wondering: what is a bridged connection? Essentially this is a “see through” way of extending your network – in a bridge software decides which packets get fowarded on to the next segment of the network. So for a wired to wireless bridge you can imagine it as an extension of the wired network into the wifi-fi space. This is different from just being a router as we don’t need to, for instance, set up a new DHCP server or fix the routing table elsewhere in the network to ensure packets for the wireless connection are sent to your router and so on.

I was already using my Raspberry Pi box as Squid proxy server and I could have gone an extra step of making that “transparent” (ie forcing users to use that via the bridged connection) but that was a level of control too far! But it’s an option. To be honest the RasPi’s (this is a first series version, with less memory) performance as a Squid server seems to tend towards the mediocre, so while I think using a proxy is worth it for limiting the stress on a network like mine (we can have up to 10 devices at once with PCs and phones these days), it’s not fundamental.

Before you begin: The assumption here is that you have an ethernet connection already running and a wireless card (USB device) that supports “promiscuous” mode, meaning it can read packets that were not originally destined for it. I think most modern cards  do that, but I am no expert. The assumption here is that you are running Raspian. If you have another distro adjust the suggestions appropriately.

First step:

sudo apt-get install aptitudeaptitude is just better than apt-get.
sudo aptitude install hostapd bridge-utils – you need these to get the wireless card and the bridge running

Then ensure that IP forwarding is on by editing /etc/sysctl.conf and removing the # from before the line that reads net.ipv4.ip_forward=1.

Second step:

Edit (i.e., create) /etc/hostapd/hostapd.conf – insert your SSID and probably don’t use WEP, which is close to useless…


Third step:

Edit your /etc/network/interfaces file … here is mine:

auto lo
iface lo inet loopback
iface eth0 inet static

auto br0
iface br0 inet dhcp
    pre-up ip link set eth0 down
    pre-up ip link set wlan0 down
    pre-up brctl addbr br0
    pre-up brctl addif br0 eth0 wlan0
    pre-up ip addr flush dev eth0
    pre-up ip addr flush dev wlan0
    post-down ip link set eth0 down
    post-down ip link set wlan0 down
    post-down ip link set br0 down
    post-down brctl delif br0 eth0 wlan0
    post-down brctl delbr br0

(I had to force my eth0 to IP address because of the behaviour of my DHCP server on the commodity router, you may not need to do that, but it is essential that neither your eth0 nor your wlan0 acquire an IP address.)

Fourth step:
Edit your /etc/rc.local file to ensure that the hostapd service is restarted after the bridge comes up. (For DHCP server reasons I also had to ensure my bridge was assigned an IP address – not sure you will need to do that, but it’s probably harmless)

# Setup bridge
dhclient br0
/etc/init.d/hostapd restart

Fifth step:
Restart your box sudo shutdown -r now and if it doesn’t work, don’t blame me, blame the guy who gave me the answer here – http://superuser.com/questions/520172/wired-to-wireless-bridge-in-linux

But hopefully it will work…

One thought on “Raspberry Pi as an ethernet to wifi bridge

  1. Pingback: Wired to wireless bridge in Ubuntu Linux « cartesian product

Comments are closed.