emw
Posts: 44
Joined: Tue Apr 12, 2016 2:53 pm

how to automatically disable wifi when wired connection is present (stretch).

Fri Nov 24, 2017 6:54 pm

How do you automatically disable wifi when a wired connection is present (stretch)? I know there are a lot of articles about this, but they don't seem to work for stretch.

sora03
Posts: 193
Joined: Mon Dec 29, 2014 4:11 pm
Contact: Website

Re: how to automatically disable wifi when wired connection is present (stretch).

Sat Nov 25, 2017 5:48 am

you can write a script (python or bash or whatever you want) to detect if the ethernet has an IP address (indicates connection) then disable wifi via putting interface down or rf-kill)

example:
sudo ifconfig -a (ip -a in stretch) to get network interfaces name (ens32,eth0,wlan0)
the script to detect if eth has IP address (therefore is connected to a wired network (bash script)

Code: Select all

#!/bin/bash
    if ifconfig eth0 | grep -q "inet 192.168.XXX.XXX"  ; then #change 192.168.XXX.XXX to your IP address when connected to wired 
      echo "ETH connection is up"
      #put code to disable wifi here
       sleep 5
     else
       echo "ETH connection is down"
       #put code to renable wlan and connect to some AP

     fi
FLOSS enthusiast, Debian user (linux-libre)

emw
Posts: 44
Joined: Tue Apr 12, 2016 2:53 pm

Re: how to automatically disable wifi when wired connection is present (stretch).

Mon Nov 27, 2017 6:33 pm

But how do you get the script to trigger when a cable is plugged in / unplugged (or actually when a connection is made / lost) ?

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: how to automatically disable wifi when wired connection is present (stretch).

Mon Nov 27, 2017 9:44 pm

Isn't this what 'ifplugd' (or something like that) is for?

And isn't it installed and active by default?
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

emw
Posts: 44
Joined: Tue Apr 12, 2016 2:53 pm

Re: how to automatically disable wifi when wired connection is present (stretch).

Tue Nov 28, 2017 6:14 pm

ifplugd was not installed by default for stretch. I also thought it relied on ifup and ifdown which don't work on stretch. It looks like you can replace the ifup and ifdown in the script. So to it looks like I can still install and use use ifplugd or netplug. It also looks like I could do it with dhcpcd which Is (for other reasons) the way I think I will do it.

Return to “Beginners”