How do I configure a linux machine to ignore wifi when connected via LAN?

My laptop is set to automatically connect to my campus wifi network, which is desirable under most circumstances. However, in my office, the signal is quite poor, so I rely on a wired connection. Unfortunately, my machine tries to make both connections. There are two problems:

  1. This wifi connection is terrible, and traffic seems to go through that even when I have an ethernet cable.
  2. Connecting to wifi in general requires password entry to unlock my keyring.

I think I can take care of problem 1 using this question, but problem 2 would best be solved by not trying to make the connection in the first place. Any recommendations for that?


You need to configure the metric of the interface, which defines the "delay" or "slowness".

First, install the ifmetric program for your distribution, which allows you to easily change the metric for an interface.

Next, you want to edit your /etc/network/interfaces to call ifmetric when the networking interfaces are connected:

iface eth0 inet dhcp
    up ifmetric eth0 10

iface wlan0 inet dhcp
    up ifmetric wlan0 20

(I'm assuming that eth0 is the wired interface here, and wlan0 is the wireless interface. You might have other lines around the iface line, the key part that you want to add is the

    up ifmetric wlan0 20

part. This tells the system that it should assume that the wlan0 interface is twice as slow as the eth0 interface. This will cause your system to use the wired interface if it is connected, but automatically fall back to the wireless interface.

Depending upon your distribution, there might be a GUI tool to configure this much more easily (such as NetworkManager in the Ubuntu distribution)


If your computer has hardware switch to disable/enable WiFi card you can shut it down while you are in the office.

If your computer does not have a switch, you can shut wireless interface down. By doing:

ifconfig wlan0 down

Where wlan0 is name of the wireless interface.

Once you are out of the office you will turn it back on:

ifconfig wlan0 up

You can obtain list of network interfaces by issuing following command:

ifconfig -a

That should solve your problem.