AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

[SOLVED] Bridge wlan0 and eth0 - help needed

Thu Sep 21, 2017 9:55 pm

Hello,

I have some Modbus/TCP devices connected via eth0 to my Raspberry Pi 3 with the up to date Raspbian Jessie Desktop.
I would like to:
1. Make my RPi a wi-fi hotspot in order to be able to connect to the Modbus/TCP devices from my laptop and phone via wi-fi.
The Modbus devices have hard coded IP addresses e.g. 192.168.0.XXX:502 so my network has to be 192.168.0.XXX

2. I would like to be able to update my Pi once in a while and I think the easiest way is to plug the whole eth0 network in to my router and download updates occasionally.

I have tried to follow this guide but was not able to get what I want:
https://www.raspberrypi.org/documentati ... s-point.md

I am wondering if it matters whether I bridge eth0 to wlan0 or wlan0 to eth0. Or maybe there is something missing in the guide?
The problem is is that as soon as I start doing the steps per the guide the network widget on my desktop stops working (does not see any wifi network anymore) which makes it hard to troubleshoot the issues. So I always format the SD, load a fresh raspbian image on it again and start again.
I am looking for help. Any ideas would be greatly appreciated.
Last edited by AndriusWild on Tue Sep 26, 2017 5:17 pm, edited 1 time in total.

User avatar
rpdom
Posts: 12874
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Bridge wlan0 and eth0 - help needed

Fri Sep 22, 2017 5:23 am

It's not so much a case of bridging interface A to interface B. The way the bridging works is that you create a virtual interface (the "bridge", usually called br0) and give it an IP address. Then you add interfaces to the bridge. The order isn't important.

So you don't "bridge eth0 to wlan0" or "bridge wlan0 to eth0" as such, you just "add wlan0 and eth0 to the bridge". You can also have more than two interfaces on a bridge.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Fri Sep 22, 2017 1:06 pm

If you upgrade to Stretch, you will not be able to use the "sudo brctl addif br0 wlan0" command.

I have a fix for Stretch. Post if you upgraded to Stretch on your new install.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Fri Sep 22, 2017 1:30 pm

SurferTim wrote:
Fri Sep 22, 2017 1:06 pm
If you upgrade to Stretch, you will not be able to use the "sudo brctl addif br0 wlan0" command.

I have a fix for Stretch. Post if you upgraded to Stretch on your new install.
Yes, I have upgraded to Stretch.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Fri Sep 22, 2017 1:33 pm

This is the setup I use with Stretch. This is the only time I recommend adding anything to /etc/network/interfaces.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
install hostapd and bridge utilities.

Code: Select all

sudo apt-get install hostapd bridge-utils
sudo systemctl stop hostapd
Create bridge br0.

Code: Select all

sudo brctl addbr br0
Create file /etc/hostapd/hostapd.conf

Code: Select all

interface=wlan0
bridge=br0
#driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd, uncomment and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
Add eth0 to br0

Code: Select all

sudo brctl addif br0 eth0
Edit /etc/network interfaces and add this

Code: Select all

auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0
Edit /etc/dhcpcd.conf and add this above other interfaces

Code: Select all

denyinterfaces eth0 wlan0
reboot

Edit: Don't panic if you get a double red x on the network icon in the upper right corner of the GUI desktop. That is to be expected. Also, you will get a red "failed" message on boot for the dhcpcd service. That is also expected.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sat Sep 23, 2017 7:26 pm

SurferTim wrote:
Fri Sep 22, 2017 1:33 pm
Thank you for posting the solution.
I just did all the steps per your guide.
br0 is up but looks like I need to add a static ip for it in /etc/dhcpcd.conf

wlan0 isn't showing up in ifconfig but wi-fi still working (connected to my router)
network widget showing two X's as you said (not connected to dhcpcd)

I am wondering what parts of the original guide I should do now to make my pi a hotspot.
Do I have to use dnsmasq? Again, I would like to be able to connect to the internet via eth0 in future.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sat Sep 23, 2017 7:54 pm

If you bridge the interfaces as I suggested, you don't need a "hotspot" or dnsmasq. Your router will take care of dhcp for the network.

You can assign a static IP for br0 in /etc/dhcpcd.conf, just like you would for an ethernet interface. Insure the IP is not in the dhcp range that the router's dhcp server will issue.

edit: Any device connected to wlan0 SSID should get an ip issued by the router on eth0.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sat Sep 23, 2017 8:16 pm

SurferTim wrote:
Sat Sep 23, 2017 7:54 pm
If you bridge the interfaces as I suggested, you don't need a "hotspot" or dnsmasq. Your router will take care of dhcp for the network.

You can assign a static IP for br0 in /etc/dhcpcd.conf, just like you would for an ethernet interface. Insure the IP is not in the dhcp range that the router's dhcp server will issue.

edit: Any device connected to wlan0 SSID should get an ip issued by the router on eth0.
In future I would like to disconnect from the router and make a standalone network managed by Raspbery Pi.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sat Sep 23, 2017 8:19 pm

Then you will need to remove the bridge and set up the wlan0 interface as an AP. In that case, you will need dnsmasq.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sat Sep 23, 2017 8:43 pm

SurferTim wrote:
Sat Sep 23, 2017 8:19 pm
Then you will need to remove the bridge and set up the wlan0 interface as an AP. In that case, you will need dnsmasq.
I thought I need the bridge to connect wireless (wlan0) and wired (eth0) devices together...

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sat Sep 23, 2017 9:24 pm

A bridge is one way. The other way is routing with a masquerade. It depends on whether you want the clients on each side of the RPi to access each other.

With a bridge, the clients on both sides of the RPi can access all the other clients.

With the routing and masquerade, the wlan0 clients can access the eth0 clients, but the eth0 clients cannot access the wifi clients.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 1:45 pm

SurferTim wrote:
Sat Sep 23, 2017 9:24 pm
A bridge is one way. The other way is routing with a masquerade. It depends on whether you want the clients on each side of the RPi to access each other.

With a bridge, the clients on both sides of the RPi can access all the other clients.

With the routing and masquerade, the wlan0 clients can access the eth0 clients, but the eth0 clients cannot access the wifi clients.
I would definitely need a bridge (which I already have). I am going to try to setup a wireless AP per the first part of the guide and wil post results here.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 1:46 pm

If you are using Stretch, the only way you can set up a bridge with ethernet and wireless is with an AP using hostapd.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:01 pm

SurferTim wrote:
Sun Sep 24, 2017 1:46 pm
If you are using Stretch, the only way you can set up a bridge with ethernet and wireless is with an AP using hostapd.
doing it right now.

Code: Select all

sudo service dhcpcd restart
Job for dhcpcd.service failed because the control process exited with error code.
See "systemctl status dhcpcd.service" and "journalctl -xe" for details.

Code: Select all

sudo ifdown wlan0
ifdown: interface wlan0 not configured
i think i am going to lose the internet connection after starting dnsmasq and hostapd

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:04 pm

AndriusWild wrote: i think i am going to lose the internet connection after starting dnsmasq and hostapd
No. From my post above:
Edit: Don't panic if you get a double red x on the network icon in the upper right corner of the GUI desktop. That is to be expected. Also, you will get a red "failed" message on boot for the dhcpcd service. That is also expected.
Edit: Run ifconfig. You should see that br0 now has the IP address.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:10 pm

I just finished setting up AP per the guide but looks like it did not work. My Pi still connected wirelessly to my router and my network per /etc/hostapd/hostapd.conf cannot be discovered.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:12 pm

AndriusWild wrote:
Sun Sep 24, 2017 2:10 pm
I just finished setting up AP per the guide but looks like it did not work. My Pi still connected wirelessly to my router and my network per /etc/hostapd/hostapd.conf cannot be discovered.

Code: Select all

ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.70  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ba27:ebff:feef:58d1  prefixlen 64  scopeid 0x20<link>
        inet6 2001:56a:7786:bd00:ba27:ebff:feef:58d1  prefixlen 64  scopeid 0x0<global>
        ether b8:27:eb:ef:58:d1  txqueuelen 1000  (Ethernet)
        RX packets 35  bytes 6697 (6.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 60  bytes 8648 (8.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether b8:27:eb:ef:58:d1  txqueuelen 1000  (Ethernet)
        RX packets 46  bytes 10857 (10.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 60  bytes 9228 (9.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 166  bytes 13482 (13.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 166  bytes 13482 (13.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.0.1  netmask 255.255.255.0  broadcast 192.168.0.255
        ether b8:27:eb:ba:0d:84  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
wlan0 does show up in ifconfig now but Pi is not broadcasting

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:12 pm

Check /etc/wpa_supplicant/wpa_supplicant.conf. Remove any network stuff there. Leave the top few lines in that file.
Reboot.

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:40 pm

Here is the output of my ifconfig with the bridge:

Code: Select all

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.245  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ba27:ebff:fe24:cc6  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:24:0c:c6  txqueuelen 1000  (Ethernet)
        RX packets 45  bytes 4564 (4.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 46  bytes 5927 (5.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether b8:27:eb:24:0c:c6  txqueuelen 1000  (Ethernet)
        RX packets 149730  bytes 221607283 (211.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40654  bytes 3250344 (3.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 2  bytes 78 (78.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2  bytes 78 (78.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether b8:27:eb:71:59:93  txqueuelen 1000  (Ethernet)
        RX packets 40610  bytes 2350837 (2.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 149720  bytes 227299017 (216.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 2:57 pm

SurferTim wrote:
Sun Sep 24, 2017 2:12 pm
Check /etc/wpa_supplicant/wpa_supplicant.conf. Remove any network stuff there. Leave the top few lines in that file.
Reboot.
it did not do the trick. I am still connected to the router ...

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 3:00 pm

What version of Raspbian are you using? I'm using Stretch 2017-09-07.

Check the bridge.

Code: Select all

sudo brctl show
It should show both eth0 and wlan0 on br0.

Insure you follow all the instructions.

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 3:07 pm

SurferTim wrote:
Sun Sep 24, 2017 3:00 pm
What version of Raspbian are you using? I'm using Stretch 2017-09-07.

Check the bridge.

Code: Select all

sudo brctl show
It should show both eth0 and wlan0 on br0.

Insure you follow all the instructions.
I downloaded Raspbian few days ago and did update upgrade and dist-upgrade.

Code: Select all

sudo brctl show
bridge name	bridge id		STP enabled	interfaces
br0		8000.b827ebef58d1	no		eth0

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 3:16 pm

Looks like you messed up the hostapd part.

Code: Select all

sudo service hostapd status
Should say it is active (running).

AndriusWild
Posts: 30
Joined: Thu Sep 21, 2017 9:10 pm

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 3:34 pm

SurferTim wrote:
Sun Sep 24, 2017 3:16 pm
Looks like you messed up the hostapd part.

Code: Select all

sudo service hostapd status
Should say it is active (running).

Code: Select all

sudo service hostapd status
● hostapd.service - LSB: Advanced IEEE 802.11 management daemon
   Loaded: loaded (/etc/init.d/hostapd; generated; vendor preset: enabled)
   Active: active (exited) since Sun 2017-09-24 08:53:53 MDT; 36min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 659 ExecStart=/etc/init.d/hostapd start (code=exited, status=0/SUCCES
   CGroup: /system.slice/hostapd.service

Sep 24 08:53:52 Pi systemd[1]: Starting LSB: Advanced IEEE 802.11 management daemon...
Sep 24 08:53:53 Pi hostapd[659]: Starting advanced IEEE 802.11 management: hostapd failed!
Sep 24 08:53:53 Pi systemd[1]: Started LSB: Advanced IEEE 802.11 management daemon.

lines 1-10/10 (END)

SurferTim
Posts: 1764
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Bridge wlan0 and eth0 - help needed

Sun Sep 24, 2017 3:56 pm

Then one or both of these two thing are wrong.
Create file /etc/hostapd/hostapd.conf

Code: Select all

interface=wlan0
bridge=br0
#driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd, uncomment and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Return to “Troubleshooting”