Intro

Probably GNOME NetworkManager meets all your requirements, but I personally find it too restricted in sense of functionality and unstable in any sense. Also it often conflicted with my manual network settings. So I never use NetworkManager.

While legacy /etc/network/interfaces file is powerful for setting up unusual and complex topologies, it offers nothing for setting wireless networks that are quite usual nowadays.

This article is about how I got using WiFi without help of tools that were created with a single purpose: to reinvent wheel.

Prerequisites

Most WiFi networks use IP-address allocation via DHCP, this very case is regarded below.

Assume networks are secured with any mechanism supported by wpa_supplicant.

Hidden and Ad-hoc networks are out of scope of this article.

Solution

Excerpt from /etc/network/interfaces:

allow-hotplug wlan0
iface wlan0 inet dhcp
	pre-up ip link set "$IFACE" up
	pre-up /etc/network/up-wpa.sh
	down pid="$(cat '/var/run/wpa_supplicant.'"$IFACE"'.pid')" ; test -z "$pid" || kill "$pid"

There are two worth noting points:

  1. down hook;
  2. up-wpa script;

Down hook is here because wpa_supplicant is not good in detecting interface state changes. Sometimes it remains running even after interface go down. To avoid possible conflicts with several instances this workaround is here.

Lets look at up-wpa wrapper script (available here: HTML , plain text ). Following Android way you can put settings for all known WiFi access points into a single file. And append new APs to the end of this file. In this case you can simply replace that pre-up command with wpa_supplicant:

wpa_supplicant -B -c /etc/wpa_supplicant.conf -P '/var/run/wpa_supplicant.'"$IFACE"'.pid' -i "$IFACE"

It is simple to understand and to use, it works. Though I prefer to have a separate file for each AP. Primary for (but not limited to) a security reason.

Well, up-wpa discovers all available APs with iwlist from wireless-tools collection, compares with a list of configured networks and connects to the first found one with wpa_supplicant. Precedence of configured networks is controlled by alphabetic order of configuration files' names.

Configuration files stored under /etc/network/wpa/ and have .conf suffix (ignored otherwise).

Sample WPA2-PSK secured network settings in /etc/network/wpa/99-sample.conf:

network={
	ssid="Sample_WiFi_Network"
	key_mgmt=WPA-PSK
	psk="secret"
}

Conclusion

ifupdown interfaces in Debian is powerful enough to be yet applicable. The proposed solution allows one to up/down wireless interfaces with:

$ ifup wlan0
$ ifdown wlan0

or debug any issues with:

$ ifup --verbose wlan0
$ ifdown --verbose wlan0