dimabagow

Setting Up Wi-Fi in Debian

Historical instructions for Debian Lenny and the hardware of that period. Package names, repositories and WPA/TKIP settings are archival examples, not a current installation recipe. The DNS addresses 192.0.2.53 and 192.0.2.54 are documentation placeholders: replace them with real DNS servers. Configure a given interface with one network manager, using documentation for the installed Debian release.

This guide describes Debian Lenny and contemporary hardware. Its repository, package and WPA/TKIP examples belong to that historical setup.

I keep coming across this guide, which helps me set up Wi-Fi in Debian, but only after a long search. I decided to keep it on my blog so I can always find it. The guide was written by Dm. Yurevich, web editor of the KB MDA website.
1. Introduction
Wireless local area networks (WLANs) have become widespread. This practical guide covers a simple case: configuring a Debian GNU/Linux computer to connect to an existing Wi-Fi network. It describes the specifics of two wireless cards: an Intel 2200 BG in a Dell laptop and a D-Link DWA-510 PCI card with a RaLink RT2561/RT61 chip in a desktop computer.
In the example below, the network address is 192.168.7.0. The Wi-Fi access point (AP) also acts as the internet gateway and has address 192.168.7.1. The subnet mask is 255.255.255.0. The access point is configured to use channel 3 and WPA encryption with TKIP and a pre-shared key (PSK).

2. Kernel module and firmware installation for the Wi-Fi card

Many distributions detect the wireless card and configure its software module to load automatically at every boot during operating-system installation. However, having the module installed does not mean the card will work immediately. Many cards also need special firmware, which must be placed in a directory where the module can find it.
    Setting up the card therefore has two stages:

  1. check that the operating system has a kernel module for the card;
  2. install the card's firmware.
2.1. Kernel module
To identify the manufacturer and model, use this command to display the PCI device associated with wireless networking:
$ lspci | grep -i wireless
For the Intel 2200 BG, the output is:
02:03.0 Network controller: Intel Corporation PRO/Wireless 2200BG Network Connection
If there is no output, run
lspci | grep -i network
and find the wireless card among the network controllers.
The D-Link card produces similar output, but names the chip manufacturer, RaLink RT2561/RT61, rather than the card manufacturer. This matters because the module and firmware must match the chip. Two cards of the same make and model may contain different chips, so GNU/Linux support and configuration difficulty may differ.
Next, determine whether installation already loaded the module. Its name usually includes the model number and sometimes an abbreviation of the manufacturer. Run this as root:
# lsmod | grep -i {chip_model}
If trying possible names and examining all loaded modules with
# lsmod | less
finds nothing, the installer did not recognise the card. You can try a distribution with a newer kernel that supports it, or search for information about the chip under GNU/Linux, using a phrase such as “{chip_model} linux”. Some chips are unsupported.
Debian Lenny detected both cards discussed here and configured their kernel modules to load at startup. Let's verify that.
For the Intel 2200 BG, searching for the module gives:
# lsmod | grep -i 2200[Module] [Size] [Use count] [Used by]ipw2200               130760  0ieee80211              30632  1 ipw2200firmware_class          9088  2 ipw2200,pcmcia
For the RaLink RT2561/RT61, I first searched for rt2561 without success. Searching for “rt61” found rt61pci, together with its related modules rt2x00pci, rt2x00lib and eeprom_93cx6:
 # lsmod | grep -i rt61[Module] [Size] [Use count] [Used by]rt61pci   2212 0rt2x00pci  10208 1 rt61pcirt2x00lib  21280  2 rt61pci,rt2x00pcieeprom_93cx6  2304 1 rt61pci
2.2. Installing firmware
Even with the kernel module present, a card may not work without firmware: binary software loaded to make the chip function.
For example, the system sees the D-Link DWA-510 with a RaLink RT2561/RT61 rev B 802.11g chip and even creates two interfaces, which is unusual: wlan0 and wmaster0, but both are inactive:
# ifconfig -aeth0      Link encap:Ethernet  HWaddr 00:0c:6e:4e:24:04 ...lo        Link encap:Local Loopback ...wlan0     Link encap:Ethernet  HWaddr 00:1c:f0:d4:34:61          BROADCAST MULTICAST  MTU:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)wmaster0  Link encap:UNSPEC  HWaddr 00-1C-F0-D4-34-61-65-74-00-00-00-00-00-00-00-00          BROADCAST MULTICAST  MTU:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
Only wlan0 is wireless, as shown by the command that lists wireless interfaces:
# iwconfiglo        no wireless extensions.eth0      no wireless extensions.wmaster0  no wireless extensions.wlan0     IEEE 802.11g  ESSID:""          Mode:Managed  Channel:0  Access Point: Not-Associated          Tx-Power=0 dBm          Retry min limit:7   RTS thr:off   Fragment thr=2352 B          Encryption key:off          Link Quality:0  Signal level:0  Noise level:0          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
Attempts to use wlan0 after adding it to /etc/network/interfaces (see below) reported that it was not configured. The dmesg output revealed the reason: missing firmware for this card.
Where can you get the firmware? There are several possibilities.
1. Look for a distribution package containing the firmware. In the Debian version used here, this non-free firmware package is neither in main nor in contrib, but in non-free. Therefore, edit the repository entry in /etc/apt/sources.list to enable its non-free component. Replace
deb http://ftp.ru.debian.org/debian/ lenny maindeb-src http://ftp.ru.debian.org/debian/ lenny main
with
deb http://ftp.ru.debian.org/debian/ lenny main contrib non-freedeb-src http://ftp.ru.debian.org/debian/ lenny main contrib non-free
and update the package list:
# aptitude update
Search for the chip or module name in package names and descriptions:
# apt-cache search {search_phrase}
The search found nothing for the Intel 2200, but did find a package for the RaLink RT2561/RT61 when searching for “rt61”:
# apt-cache search rt61firmware-ralink - Binary firmware for Ralink RT2561, RT2571, RT2661 and RT2671 wireless cards
Now check whether it is the package we need:
# aptitude show firmware-ralinkPackage: firmware-ralinkNew: yesState: not installedVersion: 0.12Priority: optionalSection: non-free/adminMaintainer: Debian Kernel Team <[email protected]>Uncompressed size: 69.6kSuggests: initramfs-tools, linux-imageDescription: Binary firmware for Ralink RT2561, RT2571, RT2661 and RT2671 wireless cards. This package contains the binary firmware for PCI, CardBus and USB wireless network cards  with the Ralink RT2501 [Turbo],  RT2600, RT5201 [Turbo], RT5600 or RT5201USB chipset,  supported by the rt61, rt61pci, or rt73, rt73usb drivers. Contents: * Ralink RT2561 (RT2501/RT5201 chipset) firmware, version 1.2 * Ralink RT2561S (RT2501 Turbo/RT5201 Turbo chipset) firmware, version 1.2 * Ralink RT2661 (RT2600/RT5600 chipset) firmware, version 1.2 * Ralink RT2571W/RT2671 (RT2501USB/RT5201USB chipset) firmware, version 1.8Homepage: http://www.ralinktech.com/ralink/Home/Support/Linux.html
The description says it contains the binary firmware we need, so install it:
# aptitude install firmware-ralink
Installation placed the required firmware in /lib/firmware. The card was ready to use.
2. Find and download firmware for the chip online. Search for “{chip_model} linux firmware” or “{chip_model} linux driver” and examine the results.
That is how I found the Intel 2200 BG firmware. A Google search for “Intel Wireless 2200BG linux driver” led directly to the GNU/Linux firmware website: http://ipw2200.sourceforge.net/ (see the «Firmware» section). Intel provides GNU/Linux drivers for many of its devices, which is worth considering when buying hardware for use with GNU/Linux.
Download the firmware version used here, 3.0, from http://ipw2200.sourceforge.net/firmware.php?fid=7. This gives you the archive ipw2200-fw-3.0.tgz. As root, extract its contents into /lib/firmware (some distributions use /usr/share/firmware or /usr/lib/hotplug/firmware/). The directory will then contain:
# ls -l /lib/firmware-rw-r--r-- 1 root root 191142 Mar  7  2006 ipw2200-bss.fw-rw-r--r-- 1 root root 185660 Mar  7  2006 ipw2200-ibss.fw-rw-r--r-- 1 root root 187836 Mar  7  2006 ipw2200-sniffer.fw-rw-r--r-- 1 root root  12007 Mar  7  2006 LICENSE.ipw2200-fw
3. Try the binary supplied with the card's MS Windows driver. This can be done with ndiswrapper. For an example, see http://citkit.ru/articles/423/ (the “Включаем” section).

3. Installing the required programs

Install the wireless networking packages, at least wireless-tools and, for WPA encryption, wpasupplicant. You may also find the graphical utilities useful, though I did not need them: kwifimanager, kwirelessmonitor and, for WPA, wpagui. Install them as root:
# aptitude install wireless-tools wpasupplicant kwifimanager kwirelessmonitor wpagui
Also, following M. Konnik's advice, install the ACPI power-management packages:
# aptitude install acpi-support acpid laptop-mode-tools
This starts the acpid daemon and adds the required scripts to /etc/acpi.

4. Possible problems with the laptop's Wi-Fi switch

After rebooting, testing the Intel 2200 card (see below) shows that it still does not work.
Examine the boot messages:
# dmesg | less
Scroll down to find lines resembling these:
[    8.443703] ieee80211_crypt: registered algorithm 'NULL'[    8.468166] ieee80211: 802.11 data/management/control stack, git-1.1.13[    8.468170] ieee80211: Copyright (C) 2004-2005 Intel Corporation[    8.527267] ipw2200: Intel(R) PRO/Wireless 2200/2915 Network Driver, 1.2.2kmprq[    8.527271] ipw2200: Copyright(c) 2003-2006 Intel Corporation[    8.527350] ACPI: PCI Interrupt 0000:02:03.0[A] -> GSI 17 (level, low) -> IRQ 17[    8.547046] ipw2200: Detected Intel PRO/Wireless 2200BG Network Connection[    8.934885] ipw2200: Radio Frequency Kill Switch is On:[    8.971250] Kill switch must be turned off for wireless networking to work....[    9.272808] ipw2200: Detected geography ZZD (13 802.11bg channels, 0 802.11a channels)
The module loads, as indicated by ipw2200: Intel(R) PRO/Wireless 2200/2915 Network Driver, 1.2.2kmprq, but cannot operate for a simple reason. In the BIOS, under «Wireless» (“Wireless Network”), the device is disabled at startup! The message “Radio Frequency Kill Switch is On” reports this. The ominous-sounding “kill switch” blocks the radio; as the next message says, “Kill switch must be turned off for wireless networking to work”.
Reboot, enter the BIOS with Delete or the appropriate key before the operating system loads, and enable the Wi-Fi card at startup. On a laptop, allow the wireless function-key shortcut to control it; mine uses Fn + F2, with a transmitter symbol on F2.
Start the system again:
# dmesg | less...[    8.443703] ieee80211_crypt: registered algorithm 'NULL'[    8.468166] ieee80211: 802.11 data/management/control stack, git-1.1.13[    8.468170] ieee80211: Copyright (C) 2004-2005 Intel Corporation[    8.527267] ipw2200: Intel(R) PRO/Wireless 2200/2915 Network Driver, 1.2.2kmprq[    8.527271] ipw2200: Copyright(c) 2003-2006 Intel Corporation[    8.527350] ACPI: PCI Interrupt 0000:02:03.0[A] -> GSI 17 (level, low) -> IRQ 17[    8.547046] ipw2200: Detected Intel PRO/Wireless 2200BG Network Connection...[    9.272808] ipw2200: Detected geography ZZD (13 802.11bg channels, 0 802.11a channels)
The unwanted message no longer appears.
If you cannot turn off the kill switch, more involved methods include the program rfswitch, which forces the switch off (website: http://rfswitch.sourceforge.net/), or recompiling the kernel as described here).

5. Testing the Wi-Fi card

Now try detecting an access point. Run
# ifconfig -a
to find the name assigned to the card's wireless interface. My laptop's Intel 2200 appeared as eth1. The desktop's RaLink RT2561/RT61 produced two interfaces, wlan0 and wmaster0, but only the first is wireless. You can check this with iwconfig -a; see the example above)
Then scan for access points on the wireless interface, using eth1 as the example:
# iwlist eth1 scaneth1      Scan completed :          Cell 01 - Address: 11:22:6B:81:A8:6A                    ESSID:"home_wireless_network"                    Protocol:IEEE 802.11bg                    Mode:Master                    Frequency:2.422 GHz (Channel 3)                    Encryption key:on                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 6 Mb/s; 9 Mb/s                              11 Mb/s; 12 Mb/s; 18 Mb/s; 24 Mb/s; 36 Mb/s                              48 Mb/s; 54 Mb/s                    Quality=100/100  Signal level=-19 dBm                    IE: WPA Version 1                        Group Cipher : TKIP                        Pairwise Ciphers (1) : TKIP                        Authentication Suites (1) : PSK                    Extra: Last beacon: 176ms ago
The output shows access point 11:22:6B:81:A8:6A providing the network “home_wireless_network” on channel 3. I assigned that name through the access point's web interface. The network uses WPA with TKIP and a pre-shared key (PSK).
A straightforward way to configure the network in this Debian setup is to put its parameters in /etc/network/interfaces .
Note 1, for those who prefer graphical tools: this file is itself a convenient configuration interface. You only need a few lines with appropriate values. If you prefer a GUI, enter the same values in its corresponding fields as those shown below in /etc/network/interfaces .
Note 2. Another way to configure the wireless interface from the console is with iwconfig.

6. Configuring a wireless interface
with a static address

For this network, we assign static addresses to the computers to make their configuration predictable. A static address alone does not provide network security.
The following section of /etc/network/interfaces configures a wireless network with addresses assigned in advance by the administrator. Detailed comments explain each setting.
#-------------------------------------------------# Wireless LAN interface: eth1#-------------------------------------------------## Interface definition:# inet: IPv4 networking# static: a fixed IP addressiface eth1 inet static # Required interface address # Our computer uses this address # on the 192.168.7.* wireless network address 192.168.7.15 # Required subnet mask netmask 255.255.255.0 # Network address network 192.168.7.0 # Broadcast address broadcast 192.168.7.255 # Gateway: the wireless access point # Assigned when configuring the access point gateway 192.168.7.1 # Network name: home_wireless_network wireless-essid home_wireless_network # managed: connect to an access point wireless-mode managed # Channel 3, matching the access point wireless-channel 3 # Determine the transmission rate automatically wireless-rate auto #------------------------------------------------- # WPA encryption settings #------------------------------------------------- # # WPA SSID: the network name # home_wireless_network in this example wpa-ssid home_wireless_network # WPA pre-shared key # Set when configuring the access point # Use a passphrase of 8-63 characters or a 64-digit hexadecimal key # This example uses a passphrase wpa-psk paw6102bdse889mpaaj9828nhhiizpsye8732j # Key management: WPA-PSK wpa-key-mgmt WPA-PSK # Pairwise ciphers: TKIP and CCMP wpa-pairwise TKIP CCMP # Group cipher: TKIP wpa-group TKIP # Protocol: WPA        wpa-proto WPA
Parameters beginning with “wireless-” configure the wireless network; those beginning with “wpa-” configure WPA (Wi-Fi Protected Access). At the time of this setup, WPA was preferred to WEP (Wired Equivalent Privacy). The access point must use matching settings.
You also need DNS servers, which translate domain names into IP addresses. For example, the original guide used lenta.ru and the address 81.19.69.232. DNS server addresses are usually entered in /etc/resolv.conf as follows:
# Example /etc/resolv.conf## nameserver is followed by a DNS server's IP address## You can use your internet provider's DNS servers;# ask the provider for their addresses.# Alternatively, use public servers# whose response time may be longer.## The original example lists two public server addresses below#nameserver 192.0.2.53nameserver 192.0.2.54
Other public DNS server addresses are listed here.
Reboot and, if necessary, bring up eth1 as root:
# ifup eth1
If you were using a wired interface, called eth0 on my machine, bring it down first if you are switching entirely to Wi-Fi:
# ifdown eth0
To bring the wireless interface down, use the corresponding command:
# ifdown eth1
To bring eth1 up automatically at boot, add this line before its definition, that is, before iface eth1 inet static:
auto eth1

7. Configuring a wireless interface
with dynamically assigned addresses

This is similar to the previous case, but in the wireless section of /etc/network/interfaces replace
iface eth1 inet static
with
iface eth1 inet dhcp
and remove the fixed address below, along with the static netmask, network, broadcast and gateway settings. DHCP supplies the network configuration:
address 192.168.7.15
Note. Remember to check DNS configuration (see above).

8. Additional WPA settings

With GNU/Linux kernel 2.4 or a 2.6 kernel older than 2.6.14, explicitly specify the WPA driver. In this Debian setup, add it to /etc/network/interfaces):
wpa-driver {driver}
    where {driver} is one of the following:

  • wext: the general-purpose driver, suitable in most cases;
  • atmel: driver for ATMEL AT76C5XXx (USB, PCMCIA);
  • wired: driver for wired Ethernet.
Common WPA options
In Debian, put these in the appropriate section of /etc/network/interfaces);
taken from here
Option Possible values
(in /etc/network/interfaces, separate allowed values with spaces)
Description
wpa-ssid {text string} sets the network name (SSID)
wpa-bssid Example:00:1a:2b:3c:4d:5e identifier (BSSID) of the access point to connect to
wpa-psk Example:iehRHbfGy89620ksjDHF3 WPA pre-shared key
wpa-key-mgmt NONE, WPA-PSK, WPA-EAP,IEEE8021X accepted key-management methods
wpa-group CCMP, TKIP, WEP104,WEP40 accepted WPA group ciphers
wpa-pairwise CCMP, TKIP, NONE accepted WPA pairwise ciphers
wpa-auth-alg OPEN, SHARED, LEAP allowed IEEE 802.11 authentication algorithms
wpa-proto WPA, RSN accepted protocols
wpa-identity Example:vasya username supplied by the administrator for EAP authentication
wpa-password Example:rRt89Nbvc4 password for EAP authentication

9. Conclusion

The configuration method described here works with Debian's traditional networking tools. It has a drawback when you regularly switch between two interfaces, such as wired and wi-fi networks: switching is manual and requires the root password, which an ordinary user may not know.
If you frequently use several interfaces or connect to new Wi-Fi networks, both common on a laptop, consider the alternative approach provided by NetworkManager. You can read more about it here.
In KDE, you can monitor the interfaces with KNemo. After installation, configure it under KDE Control Centre > Network and Internet > Network Monitor.