2

after reading this answer for how to setup dynamic network failover I am having a question. First of all thanks a lot to @Ingo posting this manual how to setup bonding/dynamic network failover. It was very easy to setup and works fine for me if my ethernet and wlan network IP address are the same!

However, if my wifi connection is a phone/cellular hotspot that uses a different internet IP address (for example 172.20.10.2 instead of 192.168.2.105 on the ethernet connection), the failover is not working! It looks to me like the bonding interface sticks with the old 192.168.2.105 IP address and then the new connection on the wifi does not work. Do you have any idea what could be the reason?

I have tried to setup the ethernet and wifi interface with static ips, however that didn't help. The bonding interface (still on DHCP) sticks with the IP address from the ethernet interface, even though that one is down.

Any help is appreciated!!

Darksta
  • 25
  • 1
  • 6

2 Answers2

2

The goal of bonding is that the ip address on an interface does not change no matter what connection is used. The interface is connected to a subnet with a defined ip address range. It can only direct connect to devices on the same subnet. If it want to connect to devices on other subnets there is a router needed that sends packets from one subnet to the next.

Your internet router uses subnet 192.168.2.0/24 and the DHCP server on this subnet gives ip address 192.168.2.105 to the RasPi. The cell phone uses subnet 172.16.0.0/12 and the DHCP server on this subnet gives ip address 172.20.10.2 to the RasPi. With DHCP enabled on the RasPi you will get different ip addresses on the bond0 interface. That breaks bonding by definition.

First of all you have to determine what subnet to use, maybe that private subnet from the cell phone 172.16.0.0/12. Then you can give bond0 a static ip address, e.g. 172.20.10.200/12. Now you have to configure the internet router for the wired connection to use the same subnet so all devices are on this subnet.

But as you see, a cell phone is a device for personal use and not very suitable to improve stability of a network.

Ingo
  • 42,961
  • 20
  • 87
  • 207
1

The simple answer is that you can't use that as a failover for existing connections.

If you have short connections or can reconnect after a failure, the next connection will use the other interface. But an existing connection is always tied to a specific IP address pair.

Even if you could convince the kernel to move the connection to the other local address, it wouldn't work because the other end doesn't expect packets for the connection to suddenly come from a different IP address.

IPv6 has some support for failover, and you can do something similar with IPv4, but both sides must support it, so you can't use that for standard connections.

If you really want a failover for existing connections, you can set up two links to a server configured to allow that. All connections to the outside will seem to come from this server.

RalfFriedl
  • 2,180
  • 2
  • 11
  • 12