Configuring Wireless

From gr0x0rd
Jump to navigation Jump to search

Configuring Hardware - Configuring Wireless

If you set up your kernel correctly, you installed the driver for your wireless card as a module. As another example, let's investigate the wireless network controller using lspci:

$ sudo lspci -v | grep Wireless 

The results should look something like this:

03:00.0 Network controller: Atheros Communications Inc. AR9285 Wireless Network Adapter (PCI-Express) (rev 01)

For this card, the kernel config is as follows:

[*] Networking support  ---> 
 -*-   Wireless  --->
  <*>   cfg80211 - wireless configuration API
  ...
  [*]     enable powersave by default
  ...
  <*>   Generic IEEE 802.11 Networking Stack (mac80211)

Device Drivers  --->
 [*] Network device support  --->
  [*]   Wireless LAN  --->
   <*>   Atheros Wireless Cards  --->
    ...
    <M>   Atheros 802.11n wireless cards support
    ...

Using lspci again, you should be able to see whether or not the correct kernel driver or module has been loaded for the device.

Kernel driver in use: ath9k
Kernel modules: ath9k

If you are confident you have correct kernel configuration and driver, you can test the module by probing it. Replace ath9k with the name of the module for your wireless device.

$ sudo modprobe ath9k

If you don't see any error messages the module is configured correctly. If you haven't already, be sure to add the module to /etc/modules.autoload.d/kernel-2.6. Depending on the card, you may also have to emerge a software package for your card, in order to create an interface between the kernel driver and the software package you'll use to configure it. For most cards, this will be the net-wireless/wireless-tools package.

$ sudo emerge -av wireless-tools

Once the package has emerged, we'll also need to install a package to manage the connections between the card and the networks it connects to. Since most wireless access points use WPA or WPA2 for security, the best package for this is wpa_supplicant. Before emerging, be sure that you have set the qt4 USE flag for it in your /etc/portage/package.use so you can use a simple GUI to manage your network connections.

$ sudo nano -w /etc/portage/package.use

Make sure the file contains the following line:

net-wireless/wpa_supplicant qt4

Next, we emerge wpa_supplicant.

$ sudo emerge -av wpa_supplicant

Once the emerge has completed, we'll need to create our initial wpa_supplicant.conf file.

/etc/wpa_supplicant/wpa_supplicant.conf

# The below line not be changed otherwise we refuse to work
ctrl_interface=/var/run/wpa_supplicant

# Allow users can read the WPA configuration
ctrl_interface_group=users

# Let wpa_supplicant take care of scanning and AP selection
ap_scan=1

#allow users to change this file
update_config=1

network={
       ssid="any"
       key_mgmt=NONE
       priority=1
}

# Simple case: WPA-PSK, PSK as an ASCII passphrase, allow all valid ciphers
network={
        ssid="WPAnetworkID"
	scan_ssid=0
	key_mgmt=WPA-PSK
	pairwise=CCMP TKIP
	group=CCMP TKIP
	psk="secretwpapassphrase"
 	priority=1024  
}

# another case: WEP network with a SHARED key
network={
        ssid="WEPnetworkID"
        scan_ssid=1
        key_mgmt=NONE
        wep_key0="secretweppassphrase"
        auth_alg=SHARED
        priority=1023
}

Feel free to use google to find some manual wpa_supplicant.conf examples. The other option is to use the GUI to configure your networks; most users will mostlikely find this to be the easiest option.

We'll need to make some changes in order for normal users to make changes to wireless connections.

$ sudo chown root:users /usr/bin/wpa_gui
$ sudo chown root:users /etc/wpa_supplicant/wpa_supplicant.conf
$ sudo chmod 775 /etc/wpa_supplicant/wpa_supplicant.conf
$ sudo chown -R root:users /var/run/wpa_supplicant

In order to configure the device and set it to start with the system, we'll need to determine what name udev has given it. To look at the udev rules

$ sudo cat /etc/udev/rules.d/70-persistent-net.rules

The results should look something like this:

# PCI device 0x168c:0x002b (ath9k)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="48:5d:60:64:75:73", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

The key piece of information here is the NAME value. We can see the device has been set to wlan0. Next we'll want to set the device to start with the networking stack at boot time. To do this, we'll create a symbolic link to the card's initialization routines. This may have been done for you already, but in case it hasn't

$ cd /etc/init.d
$ sudo ln -s net.lo /etc/init.d/net.wlan0

Now we'll need to modify the network startup configuration so your wireless card is initialized during the boot process.

$ sudo nano -w /etc/conf.d/net

As long as your card uses the wireless-tools package for configuration and not some other package, the following should work fine.

/etc/conf.d/net

...
modules_wlan0=( "wpa_supplicant" )
wpa_supplicant_wlan0="-Dwext"
config_wlan0=( "dhcp" )
...

At this point, we're ready to initialize the wireless card.

$ sudo ifconfig wlan0 up

Once this command has completed, you can check the status of the wireless device.

$ sudo ifconfig -s

If your device is listed, looks like you've succeeded. Start the card.

$ sudo /etc/init.d/net.wlan0 start

If you've configured wpa_supplicant correctly, the card should grab an IP from the highest priority wireless access point it can successfully connect to. You should now have a successful wireless connection.