2

My PC (Ubuntu 16.04) is connected to the home network by an Ethernet cable. I want to move to another room and use Wifi. I want to switch over as seamlessly as possible (to avoid VPN disconnection, for instance). I can connect to both the Wifi and Ethernet, but if at that point I disconnect the Ethernet applications receive a connection error.

So I think I need a way to force the traffic to use the Wifi interface before disconnecting the wire. With both interfaces active, ip route says:

default via 192.168.0.254 dev enp0s31f6  proto static  metric 100 
default via 192.168.0.254 dev wlp4s0  proto static  metric 600 
192.168.0.0/24 dev enp0s31f6  proto kernel  scope link  src 192.168.0.43  metric 100 
192.168.0.0/24 dev wlp4s0  proto kernel  scope link  src 192.168.0.7  metric 600 

If I use:

ip route del default via 192.168.0.254 dev enp0s31f6 

traffic goes to a crawl.

So I think I have to be a bit more subtle and keep both interfaces active for a while, but make the Wifi one the preferred one. I believe this is accomplished by having a smaller metric on the Wifi interface than on the Ethernet one. However, if I do:

ip route change default via 192.168.0.254 dev enp0s31f6 proto static metric 600

I get:

default via 192.168.0.254 dev enp0s31f6  proto static  metric 100 
default via 192.168.0.254 dev enp0s31f6  proto static  metric 600 

So the command seems to replace whatever interface has the given metric. And if I try to use any other metric value than 100 or 600, I get:

RTNETLINK answers: No such file or directory

Of course, if I am on Wifi and reconnect to the Ethernet, the traffic switches seamlessly to it...

So, which of my assumptions are wrong? Is there a solution?

xenoid
  • 8,648
  • 1
  • 24
  • 47

2 Answers2

0

You should bleed out the ethernet interface. You can do that with the help of iptables and advanced routing. With

iptables -m conntrack --ctstate NEW

you can find new connections in your OUTPUT chain and mark them with --set-mark.

The you can use ip rule for routing the packets with this mark over the WiFi.

After a while all or at least most of your traffic will use the WiFi without experiencing any interruption.

If you control the router then you can probably even save connections which last forever using SNAT.

Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
0

The solution mentioned by Hauke would be one way to go. The drawback of this approach would be that you have to keep the (wired) ethernet interface plugged until all connections »blead out«.

Another, more smooth but also a bit more elaborate approach (e.g. I don't now whether you can achieve this using NetworkManager, which your route-metrics suggests you are using), would be to use bonding to bond the interfaces together. In this way, when unplugging your wired ethernet connection, the connections would fail-over to using WiFi automagically.

I already gave a more detailed explanation how to configure bonding for WiFi and wired connections in my answer to Using WiFi port as redundant link.

Andreas Wiese
  • 10,112
  • 1
  • 32
  • 38
  • NM supports bonding, so I'll try that. Still surprised that the switchover is automatic only in one direction. – xenoid Sep 05 '17 at 06:03