Wednesday, May 1, 2024
 Popular · Latest · Hot · Upcoming
35
rated 0 times [  35] [ 0]  / answers: 1 / hits: 13558  / 3 Years ago, thu, august 26, 2021, 3:51:37

What's the best way to automatically disable my Wifi/wireless connection whenever I plug in a wired Ethernet cable? I'd like it to be re-enabled when I later unplug the wire.



Also, I sometimes like to share the wired connection with other wireless users (or vice-versa). It'd be nice if I could somehow exempt these setups.



I'm using 11.10 Oneiric, which uses NetworkManager.


More From » networking

 Answers
5

The following script, put in /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired, mostly works—it disables wireless even when I want to share wired with wireless or vice-versa.



To do this, run the following command in terminal:



sudo nano /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired


And paste the following code into the text editor.



#!/bin/sh
myname=${0##*/}
log() { logger -p user.info -t "${myname}[$$]" "$*"; }
IFACE=$1
ACTION=$2

release=$(lsb_release -s -c)
case ${release} in
trusty|utopic) nmobj=nm;;
*) nmobj=radio;;
esac

case ${IFACE} in
eth*|usb*|en*)
case ${ACTION} in
up)
log "disabling wifi radio"
nmcli "${nmobj}" wifi off
;;
down)
log "enabling wifi radio"
nmcli "${nmobj}" wifi on
;;
esac
;;
esac


Then save and exit.



Note the following conditions on the script, as documented in the NetworkManager manual page:




Each script should be:




  • a regular file,

  • owned by root,

  • not writable by group or other,

  • not set-uid,

  • and executable by the owner.




Instead of nmcli radio wifi off (or nmcli nm wifi off for older
versions of NetworkManager), there is also rfkill block wifi.
However, if rfkill is used instead of nmcli, newer versions of
NetworkManager will turn wifi back on during boot.


[#39855] Friday, August 27, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tialmes

Total Points: 14
Total Questions: 108
Total Answers: 102

Location: Oman
Member since Thu, Jun 16, 2022
2 Years ago
;