The question says it all. All i want is that my W-Lan connection should be disabled whenever a wired connection is available. What would be the easiest way to do that in Ubuntu/Gnome?

In all guides (for instance some about guessnet) i found i had to configure my whole network configuration (WPA keys, DHCP, ...), but i find that a bit too complicated for such a simple use case. I just want to disable wlan0 when eth0 is connected.

link|improve this question

The answer for this question varies from computer to computer. I don't know if Ubuntu allows this, but typically I've found it's an option in the BIOS. – Iszi Rory or Isznti Jan 14 '11 at 23:27
I don't mean completely disable the wlan, i mean disable Ubuntu to try to connect to any wlans if a wired connection is available. So it is an OS thing. – ifischer Jan 14 '11 at 23:37
feedback

3 Answers

up vote 3 down vote accepted

You can drop this script to /etc/NetworkManager/dispatcher.d/99-wlan:

#!/bin/bash

if [ "$1" = "eth0" ]; then
    case "$2" in
        up)
            nmcli nm wifi off
            ;;
        down)
            nmcli nm wifi on
            ;;
    esac
fi

Don't forget afterwards:

chmod +x /etc/NetworkManager/dispatcher.d/99-wlan
link|improve this answer
feedback

Just a guess but i assume ifplugd could help. You could make it shut down wifi when cable is used.

link|improve this answer
Thanks, i already read about that. What i don't like about ifplugd is that i have to put all my network settings into /etc/network/interfaces. I'm not very good at networking stuff, so i wonder where i could get all the needed values out of my existing connections? Still hope that there is a simpler solution. – ifischer Jan 15 '11 at 11:22
feedback

Create two simple 'scripts', the name of the script is not important (I simply use wlan) and I assume there is only one cabled network interface, and is thus called 'eth0'... Check this with 'ifconfig' if you're not sure. Note that this disabled wireless entirely, not just wlan0. (Only an issue if you have multiple wlan interfaces and only want to disable specific ones)

These scripts could easily be adapted - by boolean logic - to a situation in which you have two or more cabled network interfaces.

Make sure these scripts are executable with 'chmod +x'

/etc/network/ip-up.d/wlan

#!/bin/sh
# If eth0 goes up, disable wireless
if [ "$IFACE" = "eth0" ]; then
  dbus-send --system --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.DBus.Properties.Set string:org.freedesktop.NetworkManager string:WirelessEnabled variant:boolean:false
fi

/etc/network/if-down.d/wlan

#!/bin/sh
# If eth0 goes down, enable wireless
if [ "$IFACE" = "eth0" ]; then
  dbus-send --system --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.DBus.Properties.Set string:org.freedesktop.NetworkManager string:WirelessEnabled variant:boolean:true
fi

This enables/disables wireless in the NetworkManager that can usually be found as an system indicator in the Gnome panel.

You could also use 'ifconfig wlan0 down' or 'ifconfig wlan0 up' instead of the dbus-send line, but this should be more user-friendly and interfere less with Ubuntu's system utilities.

Tested with Ubuntu Desktop 10.10, and should work with earlier versions or other distributions using NetworkManager and dbus.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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