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

How To: Wifi to Ethernet Bridge(Updated for RPi 3)

Thu Jan 14, 2016 11:15 pm

The method I had here originally no longer works. I have updated the guide to work with the Raspberry Pi 3 and the built in wifi.

Originally, this would allow something connected to the Pi via ethernet to get an IP directly from the WiFi. That might still be possible but for my purposes was not necessary.

This is basically just a reversed version of this guide.

This method works by creating a DHCP server on the Pi's ethernet connection and internally it 'shares' the internet access between eth0 and wlan0. A device connected to the Pi's ethernet will get an IP address from the Pi, not the WiFi, but will still have internet access.

I used a jessie light image but it should work with any... The only package that is needed is dnsmasq however from a clean install it is a good idea to make sure everything is up-to-date:

Code: Select all

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get install rpi-update dnsmasq -y
sudo rpi-update
Reboot before continuing.

Connect to WiFi
First, setup the wifi connection that will be bridged to the ethernet.

Code: Select all

sudo nano  /etc/wpa_supplicant/wpa_supplicant.conf
Add:

Code: Select all

network={
        ssid="mynetwork"
        psk="secret"
        key_mgmt=WPA-PSK
}
Ethernet Static IP
Next, setup a static ip for the dhcp server.

Code: Select all

sudo nano /etc/network/interfaces
Comment out the existing eth0 line and add:

Code: Select all

#iface eth0 inet manual
allow-hotplug eth0  
iface eth0 inet static  
    address 172.24.1.1
    netmask 255.255.255.0
    network 172.24.1.0
    broadcast 172.24.1.255
dnsmasq setup
Save the old dnsmasq conf file and create a new one.

Code: Select all

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig  
sudo nano /etc/dnsmasq.conf
Add:

Code: Select all

interface=eth0      # Use interface eth0  
listen-address=172.24.1.1 # Explicitly specify the address to listen on  
bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewhere  
server=8.8.8.8       # Forward DNS requests to Google DNS  
domain-needed        # Don't forward short names  
bogus-priv           # Never forward addresses in the non-routed address spaces.  
dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time  
Enable IPv4 forwarding.

Code: Select all

sudo nano /etc/sysctl.conf
Uncomment the following line:

Code: Select all

net.ipv4.ip_forward=1
IP Tables
Add this:

Code: Select all

sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE 
Configure it to load on reboot by first saving it to a file:

Code: Select all

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Then create a 'hook' file with a line to restore the ip tables :

Code: Select all

sudo nano /lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat
Add:

Code: Select all

iptables-restore < /etc/iptables.ipv4.nat
After a reboot you should automatically connect to your wifi and, assuming it has internet access, anything plugged into your Pi's ethernet port will have internet access as well.

Good luck...
Last edited by pathead on Sat Jun 11, 2016 12:27 am, edited 3 times in total.

User avatar
DougieLawson
Posts: 32342
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: How To: Wifi to Ethernet Bridge

Fri Jan 15, 2016 8:21 am

You do NOT need sudo in /etc/rc.local. It's running with root privileges already.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3B*3, 3B+

Please post ALL technical questions on the forum. Do not send private messages.

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

Re: How To: Wifi to Ethernet Bridge

Fri Jan 15, 2016 10:41 pm

Sorry about that! Like I said I am new. I edited the post.

Thank you for the feedback!

pumatrax
Posts: 4
Joined: Thu Dec 24, 2015 6:09 am

Re: How To: Wifi to Ethernet Bridge

Sat Jan 16, 2016 3:40 am

Hi,Ive been trying to get a bridge working for days. There were times were I had it working but after reboot I lost it as sometimes I was able to get it to work by removing and adding the bridge and bringing interfaces up and down..

Sad to say that after a clean install with NOOBs and trying your method which is really all the basics I know that needs be setup, but its still not working. Should I do a clean install with Rasbian Jessie 4.1 image?

pumatrax
Posts: 4
Joined: Thu Dec 24, 2015 6:09 am

Re: How To: Wifi to Ethernet Bridge

Sat Jan 16, 2016 4:05 am

welp! I just finished the clean install and used your settings again and it works. I haven't done an update yet. Big thank you!

User avatar
Quill
Posts: 2
Joined: Sun Jan 17, 2016 12:03 am

Re: How To: Wifi to Ethernet Bridge

Sun Jan 17, 2016 12:25 am

Hi,

I'm a new RPi user and very inexperienced with any of this.

Code: Select all

sudo brctl addif br0 wlan0 eth0 
gives me the result

Code: Select all

can't add wlan0 to bridge br0: Operation not supported
Can you give me any idea what the problem could be?

fubk
Posts: 2
Joined: Mon Jan 25, 2016 9:15 pm

Re: How To: Wifi to Ethernet Bridge

Tue Jan 26, 2016 10:54 pm

I can get this solution to work with only the correct usb wifi dongle. It has to do with the chipsets. Some people were saying it had to do with the older linux kernels but I didn't see any difference.

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

Re: How To: Wifi to Ethernet Bridge

Mon Feb 15, 2016 12:28 am

Thank fubk. This had stopped working for me and you helped me realize it was because I had switched wifi dongles...

Quill, which wifi dongle are you using? I was able to get this working with http://www.amazon.com/Edimax-EW-7811Un- ... 003MTTJOY/

I was unable to get it working with http://www.amazon.com/Cable-Matters-Wir ... 00MXD2T5G/ though.

User avatar
Quill
Posts: 2
Joined: Sun Jan 17, 2016 12:03 am

Re: How To: Wifi to Ethernet Bridge

Thu Apr 21, 2016 6:59 pm

Absolutely forgot about this (and I still haven't got it working)

I'm using the official Raspberry Pi dongle (https://shop.pimoroni.com/collections/r ... ifi-dongle) with BCM43143 chipset

stdavis68
Posts: 1
Joined: Thu May 12, 2016 9:48 pm

Re: How To: Wifi to Ethernet Bridge

Thu May 12, 2016 9:51 pm

Time to bring this back.

I have the Pi3

Running the:

Code: Select all

sudo brctl addif br0 wlan0 eth0 
results in:
can't add wlan0 to bridge br0: Operation not supported

This is with the built in Wi-Fi adapter. Is this a compatibility issue?

User avatar
Yugoslav
Posts: 3
Joined: Wed May 11, 2016 3:29 pm
Location: Yugoslavia

Re: How To: Wifi to Ethernet Bridge

Fri May 13, 2016 9:22 pm

Quill wrote:Hi,

I'm a new RPi user and very inexperienced with any of this.

Code: Select all

sudo brctl addif br0 wlan0 eth0 
gives me the result

Code: Select all

can't add wlan0 to bridge br0: Operation not supported
Can you give me any idea what the problem could be?

Same problem both with integrated Rpi (3) WiFi and with TP-LINK wifi adapter.
An ounce of action is worth a ton of theory.

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

Re: How To: Wifi to Ethernet Bridge

Sat May 14, 2016 8:21 am

Yugoslav wrote:
Quill wrote:Hi,

Code: Select all

can't add wlan0 to bridge br0: Operation not supported
Can you give me any idea what the problem could be?
Same problem both with integrated Rpi (3) WiFi and with TP-LINK wifi adapter.
I think the issue with this setup (and potentially the reason some dongles give you errors) is that it's not supported in the 802.11 (wireless) specifications. The packets going over the wifi connection are likely to get changed (in particular the ethernet address of the source machine).

I first saw this with virtual machines over a bridged wifi network where the dhcp server saw all the virtual machines using the mac address of the host machines wifi dongle.

User avatar
Cancelor
Posts: 751
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: How To: Wifi to Ethernet Bridge

Sat May 14, 2016 11:07 am

Could you enter the following command in a terminal and post the results:-

Code: Select all

netstat -i
This will show if wlan0 is presant.

Are you getting this message when booting or when trying to set up the bridge?
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

epoch1970
Posts: 1465
Joined: Thu May 05, 2016 9:33 am

Re: How To: Wifi to Ethernet Bridge

Sat May 14, 2016 1:16 pm

User mfa298 is correct I'm afraid.
I would be surprised if bridging the wireless interface in client mode actually works.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

miguej
Posts: 7
Joined: Fri May 27, 2016 7:37 pm

Re: How To: Wifi to Ethernet Bridge

Fri May 27, 2016 7:48 pm

Ok,

I'm trying create the bridge on a raspy B ...
It seems to work (no problem using addif etc etc)..but anyway I'll tell you.

Raspbian Jessie kernel 4.4.9+
Wifi Adapter-> 0bda:8179 Realtek Semiconductor Corp. ( driver r8188eu )

my /etc/network/interfaces -->

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

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

iface wifiathome inet static
    address 192.168.0.9
    netmask 255.255.255.0
    gateway 192.168.0.1
    dns-nameservers 8.8.8.8 8.8.4.4
Now...

ifconfig PREVIOUS to create bridge

Code: Select all

eth0      Link encap:Ethernet  HWaddr b8:27:eb:92:e8:49  
          inet6 addr: fe80::ca66:f12:95bd:e886/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:144 errors:0 dropped:0 overruns:0 frame:0
          TX packets:144 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:11900 (11.6 KiB)  TX bytes:11900 (11.6 KiB)

wlan0     Link encap:Ethernet  HWaddr e8:94:f6:23:56:7b  
          inet addr:192.168.0.9  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ea94:f6ff:fe23:567b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:783 errors:0 dropped:90 overruns:0 frame:0
          TX packets:434 errors:0 dropped:2 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:163529 (159.6 KiB)  TX bytes:105964 (103.4 KiB)
So...let's go!

sudo brctl addbr br0
sudo brctl addif br0 wlan0 eth0


and now...

Code: Select all

br0       Link encap:Ethernet  HWaddr b8:27:eb:92:e8:49  
          inet addr:169.254.155.71  Bcast:169.254.255.255  Mask:255.255.0.0
          inet6 addr: fe80::fea8:1882:688d:457f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:32 errors:0 dropped:0 overruns:0 frame:0
          TX packets:45 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2120 (2.0 KiB)  TX bytes:11694 (11.4 KiB)

eth0      Link encap:Ethernet  HWaddr b8:27:eb:92:e8:49  
          inet6 addr: fe80::ca66:f12:95bd:e886/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:144 errors:0 dropped:0 overruns:0 frame:0
          TX packets:144 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:11900 (11.6 KiB)  TX bytes:11900 (11.6 KiB)

wlan0     Link encap:Ethernet  HWaddr e8:94:f6:23:56:7b  
          inet addr:192.168.0.9  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ea94:f6ff:fe23:567b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1061 errors:0 dropped:102 overruns:0 frame:0
          TX packets:594 errors:0 dropped:2 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:212376 (207.3 KiB)  TX bytes:135818 (132.6 KiB)
And....it seems not to work...

What should I do now? Any Ideas?

Thanks for reading till here ^_^

epoch1970
Posts: 1465
Joined: Thu May 05, 2016 9:33 am

Re: How To: Wifi to Ethernet Bridge

Sat May 28, 2016 2:00 am

The bridge doesn't have an address on the network, it has an ipv4ll (auto-ip, APIPA address).
wlan0 has got the address. It should not have one anymore.
This attempt is futile. Bridging wlan in client mode is not allowed by the wifi standard.
Only if the interface is in AP mode, meaning use hostapd.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

tylernt
Posts: 3
Joined: Mon Aug 19, 2013 11:37 pm

Re: How To: Wifi to Ethernet Bridge

Wed Jun 08, 2016 7:22 pm

For those of you not wanting to use hostapd but still wanting to pseudo-bridge a WLAN client to the LAN, there's another way: Proxy ARP!

https://wiki.debian.org/BridgeNetworkCo ... nsProxyArp

Proxy ARP is Layer 3 rather than Layer 2, but "most" things will work just fine. The notable exception to this is DHCP, but as the above link notes you can use a DHCP helper or simply deploy another DHCP server on the other side of the pseudo-bridge (perhaps using the Pi itself as said DHCP server).

User avatar
Cancelor
Posts: 751
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: How To: Wifi to Ethernet Bridge

Thu Jun 09, 2016 12:56 pm

tylernt wrote:For those of you not wanting to use hostapd but still wanting to pseudo-bridge a WLAN client to the LAN, there's another way: Proxy ARP!

https://wiki.debian.org/BridgeNetworkCo ... nsProxyArp

Proxy ARP is Layer 3 rather than Layer 2, but "most" things will work just fine. The notable exception to this is DHCP, but as the above link notes you can use a DHCP helper or simply deploy another DHCP server on the other side of the pseudo-bridge (perhaps using the Pi itself as said DHCP server).
Yey Yah! debian.org refuring to the RPi :P
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

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

Re: How To: Wifi to Ethernet Bridge

Sat Jun 11, 2016 12:24 am

Updated post to a different method that will work on a Raspberry Pi 3 with the built in WiFi...

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

Re: How To: Wifi to Ethernet Bridge

Sat Jun 11, 2016 7:36 am

pathead wrote:Updated post to a different method that will work on a Raspberry Pi 3 with the built in WiFi...
I'm not sure that such a major change to the original post is a great idea as it makes all the following posts confusing. At the very least you should probably have stuck an obvious comment in there to say that it's been totally re-written. A better approach might have been to but the details in a new post and then stick a comment at the top of the first post saying you've provided new instruction with a link to the new post.

As for some comments on the updated post:
  • You shouldn't need to run rpi-update. The latest stable firmware package is provided via apt-get upgrade. rpi-update gives you a testing firmware which may be broken.
  • If setting static IP in /etc/network/interfaces you need to disable dhcpcd for that interface. A better approach might be putting the static IP settings into /etc/dhcpcd.conf
  • There's an iptables-persistent package that handles loading the iptables config at boot which may be better than using dhcpcd (however your method is much better than just putting an entry in rc.local)
  • It might be worth commenting that 172.24.1 is part of the private address space as lots of people won't know that (most people only know about the 192.168/16 and 10/8 private ranges).

User avatar
Cancelor
Posts: 751
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: How To: Wifi to Ethernet Bridge

Sat Jun 11, 2016 9:58 pm

pathead wrote:Updated post to a different method that will work on a Raspberry Pi 3 with the built in WiFi...
WOOT WOOT, many thanks pathead.
Jessie has made so many guides and tutorials non functional.
I wish more ppl would update their threads.
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

User avatar
Cancelor
Posts: 751
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: How To: Wifi to Ethernet Bridge

Thu Jun 16, 2016 6:21 pm

pathead wrote:Updated post to a different method that will work on a Raspberry Pi 3 with the built in WiFi...
Is this now a routing solution instead of a bridging solution?
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

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

Re: How To: Wifi to Ethernet Bridge

Thu Jun 16, 2016 6:46 pm

Cancelor wrote:
pathead wrote:Updated post to a different method that will work on a Raspberry Pi 3 with the built in WiFi...
Is this now a routing solution instead of a bridging solution?
Yes!
Although bridging solutions with wlan client to Ethernet aren't really supported by the wifi protocols so have issues (if they work at all)

eddiez
Posts: 1
Joined: Wed Aug 31, 2016 4:22 pm

Re: How To: Wifi to Ethernet Bridge(Updated for RPi 3)

Wed Aug 31, 2016 4:32 pm

Hi guys,

I got the bridge working on the RPi 3 according to the original (updated) post. But I did not realize that this might interfere with other things... I'm not sure but I think this is now forwarding all traffic from the wlan0 to the eth0 therefore rendering the samba and ssh useless. I can't get the RPi to respond to ping anymore (from wlan0) and I assume that the reason is that it is being forwarded.

Do you think this is what happened and if so, how do I fix this? The RPi is supposed to share the internet connection to a digibox but I would like to still ssh to the RPi as it is a headless setup.

regisin
Posts: 5
Joined: Thu Jul 28, 2016 3:23 am

Re: How To: Wifi to Ethernet Bridge(Updated for RPi 3)

Sun Sep 04, 2016 3:29 am

Hey there.

I followed the original updated post as it is right now. I got the dns server and the wifi connection working but I wasn't able to make the "bridging". I connect my laptop to the ethernet cable, I get the IP address, but cannot ping even google.

The WiFi in question uses WPA2 Enterprise, not sure if should matter though. Is there a way to debug to see what's going on?

UPDATE: nevermind, my mistake, keyboard was in another language so got a lot of typos along the way.. sorry.

Return to “Networking and servers”

Who is online

Users browsing this forum: No registered users and 3 guests