So, here’s my account of how to set up your Raspberry Pi box as an ethernet bridge.
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.
sudo apt-get install aptitude –
aptitude is just better than
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
Edit (i.e., create)
/etc/hostapd/hostapd.conf – insert your SSID and probably don’t use WEP, which is close to useless…
interface=wlan0 bridge=br0 driver=nl80211 auth_algs=1 macaddr_acl=0 ignore_broadcast_ssid=0 logger_syslog=-1 logger_syslog_level=0 hw_mode=g ssid=YOUR_SSID channel=11 wep_default_key=0 wep_key0=YOUR_WEP_KEY wpa=0
/etc/network/interfaces file … here is mine:
auto lo iface lo inet loopback iface eth0 inet static address 0.0.0.0 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
0.0.0.0 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.)
/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
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…
- Uses for a Raspberry Pi (cartesianproduct.wordpress.com)
- Bridging between two Ethernet cards (daniweb.com)
- Mesh networking with multiple Raspberry Pi boards (hackaday.com)
- RaspberryPi Secure VoIP access points with GNU SIP Witch (ubuntuwicohan.blogspot.com)
One response to “Raspberry Pi as an ethernet to wifi bridge”
[…] Raspberry Pi as an ethernet to wifi bridge […]