Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My HTPC has a wireless and a wired connection. When I start ubuntu both get an IP-adress. I don't see any inherent problem with this, but XBMC seems to default to the wireless, even if the wired is available.

How can I force precedence of the wired connection above the wireless?

  • I'm not looking to shutdown/disable the wireless: I do use both, but not at the same time per se.
  • There shouldn't be any interaction for this, as I don't have a keyboard connected. Currently I ssh to the box to shut down wireless manually if needed, but that's ridiculous :)

Basically what I expected was that when the wired connection gets an IP, the wireless releases it's connection, and as soon as the wired IP is gone, wireless comes in again. But that doesn't seem to happen :(

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

You can create a script and put it in the /etc/NetworkManager/dispatcher.d folder; the scripts in that folder will be executed every time a connection is (dis)established. The number with which you start the filename determines the order of execution, so we will give our script the number 99 to make sure that it is executed last.

Run the following command in a terminal

gksudo gedit /etc/NetworkManager/dispatcher.d/99-wlan

then copy the following, save and close.

#!/bin/bash

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

you should replace "eth0" with your network device (e.g., the one you see when you type ifconfig. it could be "eth1" for instance).

Make the script executable by running

sudo chmod +x /etc/NetworkManager/dispatcher.d/99-wlan

Now if a wired connection is established the wireless will be turned off, if the wired connection is disestablished the wireless will be turned back on.


Acknowledgment: credit to this superuser answer,

share|improve this answer
add comment

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.