Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to configure my network interfaces. I would like to make my wireless interface to be disabled when I plug in an Ethernet cable. When I take the Ethernet cable out, my wireless interface should be enabled again.

I have created /etc/network/if-up.d/wlan-down:


[ "$IFACE" != "eth1" ] || exit 0
ifdown wlan0

exit 0

and /etc/network/if-down.d/wlan-up:


[ "$IFACE" != "eth1" ] || exit 0
ifup wlan0
wpa_cli -i wlan0 reassociate

exit 0

but it just doesn't seem to work at all. WPA still tries to connect all the time. I can see wlan0 appears and disappears all the time. My questions are:

  1. How can I debug these scrips, e.g. what happened and what was executed?
  2. What is the correct way to implement what I am after?
  3. Also, it seems that nothing happens when I disconnect the Ethernet cable. The interface is up and the IP address is assigned. I would like to get it down in such a case, so that I could use wireless instead.

I am using Debian unstable

share|improve this question

closed as off-topic by Falcon Momot, mdpc, Dave M, Jenny D, Ward Oct 4 '13 at 1:36

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is a site dedicated to professionals; novice questions are off-topic. Please see the Help Center for more information on topicality. The best advice we can give you is to hire a professional to help you out." – Falcon Momot, mdpc, Dave M, Jenny D, Ward
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

Is this for a desktop system? Have you considered using network manager or wicd. These tools take care a lot of this for you automatically.

How can I debug these scrips, e.g. what happened and what was executed?

You might want to use something like logger to submit debug information to syslog. Or you could simply put in a few echo commands here and there to write things to a file somewhere.

share|improve this answer
Thanks for the tip with logger. I tried network manager, but I would like something that is not GUI dependent. The KDE network manager frontend is a pile of sh... btw. – Grzenio May 27 '09 at 12:49

Heres a possible "untested" solution,

in your /etc/network/interfaces

allow-hotplug eth0
iface eth1 inet dhcp

down ifconfig wlan0 up
down wpa_cli -i wlan0 reassociate

up ifconfig wlan0 down

allow-hotplug wlan0
iface wlan0 inet dhcp

up ifconfig eth0 down
down ifconfig eth0 up

well theres my five cents, I use the above setup to modify routes based on interface up/down on a server of mine, it might work for you too, reason I did it using the interface file was that my scripts didnt seem to execute from the /ifup.d dir even with 755.

Let me know if it works unfortunately I dont have a debian machine with a wifi card to test with :(

share|improve this answer
Hi, this seems reasonable, but the problem I discovered is that my eth1 doesn't seem to be hotpluggable - it is up at the system start, and then dhcp tries to obtain an address every 5 mins or so (unsuccessful because the cable is uplugged), and unfortunately the up and down scripts don't get executed. Any idea? – Grzenio May 31 '09 at 11:10
You could try a messy little script, #!/bin/bash interval=5 while [ 0 -lt 1 ]; do ifconfig eth0 up ifconfig eth0 | grep 'inet addr' | awk '{ print $2 }' | cut -c 6- > /tmp/eth0.stat if [ -z /tmp/eth0.stat ]; then ifconfig eth0 down sleep $interval else echo "We have an address (cat /tmp/eth0.stat), looking good." > /var/log/eth0.stat.log sleep 10 fi done let me know.. – Bruce Grobler Jun 2 '09 at 12:22

Looks like ifplugd package has all the scripts I need! After installing:

apt-get install ifplugd

and adding eth1 to the config file /etc/default/ifplugd everything started to work as I wanted, without adding any extra scripts (I cleaned everything to the initial state).

Thanks everyone for help

share|improve this answer

I still think that adjusting the metric on the wireless interface is the way to go, as I described in

share|improve this answer

You want to set something up in the /etc/network/ subtree, perhaps as womble suggests by increasing the metric of the wifi route, or perhaps by some other means involving a custom script in /etc/network/if-up.d/ that would take the wifi interface down if the ethernet interface came up.

Info on making scripts for /etc/network/if-up.d/ is on the interfaces man page, under the 'IFACE OPTIONS' section.

share|improve this answer

The problem is that you cannot run ifup/down recursively. I have tried to do something similar where I wanted to bring up a VPN interface when a WAN interface was brought up.

My solution is:

echo ifup vpn0 | at now >/dev/null 2>&1

To automatically bring an interface up and down when the cable is plugged or unplugged, use ifplugd from the package of the same name.

share|improve this answer

hmm comments don't like code.



while [ 0 -lt 1 ]; do 
         ifconfig eth0 up 
         ifconfig eth0 | grep 'inet addr' | awk '{ print $2 }' | cut -c 6- > /tmp/eth0.stat
         if [ -z /tmp/eth0.stat ]; then
         ifconfig eth0 down
         sleep $interval
         echo "We have an address (`cat /tmp/eth0.stat`), looking good." > /var/log/eth0.stat.log
         sleep 10

create a daemon to run this on startup.

let me know how it works out

share|improve this answer

At least in Fedora-related distributions, if you look at the ifup script and its relatives, you'll see that if /sbin/ifup-local and /sbin/ifdown-local exist, they'll be executed. This gives you a safe place to plug in machine-local scripts. The one argument passed to these scripts will be the device going up or down.

You could create these scripts and have them start and stop eth0 if the device being started or stopped is your wireless device.

I don't know if the networking scripts are configured to work in the same way under Debian and related distributions, but it's worth a look.

share|improve this answer

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