1

I am developing a Debian 8 system that has two network interfaces (one ethernet and one 3G modem) and is supposed to have two simultaneous connections to an MQTT broker i.e. there should be a connection via both interfaces. The language I am using is Python and the MQTT client is Paho.

Supplying Paho's connect-method with argument called bind_address should do extacly what I want. I would just create two instances of Paho and give them the IP addresses of my two interfaces.

The problem is that only one of them gets connected.

I have tried pinging the broker IP specifying the interface explicitly (ping -I ifname a.b.c.d) and that works with both interfaces. Also, giving the two instances of Paho the same IP, the one of ethernet, works.

At this point, my guess is that this problem is related to routing, but that's an area I am not very familiar with.

How can I fix this?

Output of ip addr as requested:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    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 pfifo_fast state UP group default qlen 1000
    link/ether 00:04:25:18:e9:a9 brd ff:ff:ff:ff:ff:ff
    inet 82.195.211.80/23 brd 82.195.211.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::204:25ff:fe18:e9a9/64 scope link
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN group default
    link/sit 0.0.0.0 brd 0.0.0.0
    inet6 ::127.0.0.1/96 scope host
       valid_lft forever preferred_lft forever
4: wwan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether 0a:71:b0:b9:ca:39 brd ff:ff:ff:ff:ff:ff
    inet 10.36.124.58/30 brd 10.36.124.59 scope global wwan0
       valid_lft forever preferred_lft forever
    inet6 fe80::871:b0ff:feb9:ca39/64 scope link
       valid_lft forever preferred_lft forever

Output of ip route as requested:

default via 82.195.210.1 dev eth0  metric 202
default via 10.36.124.57 dev wwan0  metric 204
default via 82.195.210.1 dev eth0  proto static  metric 1024
10.36.124.56/30 dev wwan0  proto kernel  scope link  src 10.36.124.58  metric 204
10.36.124.58 via 127.0.0.1 dev lo  metric 204
82.195.210.0/23 dev eth0  proto kernel  scope link  src 82.195.211.80  metric 202
82.195.211.80 via 127.0.0.1 dev lo  metric 202
1
  • Some fancy routing, with some fancy IP Tables work, and you may be able to find a way to tag traffic to force it out a specific NIC. You may need to add a socks proxy or something, to convince your local system that you're connecting to two different servers, via two different nics. Mar 9, 2017 at 19:13

1 Answer 1

2

Simple source policy routing would probably solve your problem. Create a new routing table called mobile with an arbitrary unused number (100 here; this is optional, you could just use the number instead):

echo 100 mobile >> /etc/iproute2/rt_tables

Set this table to route towards your 3G gateway:

ip route add default via 10.36.124.57 dev wwan0 table mobile
ip route flush cache

Finally, add the rule for your 3G source address to use the newly setup mobile table:

ip rule add from 10.36.124.58 table mobile

I took the interface name (wwan0) and the addresses from your question. The interface name can be reasonably expected to stay stable (at least until you attach another 3G modem to your computer), but the local and gateway address may change on every connection. You'll probably want to script this setup.

4
  • I am not sure how to deal with the two IPs used in your answer. In my case, the modem interface is wwan0 and if ppp is used, ModemManager is hiding all of that. If there is a gateway that can be referred to the way you suggest, then I don't know how to find out what it is. The only address I know is the source address.
    – TheAG
    Mar 9, 2017 at 9:48
  • Please edit your question to include the output of the ip addr and ip route commands when both your connections are alive. Is your Ethernet connection set up manually or via DHCP? Did you configure ModemManager to not use the 3G connection as a default route? Or does NetworkManager choose automatically from the two gateways? Mar 9, 2017 at 18:43
  • I added the outputs you asked. Ethernet is configured via DHCP, but I may need to configure it manually later. ModemManager is not explicitly instructed to do anything but just to connect the modem. NetworkManager is not explicitly intructed to do anything at all at this point. It is used just for getting information about the interface. One thing that I am little worried about is that NetworkManager doesn't seem to track the state of modem and it's connection correctly even though I though ModemManager and NetworkManager should co-operate to at least some extent.
    – TheAG
    Mar 13, 2017 at 7:16
  • I got the gateway-thing figured out myself and this solution seems to work for me. I have tried it only manually so far, so I still have to make it work from Python code, but that's another challenge and not a topic to be discussed in the context of this question. Thanks for help!
    – TheAG
    Mar 14, 2017 at 13:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .