Network profiles for a laptop

Posted by niol on Tue 20 Dec 2005 at 13:04

This article explains how to configure networking in a very pleasant way, so that it works automatically wherever you go. It is adaptable to lots of uses, and may be usefull even if you don't use Wifi but connect to multiple networks. 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:

First, some installation:

# apt-get 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/wpasupplicant stop
# /etc/init.d/ifplugd stop

Physical layer

/etc/default/wpasupplicant:

ENABLED=1
  
OPTIONS="-D ipw -i eth1 -c /etc/wpa_supplicant.conf"

You may notice that my Wifi driver regarding wpa_supplicant is ipw (which fits either ipw2100 and ipw2200). The wpa_supplicant manual page lists other drivers that may fit your Wifi chipset.

If you use kernel 2.6.13 or above, you need to know that what handles wireless in the kernel, the Wireless extensions, have been updated. As a consequence, you cannot use the ipw driver anymore. You need to use the wext driver.

ENABLED=1
  
OPTIONS="-D wext -i eth1 -c /etc/wpa_supplicant.conf"

/etc/wpa_supplicant.conf:

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
eapol_version=1
ap_scan=1
fast_reauth=1

# the network I use which is configured using WPA-PSK
network={
	ssid="your_case_sensitive_ssid"
	psk="your_passphrase"
	priority=5
}

# You may add networks below, such as public unencrypted APs
network={
	ssid="public-ap"
	key_mgmt=NONE
	priority=0
}

I stripped down the comments to save space on this page, but every detail may be found in the file /usr/share/doc/wpasupplicant/examples/wpa_supplicant.conf.gz. To get you some hints on how wpa_supplicant works, it tries to associate to an access point with the highest priority. My configuration is very basic. My goal is to get secure Wifi at home, and be able to add other configurations when I'm out (public AP).

Ensure your are associated to your access point:

# /etc/init.d/wpasupplicant start
# iwconfig

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

# ifplugd brings up interfaces, so do not bring them up at startup.
noauto eth0 eth1
  
# Both Ethernet and Wifi interfaces are managed automatically
mapping eth0 eth1
	script guessnet-ifupdown
	map default: foreign
	map timeout: 3
	map verbose: true

iface home inet static
	address 192.168.51.6
	netmask 255.255.255.224
	broadcast 192.168.51.31
	gateway 192.168.51.1
	dns-search subdomain.org
	dns-nameservers 192.168.1.2
	test peer address 192.168.51.1 mac 00:01:23:45:67:89
	up /etc/init.d/samba start
	down /etc/init.d/samba stop

iface foreign inet dhcp

This basically tells eth0 or eth1 to be configured differently whether a host with address 192.168.51.1 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:

# /etc/init.d/ifplugd start
# ifconfig

This setup works well for me.

There are issues when changing networks while in hibernation. The solution is to be stop ifplugd while hibernating. If you use the suspend2 ''hibernate'' script, you may want to add this line to your hibernate.conf:

RestartServices ifplugd

There should be a priority to the Ethernet interface, and the wireless interface should go down while a network cable is plugged in. A debian bug has been filled on the subject. There are two solutions :

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

As usual, comments welcomed.

References


This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):

This article is copyright 2005 niol - please ask for permission to republish or translate.