To my homepageGerman
Did this site help you?
Average rating (Interfaces):
2.97/3 (169 votes)

Network configuration with Debian GNU/Linux

...always online

Debian GNU/Linux provides a slick and elegant way of network configuration through the file /etc/network/interfaces. Other distributions like Familiar adopted this system, and despite its broad acceptance, many of its features are still hidden to most users.

Assigning unique device names

A main issue with systems having multiple network interfaces is the identification of those: Due to race conditions in module loading, positions can switch; While eth0 is usually the Ethernet interface, it can also become the Firewire network interface or the WLAN card. Therefore, the association between device name and physical interface is not really tight.

A solution to this issue is to abandon generic interface names and assign descriptive ones. To do this, udev provides a way of renaming network devices depending on their unique MAC hardware address:

KERNEL=="eth*", SYSFS{address}=="00:02:3f:46:de:ad:be:ef", NAME="fw"

Adding this line to a file in /etc/udev/rules.d/ instructs udev to rename the netork interface with the entered MAC address to "fw", indicating the firewire interface. You can do the same with your WLAN and LAN interfaces, so that you end up with descriptive names for all of your network devices.

Using different profiles

Notebook users often roam from one network to another - and despite DHCP, a different configuration is required for most of them, especially when dealing with WEP/WPA encryption or static addresses.

Having multiple profiles is not problem at all: Instead of assigning network information directly to an interface name, a descriptive identifier of the situation those data shall be employed in can be used.

Consider the following example: At home, you want to use a static IP, but at work, you receive your network configuration via the DHCP protocol. To achieve this, you can simply create the following stanzas in your /etc/network/interfaces file:

iface home inet static
    address 192.168.0.2
    netmask 255.255.255.0
    gateway 192.168.0.1
    
iface office inet dhcp

To select the valid profile depending on your location, simply append it to the ifup command: ifup eth0=office brings up the physical interface "eth0" with the profile data from "office".

Automatic selection of the right profile

It is possible to let the computer select the right profile automatically. To define how this decision is made, a mapping section is needed:

mapping wlan0
    script /usr/local/sbin/wlan-select.sh

The supplied script is free in its proceeding in detecting the right profile: All it has to do is print the name of the selected profile on its standard output. It is possible to wrte custom scripts to detect the location of the notebook, but there are also readily prepared programs in Debian for it:

Both guessnet and whereami are well documented in their Debian packages, including many examples.

Wifichoice

wifichoice.sh

Download script
Last change: Sunday, 26-Feb-2006 11:54:53 CET

Although I am using guessnet myself for my LAN interface, I was not satisfied with its support for wireless interfaces; I did not find another program that fit my needs. That's why I wrote my own mapping script. After cleaning it up a bit, it became a flexible (shell) program that could cope with many scenarios, so I decided to publish it under the name wifichoice.

Configuration

Wifichoice selects the proper configuration profile for your WLAN interface by scanning for the right environment. To achieve this, it can either scan for the correct access point or ESSID, or try to associate with the configured network.

Configuration is done in a central way via /etc/network/interfaces:

mapping wlan0
   script /usr/local/sbin/wifichoice.sh
   map default: none
   map timeout: 2

Timeout is the number of seconds the script waits after a test association for the device to settle, and default is the profile that shoud be loaded is if no known surrounding is detected.

The test parameters are defined in the profiles themselves:

iface home inet dhcp
   wireless yes
   wireless_mode managed
   wireless_key open 1234567890ABCDEF1234567890
   wireless_essid mywifinet
   wifichoice ap 00:12:34:56:78:9A

Since your access point does not not broadcast its ESSID, and/or your card does not support "iwlist scan", wifichoice tries to associate with the network, using the supplied config, and then checks whether the network is managed by the right access point.

If you can identify the network by its broadcasted ESSID or AP, you can also try to scan for it. Just add a line like this to your profile:

wifichoice scan essid mywifinet

Wifichoice then invokes a scan for neighbouring access points, and identifies those that serve the requested ESSID. It is also possible to scan for a specific access point address, this is useful if the AP does not transmit its ESSID:

wifichoice scan ap 00:12:34:56:78:9A

Adding multiple IP addresses to an interface

Adding multiple addresses to an interface usually requires trickery: This script makes it easy. Just place the script in /etc/network/if-up.d/ and create a symlink in /etc/network/if-down.d/. You can then specify additional addresses in your interface stancas:

iface eth0 dhcp
            addresses 10.0.0.1/8
            addresses-foo 192.168.1.5/24 192.168.2.5/24
            addresses-bar 172.17.2.1/16

All lines are merged, and all addresses specified in them are added when the interface comes up. The addresses are removed as well when deconfiguring the interface.

You can install this script along with some other ifupdown extension from my apt repository, just add this line to your /etc/apt/sources.list and install the package ifupdown-scripts-wa:

deb http://wertarbyte.de/apt/ ./