This question already has an answer here:

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 dev enp0s31f6  proto static  metric 100 
default via dev wlp4s0  proto static  metric 600 dev enp0s31f6  proto kernel  scope link  src  metric 100 dev wlp4s0  proto kernel  scope link  src  metric 600 

If I use:

ip route del default via 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 dev enp0s31f6 proto static metric 600

I get:

default via dev enp0s31f6  proto static  metric 100 
default via 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?

marked as duplicate by Andreas Wiese, Anthon, Rui F Ribeiro, Hauke Laging, derobert Sep 5 '17 at 20:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


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.

  • NM supports bonding, so I'll try that. Still surprised that the switchover is automatic only in one direction. – xenoid Sep 5 '17 at 6:03

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.

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