3

Edit2: Original post, look below for an Update.

I have a Raspberry Pi 4 that is both connected to a wireless LAN with an internet connection and a router that connects a different local network. The wired connection needs a static IP address while the wireless IP address is given by dhcp. The setup can be found in the following picture. enter image description here

What I am trying to do is to recieve a message from the internet and send it to a computer that is part of the wired LAN. I do this with a python script. For this porpuse both connections have to work at the same time. But it turns out that I can only use either the wireless LAN that has a connection to the internet or the wired local network. I did some research on this problem with no solution yet. But I am assuming that I have add some more information to the routing table of the raspi. Other posts on similar problems said that it had to do with "bridging" eth0 and wlan0. Sorry I am a newbie on this and I would really appreciate your help.

Edit: Posting output of ip a && ip r

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:f8:43:f0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.67.217/24 brd 192.168.67.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::1a14:a884:9c52:6e39/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether dc:a6:32:f8:43:f2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.66.177/24 brd 192.168.66.255 scope global noprefixroute wlan0
       valid_lft forever preferred_lft forever
    inet6 fe80::bb1c:f878:ee9b:ae5a/64 scope link 
       valid_lft forever preferred_lft forever
default via 192.168.67.10 dev eth0 src 192.168.67.217 metric 202 
default via 192.168.66.160 dev wlan0 src 192.168.66.177 metric 303 
192.168.66.0/24 dev wlan0 proto dhcp scope link src 192.168.66.177 metric 303 
192.168.67.0/24 dev eth0 proto dhcp scope link src 192.168.67.217 metric 202 

Edit2: More detailed descritption of my problem.

So it seems like I did not describe my problem clearly enough, so here is another try.

I am running a Raspberry Pi that runs a python script that is supposed to receive a measured value from an MQTT-Broker (test.mosquitto.org). The same python script is supposed to connect to a DDC-device (via BACnet) in order to write the measured value that was received by the MQTT-Broker into a BACnet-Object that is part of the DDC-device.

To do all of this the raspi needs to be connected to the local (wired) network (where the DDC-device is connected) with a static IP, because the python script requires this. The local network does not have access to the internet. At the same time the raspi needs an internet connection to connect to the MQTT-broker (test.mosquitto.org). This is established via a wireless connection to another network. Here I can choose between dhcp an a static IP. At the moment I am using a static IP both in the wireless an wired network.

The detailed setup of the network can be found below:

enter image description here

Don't get confused by all the VPN-stuff that is goint on here. This part of the network works just fine. I know this, because I have run the python script (that is suppossed to run on the raspi) on a windows laptop and everything is working. The value can be written or sent to the DDC-device without any problems, while the laptop receives the value from the MQTT-broker.

I the static IPs and the router-IPs for eth0 and wlan0 on the GUI of raspbian "Wireless & Wired Network Settings". I did not use command lines to do that.

Both connections work just fine, when only one is active at a time. But when I am activating both connections, only the eth0 is working. I do not have access to the internet.

As I managed to make the python script run on a windows-laptop I assume that there is a setting that the raspi is missing that tells it when to use the eth0 and when wlan0. Does this have anything to do with the routing table? Is there a way to tell the raspi to send every request to both eth0 and wlan0? Or ist there a way to tell the raspi that for connections to test.mosquitto.org it is supposed to use only wlan0?

5
  • post the output of ip a && ip r
    – Milliways
    Commented May 14, 2021 at 11:21
  • Sure! (I edited it into the original post.)
    – David
    Commented May 14, 2021 at 11:29
  • You have 2 default routes so it is unclear what will happen (or what you have actually done). It is also unclear what you are trying to do.
    – Milliways
    Commented May 14, 2021 at 11:37
  • I added some more information. I hope that it is more clear now.
    – David
    Commented May 14, 2021 at 12:09
  • +1 for the drawings. If every user would explain its question like you did, they would receive countless answers.
    – Binar Web
    Commented May 14, 2021 at 13:38

3 Answers 3

1

What you are wanting to achieve is indeed a bridge, but Rpi's lack of built-in Wifi Distribution System (WDS) support means that you have to use a network layer work around. This is more accurately called a "pseudo-bridge."

There are two main approaches you can use. Proxy ARP, and routing with DNAT.

This walkthrough details how you can use either approach to bridge your wlan0 connection to your eth0 connected subnet. The first approach is if you want the bridged device to appear on the same subnet with Proxy ARP. The second approach, which is the most relevant to your situation, utilizes routing and is for the situation where the eth0 adapter and bridged device are assigned static addresses on a different subnet. It has links to several relevant Stack Overflow answers as well that describe these two methods in more detail. The main one I have referenced to solve this exact same problem, using Proxy ARP, being this guide write-up by Ingo.

Proxy ARP has the advantage of devices on the wired subnet being "discoverable" by hosts on the other side of the bridge, as the Rpi performs ARP spoofing to basically tell other hosts on the network that its MAC address corresponds not only to its own dhcp assigned IP, but also to the IP addresses it has assigned to devices on eth0-connected subnet. In the DNAT case, the Pi acts a router for the devices on the wired subnet. They will not be visible to outside hosts, but they will still be able to connect to the internet just like the Pi can.

For example, I am using a Raspberry Pi to bridge an ethernet connected printer. I used the routing approach, and added iptable rules so that the raw print port and http port of the printer are forwarded to the corresponding ports on the Raspberry Pi. On my network, I can use the Pi's IP to access the printer's webpage, and send it print jobs just fine! At the same time, my Raspberry Pi still accepts tcp traffic destined for port 22 so I can still ssh into it for maintenance. In this way both devices can connect to the internet and I can still access specific services/sockets on the printer via forwarding. Without the details I am unsure what type of information you want to send to the eth0-connected machine, but if you have additional questions related to things like port forwarding I'd be happy to provide further details that are more relevant to your situation.

2
  • Thanks for your response. I took a look into the links you provided but I get the impression that the linked guides provide a solution to a different problem. I am sorry if my question was not clear enough. The guides that you provided show how the raspberry can be used to make a pc without a wlan adapter connect to a wireless network. That is not really what I am trying to do here. I try to receive a measured value from an MQTT-broker (test.mosquitto.org) with the raspberry pi and send the value to a device that is part of the wired network. Running out of characters again.. sorry.
    – David
    Commented May 14, 2021 at 10:41
  • Thank you for the additional info, a lot of my answer is not as relevant now, but even still one of the bridging situations is quite similar to your setup and I think could be useful as an example network configuration. In the routing setup, I used both wlan0 and eth0 interfaces simultaneously and the Pi was able to connect seamlessly with both networks because eth0 being assigned an IP on a different subnet made it clear where traffic needed to go. This was the default on my devices using Buster anyway. What OS version are you using? Have you messed with the dhcpcd/interface configs at all?
    – cnrcbr
    Commented May 15, 2021 at 3:57
1

Thank you all for your help. After some trial and error this worked for me:

first I deleted an entry on the routing table that told every traffic to go to the wired router with the IP 192.168.67.10 first.

So now I could use the Wlan but LAN did not work.

Then I entered the following command to change the routing table.

ip route add 192.168.135.0/24 via 192.168.67.10

With this I could communicate with the network as I intended. The command had to be done with admin rights.

Now I could use both connections without problem.

When I restarted the raspi the routing table was reset. So I had to find a way to make the changes permanent.

I changed the metric of the Wlan so that it was preferred over the LAN. After this I made the change to the routing table permanent by adding the above command to /etc/dhcpcd.exit-hook.

Now the system works as desired.

1
  • I'm glad you figured it out! It's easy for small changes to accumulate when messing around with networking so often clearing things out helps. For cases where you would like new iptable rules to persist and not manually add them on boot, you can also use helper programs like iptables-persistent.
    – cnrcbr
    Commented May 15, 2021 at 4:03
0

Your Question is vague, and lacking detail.

It is simple to configure both interfaces to work simultaneously, but the detail depends on exactly you are trying to achieve.

I doubt that "The wired connection needs a static IP address", but leave this and you have not specified WHAT YOU DID to achieve this and most do it incorrectly.

It is most likely that the following would solve your problem:-

Add

interface eth0
nogateway

to the /etc/dhcpcd.conf

See Prevent dhcpcd from configuring a gateway on an interface in How to set up networking/WiFi

1
  • I added the "nogateway" line as you described. Now both the wireless and wired connections are established and I am able to ping the router with the IP 192.168.67.10 but I don't have a connection to the device I am trying to send the message to. The "message" is a measured value that the raspi is supposed to recieve from an MQTT-Broker. The device I want to send the value to is connected via a VPN and has following IP adress: 192.168.135.51. I am running out of characters to be more specific...
    – David
    Commented May 14, 2021 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.