Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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.

share|improve this question

1 Answer 1

up vote 14 down vote accepted

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.

log() { logger -p -t "${myname}[$$]" "$*"; }

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

case ${IFACE} in
        case ${ACTION} in
                log "disabling wifi radio"
                nmcli "${nmobj}" wifi off
                log "enabling wifi radio"
                nmcli "${nmobj}" wifi on

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.

share|improve this answer
How can the script tell which configuration you want? Why noy just do rfkill unblock wifi after you've connected eth0 and you want to share, then rfkill block wifi when you're done? – waltinator Mar 15 '12 at 1:40
@waltinator: When a connection comes up, NetworkManager sets an environment variable named CONNECTION_UUID to the identifier for that connection. I was thinking that the script could do something like only disable WiFi for the connection that I have declared the "standard" wired connection but leave it enabled if eth0 is activated by a different connection. I haven't tried it so I don't know if it works. But your point about just controlling it manually is a good one. – Richard Hansen Mar 15 '12 at 3:57
Use eth0|usb0) to also disable/enable WiFi when USB tethering is activated/deactivated. – krlmlr Nov 25 '13 at 12:32
Most useful! Instead of using rfkill, I used the commands nmcli nm wifi off and nmcli nm wifi on. But I don't have any particular reason for believing that the nmcli commands are better. I just wanted to do everything the NetworkManager way. – Jesse Hallett Jan 23 '14 at 1:35
syntax correction for those using the nmcli alternative given in the script above: INCORRECT: nmcli nm wifi on CORRECT: nmcli r wifi on The same correction goes for the "off" switch – doublehelix Dec 26 '14 at 20:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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