Discussion:
How to switch between network interfaces?
(too old to reply)
Piers Kittel
2004-04-30 17:50:13 UTC
Permalink
Hello all,

I have a HP Omnibook 500 laptop, with Debian 3.0r2 testing - and to
access the internet/intranet, I use a WLAN card, but occasionally I plug
it into the wired network to transfer big sized files, but each time I
do that, I edit the interfaces file, comment out the wlan0 enteries,
remove the comments commenting out the eth0 enteries then restart
networking - isn't there an automatic way of doing that?

Also as I have a dhcp server on the internal net, both interfaces are
set to get an IP from the server - and the IP address is the same for
both interfaces. No problem in itself, but if I have the eth0 interface
enabled in the /etc/networking/interfaces file - it will hang there
trying to find the dhcp server, while the network cable is unplugged.

I also find even when I get eth0 enabled and on the network, the laptop
still recieves files through the wlan card, until I physically remove
the card then it'd switch over directly to the wired interface.

So:

1) Is there anyway for the computer to automatically enable and then
switch over to eth0, and disable wlan0 when the network cable is plugged
in? If not, is there a quick way to do all this? And same the other
way round, i.e. automatically enable and switch over to wlan0 and
disable eth0 when the network cable is unplugged?

2) Is there a way for the laptop to detect if the wired cable is
unplugged then it'd bypass or "disable" the eth0 interface at bootup so
preventing the dhcp client trying to find an IP via eth0?

Thanks very much for your help in advance

Cheers - Piers
--
To UNSUBSCRIBE, email to debian-user-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Derrick 'dman' Hudson
2004-04-30 18:10:37 UTC
Permalink
On Fri, Apr 30, 2004 at 06:25:35PM +0100, Piers Kittel wrote:

| 2) Is there a way for the laptop to detect if the wired cable is
| unplugged then it'd bypass or "disable" the eth0 interface at bootup so
| preventing the dhcp client trying to find an IP via eth0?

I don't know the ideal solution to your other question, but I do know
the answer to this one!

--- /etc/network/interfaces
auto eth0
iface eth0 inet dhcp
# only try DHCP if there is a physical link
pre-up /usr/local/sbin/check-link.sh eth0


--- /usr/local/sbin/check-link.sh
#!/bin/sh
# check-link.sh
# tests interface for link
#
# Usage: check-link.sh INTERFACE
#
# Greg Wiley
# ***@orthogony.com
#
# Script is meant for use with the ifupdown
# program as a pre-up command. It returns
# success if the given interface has a link.
# Created to avoid the laptop boot delay
# caused by trying to DHCP an unconnected
# interface.
#
# Currently uses MII to check link status.
# This might not be universal since not all
# NICs use MII. It should work for a large
# number of ethernet NICs, though
#
# History:
# 11/15/2001 gjwiley create
# 11/16/2001 gjwiley add syntax checking, support
# prog checking, comments, etc.
# for publish
# TODO:
# - if useful, add support for non-ether,
# non-mii xfcs


iface="$1"

# what to grep to determine no link
MIINACK='no link'

# where is ifconfig?
IFCTOOL='/sbin/ifconfig'
IFCCMD="eval ( ${IFCTOOL} ${iface} > /dev/null 2>&1 )"

# the mii link checking program
MIITOOL='/sbin/mii-tool'
MIICMD="${MIITOOL} ${iface}"

# some systems don't use egrep
GREPTOOL='/bin/egrep'
GREPMIICMD="eval ${GREPTOOL} -q '${MIINACK}'"


#default to internal error return
rval='3';
if [ -f ${MIITOOL} -a -f ${GREPTOOL} -a -f ${IFCTOOL} ]; then
if [ -x ${MIITOOL} -a -x ${GREPTOOL} -a -x ${IFCTOOL} ]; then
if [ "x${iface}" != "x" ]; then
if ${IFCCMD}; then
if ( ${MIICMD} | ${GREPMIICMD} ); then
rval='1'
else
rval='0'
fi
else
echo "${0}: invalid interface" >&2
rval='2'
fi
else
echo "${0}: interface not specified" >&2
rval='2'
fi
else
echo "${0}: required program not executable." >&2
fi
else
echo "${0}: required program not found." >&2
fi

exit ${rval}



As the comments indicate, I didn't come up with this. I found it on
the 'net when someone on d-u pointed it out.

The only downside is ifupdown puts an entry in the state file even
when it doesn't bring up the interface. Therefore after you plug a
cable in, you either need to run ifup with the '--force' parameter or
run 'ifdown' before running ifup.

-D
--
Yes, Java is so bulletproofed that to a C programmer it feels like being in a
straightjacket, but it's a really comfy and warm straightjacket, and the world
would be a safer place if everyone was straightjacketed most of the time.
-- Mark 'Kamikaze' Hughes

www: http://dman13.dyndns.org/~dman/ jabber: ***@dman13.dyndns.org
Adam Aube
2004-04-30 22:20:09 UTC
Permalink
Post by Piers Kittel
I have a HP Omnibook 500 laptop, with Debian 3.0r2 testing - and to
access the internet/intranet, I use a WLAN card, but occasionally I plug
it into the wired network to transfer big sized files, but each time I
do that, I edit the interfaces file, comment out the wlan0 enteries,
remove the comments commenting out the eth0 enteries then restart
networking - isn't there an automatic way of doing that?
Have you tried ifup/ifdown? Leave both interfaces configured
in /etc/network/interfaces, but have neither one start automatically. Then
just use ifup/ifdown as needed.

Adam
--
To UNSUBSCRIBE, email to debian-user-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Loading...