Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|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 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

4 Answers 4

up vote 21 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
share|improve this answer
    
My wireless was trying to connect again and again and it was starting to be really irritating. Thanks for this script, it finally stopped asking me for a network password. Will the script be automatically started when I reboot my computer ? –  joellord Sep 20 '12 at 12:43
1  
@joellord: This script is automatically run every time a network interface starts or stops. When you disconnect eth0, your wireless gets enabled. When you connect eth0, your wireless gets disabled. –  phord Nov 28 '12 at 16:05
    
What does 99 in the file name mean? –  day Apr 25 at 15:41
    
The scripts in that directory are executed in lexical order, so it is common to prefix the filenames with a number to control the order of execution. –  falloutboy Apr 25 at 19:48

Quite simply for the gnome GUI approach...

  1. Right click on the network system indicator in the gnome panel up by your clock. (The indicator will be one of two icons; either the up/down arrows (LAN) or the traditional WiFi Funnel. Note that the up/down icon will appear when both LAN & WiFi or only LAN are connected and the WiFi funnel appears when connected via WiFi ONLY. (LAN Disconnected)) -- [LAN trumps WiFi automatically.*]

  2. Select 'Edit Connections...'

  3. Select the 'Wireless' tab.
  4. Double click the first connection in your list and Uncheck the 'Connect automatically' box.
  5. Click the 'Apply...' button.
  6. Repeat for each connection in the list.

This will leave the Wireless network operational for on-the-fly manual connections and disconnections available by left clicking the network icon, without the NM trying to Automatically connect you all the time.

Naturally you could also disable/enable Wireless by right clicking the network icon and then left clicking on the "Enable Wireless' selection, effectively bringing down or up the Wireless interface as indicated by the presence or absence of the check mark.

  • LAN trumps WiFi automatically, there is no need to disable WiFi. Simply unplugging your Ethernet cable will seamlessly transfer the connection to WiFi and you can pick up and move about without any fuss. Likewise, with reconnecting the LAN.
  • While LAN does trump WiFi the NM (Network Manager) will find what you seek should you be on different networks simultaneously and are working both online (WiFi) and with a local host (LAN) or V/V for example.
share|improve this answer

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.

share|improve this answer

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

share|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

Your Answer

 
discard

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.