Disable Wifi when I plug in ethernet cable

Hi.

If you run the route -n command, you’ll see a column called metric. That is the priority of the interface, which is zero for both eth0 and wlan0. Zero is the highest priority, so, you’d want to give wlan0 a value of, say, 10. (Higher number = lower priority)

Here’s an example:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 eth0
8.8.4.4         192.168.11.1    255.255.255.255 UGH   0      0        0 wlan0
8.8.8.8         192.168.11.1    255.255.255.255 UGH   0      0        0 wlan0
10.8.0.0        0.0.0.0         255.255.255.0   U     0      0        0 tun0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
192.168.11.1    0.0.0.0         255.255.255.255 UH    0      0        0 wlan0
192.168.11.1    0.0.0.0         255.255.255.255 UH    0      0        0 eth0

There’s a command ifmetric that you can install to change the metric. It’s very simple to run:

osmc@osmc:~$ sudo ifmetric wlan0 10
osmc@osmc:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 eth0
8.8.4.4         192.168.11.1    255.255.255.255 UGH   10     0        0 wlan0
8.8.8.8         192.168.11.1    255.255.255.255 UGH   10     0        0 wlan0
10.8.0.0        0.0.0.0         255.255.255.0   U     0      0        0 tun0
192.168.11.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     10     0        0 wlan0
192.168.11.1    0.0.0.0         255.255.255.255 UH    0      0        0 eth0
192.168.11.1    0.0.0.0         255.255.255.255 UH    10     0        0 wlan0

The changes are lost after a reboot, so you’ll need to find some way to run it at startup. Using /etc/rc.local will unfortunately run too early, so it should be something that runs once networking is up.

1 Like