This section explains how to configure networking in a very pleasant way, so that it works automatically wherever you go. This solution has been inspired by a tutorial that can be found in the references section at the bottom of this page. It uses three tools that integrate well with the debian network configuration:

  • wpa_supplicant, which handles wireless access point association,
  • ifplugd that checks for an ethernet cable to be plugged,
  • guessnet that gives you tools to detect which network you are connected to.
  • resolvconf to understand name server configuration in /etc/network/interfaces.

First, some installation :

# aptitude install wpasupplicant ifplugd guessnet resolvconf

The next steps consist mostly in editing a bunch of files. To configure all this, my advice is to turn networking off :

# ifdown eth0
# ifdown eth1
# /etc/init.d/ifplugd stop

Physical layer

/etc/wpa_supplicant.conf :





# Connect to any public open access point

The id_str configuration parameter is used to know which configuration to use in /etc/network/interfaces (see next paragraph). Networks that do not have this parameter use the default configuration.

You may add any number of networks to fit your needs.

Transport, network and application layers

/etc/network/interfaces is the central repository of the network configuration in Debian.

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The wireless interface
auto eth1
iface eth1 inet manual
      wpa-driver wext
      wpa-roam /etc/wpa_supplicant.conf

# The Ethernet is mapped depending on the environment
mapping eth0
    script guessnet-ifupdown
    map default: default
    map timeout: 3
    map verbose: true

iface home inet static
    test peer address mac 00:01:23:45:67:89
    up /etc/init.d/samba start
    down /etc/init.d/samba stop

# This interface is to catch unidentified Wireless networks
# and is of course the default map for eth0
iface default inet dhcp

The choice of the wext driver depends on your Wireless adapter. Mine is an ipw2200 and uses the Linux Wireless extensions, thus I use wext.

This basically tells eth0 or eth1 to be configured differently whether a host with address and mac 00:01:23:45:67:89 is found or not. If it is there, take a static ip address and start samba. If not, revert to dhcp.

A little tip for the samba example : for samba not to start while booting, just run :

# update-rc.d samba stop 0 1 2 3 4 5 6 .

Ensure your have the desired ip address :

# ifup eth1
# ifconfig

This setup works well for me.

FIXME There should be a priority to the Ethernet interface, et the wireless interface should go down while a network wable is plugged in. A debian bug has been filled on the subject. Here are possible solutions :

  • Have the Ethernet ifplugd instance control the wireless instance. Drawback : this is hackish.
  • Use ifmetric to route traffic through Ethernet if available. Drawbacks : wireless is up for no reason and if wireless gets associated after the Ethernet cable is plugged, DNS settings are overwritten, which can be annoying if they are different.
  • Use the new wpa_supplicant feature to manage the Ethernet. Not sure I red well on this…

For now, before I plug to a wired network, I just use the kill switch feature of my laptop to turn wireless off.