baantonia
Posts: 62
Joined: Fri Feb 06, 2015 2:19 pm

Re: Pi as wireless bridge?

Fri Apr 03, 2015 6:53 pm

Success yesterday! After a week of trial and error, scouring the Internet for clues, I managed to build a transparent bridge using a Raspberry Pi and an Edimax wifi USB dongle. A device (laptop) was connected to the ethernet port using a crossover UTP cable and its wifi disabled.

This is using the most up to date Raspbian distro, install of bridge-utils and ebtables followed by a full update.

The Raspberry Pi is connecting to one of our SSIDs via Cisco APs and controller.

One thing I found though, if I gave the Raspberry Pi an IP address, communication between the device connected to the ethernet port had intermittent connectivity to the rest of the network. The device also required a static address in the range of the wireless range , DHCP did not work.

Two sites which helped me to some extent were:
http://blog.slor.net/2013/09/turning-yo ... eless.html
https://wiki.debian.org/BridgeNetworkConnections
However both solutions if configured as described, for me did not work.

The solution is completely transparent and works at layer 2, no NATting, proxies or port fowarding which are all layer 3. I am able to ping other equipment around the network and nmap the device from the network to discover open ports.

I'll post the configuration as soon as I get chance, but at present, cooking supper is calling......
Last edited by baantonia on Sat Apr 04, 2015 12:11 am, edited 1 time in total.

baantonia
Posts: 62
Joined: Fri Feb 06, 2015 2:19 pm

Re: Pi as wireless bridge?

Sat Apr 04, 2015 12:04 am

Here are the configurations I'm using:

/etc/network/interfaces

Code: Select all

# /etc/network/interfaces

auto lo

iface lo inet loopback

allow-hotplug eth0
iface eth0 inet manual

auto ath0
iface ath0 inet manual
    bridge_ports eth0
    bridge_hw <mac-address-of-wireless-dongle>
    bridge_stp off
    bridge_maxwait 5

allow-hotplug wlan0
auto wlan0
iface wlan0 inet manual
    pre-up wpa_supplicant -Dwext -i wlan -b ath0 -c /etc/wpa_supplicant/wpa_supplicant.conf -B

#iface default inet dhcp
/etc/wpa_supplicant/wpa_supplicant.conf

Code: Select all

# /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant Group=netdev
update_config=1
ap_scan=2
eapol_version=1
network={
    ssid="Your-SSID"
    scan_ssid=1
    mode=0
    proto=WPA
    pairwise=TKIP
    group=TKIP
    key_mgmt=WPA-PSK
    psk="Your-Pre-Shared-Key"
}
/etc/rc.local

Code: Select all

#!/bin/sh -e
#
# /etc/rc.local
brctl addif ath0 wlan0
ebtables -t nat -A POSTROUTING -o wlan0 -j snat --to-src <mac-address-of-wireless-dongle> --snat-arp --snat-target ACCEPT
ebtables -t nat -A PREROUTING -p IPv4 -i wlan0 --ip-dst <IP-address-of-device> -j dnat --to-dst <mac-address-of-device> --dnat-target ACCEPT
ebtables -t nat -A PREROUTING -p ARP -i wlan0 --arp-ip-dst <IP-address-of-device> -j dnat --to-dst <mac-address-of-device> --dnat-target ACCEPT
Also in /etc/sysctl.conf the following line is enabled, not sure if it is required, have not tested with it commented out.
net.ipv4.ip_forward=1

Replace the parts in <>, including the symbols <> with those for your own configuration. My wpa_supplicant config uses a cleartext pre shared key, change yours to suit your own setup. I've used ath0 as my bridge interface, probably br0 could be used instead. Haven't tested multiple devices connected to the eth0 port of the Raspberry Pi, but if required, repeat the last two ebtables statements with the appropriate changes for the next device. Note none of the interfaces have a static IP address or get one from DHCP, in my setup, adding an IP address caused intermittent issues. Each ebtables line is on one line, in my browser it gets wrapped, the --snat-target ACCEPT and the --dnat-target ACCEPT should be on the same line as the ebtables.

Well this is how I did it.

User avatar
littlebit
Posts: 11
Joined: Wed Jul 03, 2013 11:03 am

Re: Pi as wireless bridge?

Sat Apr 04, 2015 12:10 pm

I went through your configuration and aside that you have a thing for atheros wireless cards, it seems to work as you described. But unfortunately doesn't cover that needs to be covered. :cry:

razza30
Posts: 8
Joined: Fri Jul 26, 2013 10:01 pm

Re: Pi as wireless bridge?

Sat Apr 04, 2015 2:09 pm

baantonia wrote:Success yesterday! ......
Excellent, thanks! I will have a play next week when I am back home :D

baantonia
Posts: 62
Joined: Fri Feb 06, 2015 2:19 pm

Re: Pi as wireless bridge?

Sat Apr 04, 2015 11:21 pm

On some site I read that using br0 had an ill effect in using wpa_supplicant, which was probably incorrect, I didn't test it, but that said, at that point I hadn't managed to get a working connection. Maybe I should replace all the ath0 for br0 and check, it would be an interesting experiment to see if using br0 has a detrimental effect.

Anyway, in theory you could use any label for the bridging interface, I chose ath0 as an alternative, you could use goldfish0 in place of ath0 and it should work, just make sure to replace them all to be the same, the label ath0 has no real meaning. The bridging interface doesn't physically exist, it only exists in software.

The physical interface for the wireless I'm using is a Edimax USB dongle, I expect many owners of Raspberry Pi's have these.

Note, I've configured bridging interfaces on Cisco 3640 routers before but haven't done so using Linux, let alone a Debian variety, normally I use OpenSuSE for my desktop. So the label ath0 is an enigma to me, I just saw it and used it in my configuration. The relative merits, or otherwise, of atheros wireless cards I don't know as I don't have one to test.

The original question was:
This may be a crazy question, but is there any way to easily allow a Pi with a working wi-fi connection to 'share' its internet connection with anything plugged into the ethernet conenctor, in much the same way as Windows computers can be set to do that?
Although SiriusHardware only required a temporary connection.

This is what I needed to achieve as well but more permanent and this configuration seems to fit the bill, all that needs to be changed is the wifi authentication, the MAC addresses and a chosen IP address which would also be statically set on the device (with the associated other settings such as mask, gateway and DNS), to connect to the Raspberry Pi's ethernet port. Note the use of a crossover UTP cable and the Raspberry Pi itself has no layer 3 network connectivity, it cannot be used to communicate to the Internet itself in this state as it has no IP address. I found in my test scenario with Cisco AP's, adding an IP address to the Raspberry Pi produced an intermittent wifi connection, probably something to do with security. I did play with the security settings on the controller but didn't manage to make it work continuously. Also I couldn't get DHCP to work for the connected device, hence the static settings, and in any case, the MAC address received by the DHCP server would be that of the wireless dongle, not that of the connected device.

User avatar
littlebit
Posts: 11
Joined: Wed Jul 03, 2013 11:03 am

Re: Pi as wireless bridge?

Wed Apr 29, 2015 9:05 pm

Ok, after spontaneous reviewing my bridge configurations I thought that it could be the ifplugd that could be someone that meddles with my interfaces, as a result I went to /etc/default/ifplugd.conf and commented out all the lines. I still get those dropouts from my router (avm fritzbox 7270) and ifplugd still appears, so I took my pi and set it up at work and took it for a testdrive, and the link was stable :D.

So this is my configuration that I would like to share with the community to try out and give me their feedback, also please mention what kind of router do you have when using the pi as a bridge.
@/etc/network/interfaces:

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet manual

auto wlan0
iface wlan0 inet manual
pre-up wpa_supplicant -B w -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

auto br0
iface br0 inet dhcp
	bridge_ports wlan0 eth0
	bridge_stp off
	bridge_maxwait 5
	bridge_fd 0
@/etc/default/ifplugd.conf:

Code: Select all

# This file may be changed either manually or by running dpkg-reconfigure.
#
# N.B.: dpkg-reconfigure deletes everything from this file except for
# the assignments to variables INTERFACES, HOTPLUG_INTERFACES, ARGS and
# SUSPEND_ACTION.  When run it uses the current values of those variables
# as their default values, thus preserving the administrator's changes.
#
# This file is sourced by both the init script /etc/init.d/ifplugd and
# the udev script /lib/udev/ifplugd.agent to give default values.
# The init script starts ifplugd for all interfaces listed in
# INTERFACES, and the udev script starts ifplugd for all interfaces
# listed in HOTPLUG_INTERFACES. The special value all starts one
# ifplugd for all interfaces being present.
#INTERFACES=""
#HOTPLUG_INTERFACES=""
#ARGS="-q -f -u0 -d10 -w -I"
#SUSPEND_ACTION="stop"
@/etc/wpa_supplicant/wpa_supplicant.conf:

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
	ssid="your ssid here"
	psk="your preshared key here"
	proto=RSN
	key_mgmt=WPA-PSK
	pairwise=CCMP
	auth_alg=OPEN
}
What I need to know if there is anyone who is using this config is having similar problems or not.
Let me read your feedback, and my question to the hardware and kernel developers:
What does
ifplugd(eth0) Link beat detected
mean?

pathead
Posts: 21
Joined: Mon Dec 14, 2015 7:19 pm

Re: Pi as wireless bridge?

Thu Jan 14, 2016 10:51 pm

This thread was useful but pretty old so I just wanted to explain how I got it working using the current Rasbian distro(4.1).

Starting from a clean install, as mentioned by timb, use the wifi connection GUI so that it fills out the wpa_supplicant file automatically. For reference, my auto-generated wpa_supplicant.conf looked like this:

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
        ssid="mynetwork"
        psk="secret"
        key_mgmt=WPA-PSK
}
Then install the bridge-utils and create the bridge.

(side note, I forgot to apt-get update before doing this but it turned out fine)

Code: Select all

sudo apt-get install bridge-utils
sudo brctl addbr br0
sudo brctl addif br0 wlan0 eth0
That should be all you have to do to get this setup manually. The only problem is that it gets reset during a reboot.

I tried pretty much every configuration I could think of to put into /etc/network/interfaces and could not get it to work no matter what I did. The obvious alternative though is to just add them to /etc/rc.local instead and have the commands run at boot.

So, from a clean install, you should not have to edit /etc/network/interfaces at all. For reference, I'll copy/paste what that should look like with the current kernel:

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
The only real change we need to do is add the 2 commands from above to /etc/rc.local. The default file has some comments and a print statement, just add the commands after the statement but before 'exit 0':

Code: Select all

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

brctl addbr br0
brctl addif br0 wlan0 eth0

exit 0
In order for this to work at startup wlan0 and eth0 need to be initialized before the bridge is added. There are several ways to do this and since I am fairly new to linux I decided to just turn on the 'wait for network at boot' option in raspi-config and that worked fine for me. A script call that first sleeps for 30 seconds or something would probably work as well.

This seems like a long explanation but ultimately, from a clean install, you just need to setup the wifi connection and then edit rc.local to start the bridge on boot. Like I said I am new so maybe I am doing something wrong or maybe there is just a lot of ways to do this but I could not get this to work using any of the methods described in previous posts.

Good luck...
Last edited by pathead on Fri Jan 15, 2016 10:40 pm, edited 1 time in total.

User avatar
RDK
Posts: 169
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Pi as wireless bridge?

Fri Jan 15, 2016 6:35 pm

Which distro are you using Wheezy or Jessie? Did you install the bridge-utils ? Thanks....RDK

pathead
Posts: 21
Joined: Mon Dec 14, 2015 7:19 pm

Re: Pi as wireless bridge?

Fri Jan 15, 2016 10:40 pm

Raspbian Jessie 4.1. And yes bridge-utils is the only thing you need to install.

User avatar
RDK
Posts: 169
Joined: Wed Aug 13, 2014 10:19 am
Location: Wyoming and France

Re: Pi as wireless bridge?

Mon Feb 01, 2016 10:44 pm

Hi. Just got around to trying this as I have an application for a wireless bridge. No happiness here. I tried the "wait for network..." option in the Raspi-Config and the sleep 10 option in the rc.local (along with the other two commands). In both cases I get "can't add wlan 0 to bridge br0: operation not supported".

When I do either of the above, I do get the print message with my IP address in the boot-up console messages. That does not show when I use the default rc.local, so I know the network configuration process is finished.

It also says something about an rc.local compatibility issue??...RDK

grissgray
Posts: 12
Joined: Wed Mar 11, 2015 10:46 pm

Re: Pi as wireless bridge?

Mon Feb 01, 2016 11:38 pm

hi all im trying to do this since xmas did anyone get this too work

Spittualengr
Posts: 1
Joined: Wed Mar 23, 2016 3:31 pm

Re: Pi as wireless bridge?

Wed Mar 23, 2016 3:36 pm

I am struggling with this as well. Have a pi3 that I am trying to share the wlan0 to a second pi2 device over eth0.

1. I keep getting error that wlan0 can't added to the bridge br0
2. I can't get the bridge br0 to automatically create at reboot

TheRWT
Posts: 1
Joined: Wed Mar 30, 2016 4:56 pm

Re: Pi as wireless bridge?

Wed Mar 30, 2016 5:01 pm

Me too. Pi3. A updated tutorial would be helpful as i am not so great at these things. YET.

arre
Posts: 3
Joined: Fri May 27, 2016 2:28 pm

Re: Pi as wireless bridge?

Fri May 27, 2016 2:40 pm

Hi,

I successfully have two pi's connected over wifi (192.168.0.99, and 192.168.0.91), while only 1 of them has a wifi adaptor, and they just have an ethernet cable between them. I also first tried to bridge the wlan0, but ran into the error: "can't add wlan0 to bridge br0: Operation not supported". So, for whatever reason it refuses to do that (as other people seem to succeed), I switched to another method, and succeeded.

Thought I'd share my setup here:

Setup:

[ Pi1] ---(ethernet direct connection)--- [Pi2] --((wifidongle))

Pi1: eth0: 192.168.1.98 -> gw 192.168.1.97
Pi2: eth0: 192.168.1.97
wlan0: 192.168.0.91
192.168.0.99

Pi2 is connected directly to the wifi, and has the two addresses configured (.99 and .91).
Pi1 has no idea it is connected to the wifi, and just has an internal address 192.168.1.98, and has a default route to the other pi.

Clue:

The magic here, is that Pi2 actually fakes being two different devices on wlan0, and spoofs the packets that are going to 0.99 to actually to 1.98 and vice versa.

Configs:

All that is needed, is to have a network/interfaces like so:

Code: Select all

auto eth0
auto lo wlan0
iface lo inet loopback

iface eth0 inet static
 address 192.168.1.97
 netmask 255.255.255.0

allow-hotplug wlan0
iface wlan0 inet static
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.0.92
    netmask 255.255.255.0
    gateway 192.168.0.1

# Give it a secondary address too
iface wlan0 inet static
    address 192.168.0.99
And execute the following commands at boot:

Code: Select all

IP="192.168.0.99"
IPINT="192.168.1.98"
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s $IPINT -j SNAT --to-source $IP
iptables -t nat -A PREROUTING  -d $IP -i wlan0  -j DNAT --to-destination $IPINT
Hope this helps someone

bobomatic
Posts: 1
Joined: Thu Aug 04, 2016 6:47 pm

Re: Pi as wireless bridge?

Thu Aug 04, 2016 6:54 pm

This (and a few similar) links suggest a transparent Wifi-Eth bridge is technically impossible if there is more than one client on the ethernet side without the introduction of masquerading. Specifically, it explains why:

sudo brctl addif br0 eth0 wlan0

can't add wlan0 to bridge br0: Operation not supported

fails

http://superuser.com/questions/597834/b ... ot-working

This thread

http://serverfault.com/questions/152363 ... n0-to-eth0

explains how to set up the masquerading work-around

Bob

grissgray
Posts: 12
Joined: Wed Mar 11, 2015 10:46 pm

Re: Pi as wireless bridge?

Wed Aug 17, 2016 10:51 pm

did any one get this pi bridge too work

mfa298
Posts: 974
Joined: Tue Apr 22, 2014 11:18 am

Re: Pi as wireless bridge?

Thu Aug 18, 2016 10:23 am

grissgray wrote:did any one get this pi bridge too work
As I'm sure you've read in the other posts, bridging where the wireless card is acting as a client device will never work correctly as it's a limitation of how wireless work. There are wireless bridge options but they generally require specialised devices on both ends that are designed to work together like that (e.g. Ubiquiti's air fibre product).

The only option that's guaranteed to work with the Pi is to have the pi acting as a router where it provides a different network and dhcp to the wired side (and potentially NAT as well).

Return to “Beginners”

Who is online

Users browsing this forum: nunocv and 31 guests