Header Shadow Image


Linux Wireless Networking Step by Step HowTo

For this howto we will be using the TP-LINK line of USB wireless cards.  More precisely the 54Mbps TL-WN321G and the 300M TL-WN821N adapters otherwise known for running the Atheros Communications, Inc.  Atheros eXtended Range™ technology.  This is an important note because this is how this card will appear under Linux.

I find these adapters at least much cheaper and apparently more reliable to their DLINK counterparts – they just work out of the box with Linux without any install CD's.  No drivers necessary as, presumably, the controller chip is registered as Atheros AR9170, for which drivers appear readily available on Linux systems.

For this post, we will assume you have a router and configuration similar to the one described on our page here at Linux / Windows Networking: Configuring and securing a router for Wireless and Wired Networks.  In case you run into issues, further reading on resolving them is available from our Windows Networking: The network is not present or not started  WIKI or the Linux Networking: device eth0 does not seem to be present, delaying initialization counterpart.

As per the above links, we will be using WPA2-PSK with the AES encryption algorithm. Here are the steps assuming a configuration similar to the above router configuration link:

 

STEP # DESCRIPTION COMMANDS
1

Check if you have the correct packages installed.

 

 

To find out the version of packages under your system type:

# rpm -aq|grep wpa_supplicant
# rpm -aq|grep net-tools

At the time of this writing, the most recent RPM packages available for the Fedora 13 distribution are:

net-tools-1.60-102.fc13.i686
wpa_supplicant-0.6.8-9.fc13.i686

 

WPA Supplicant is needed for WPA2 wireless keys we will need to use.  (WPA2 + AES are the protocols and algorithms we will use.) ifconfig typically comes preinstalled on most Linux systems.

If the packages are not installed, use yum search wpa_supplicant to find the latest package for your distribution.  Ubuntu users can use apt-get instead.

2 Plug in your USB Wireless stick.

Plug in the USB Wireless stick and use the following command to check if your device has registered with the Kernel/OS:

# lsusb
Bus 001 Device 002: ID 0cf3:1002 Atheros Communications, Inc.
# lsusb -v -D /dev/bus/usb/001/002
(Lengthy detailed output of the device properties)

Record the information.  The output will be lengthy.

3 Identify the properties for your wireless USBstick.

Before you do so, you may need to run:

# service network restart
#

Checking /var/log/messages for new USB devices that were recently plugged in is also a good idea.  Typically I run:

# tail -f /var/log/messages

to see the changes as I plug in the USB Wireless device.  The output can look messy and is similar to this:

Jun 27 14:02:02 localhost kernel: usb 1-2: new high speed USB device using ehci_hcd and address 5
Jun 27 14:02:02 localhost kernel: usb 1-2: New USB device found, idVendor=0cf3, idProduct=1002
Jun 27 14:02:02 localhost kernel: usb 1-2: New USB device strings: Mfr=16, Product=32, SerialNumber=48
Jun 27 14:02:02 localhost kernel: usb 1-2: Product: USB2.0 WLAN
Jun 27 14:02:02 localhost kernel: usb 1-2: Manufacturer: ATHER
Jun 27 14:02:02 localhost kernel: usb 1-2: SerialNumber: 12345
Jun 27 14:02:02 localhost kernel: cfg80211: Calling CRDA to update world regulatory domain

.
.

Now run the following to see what name the system has provided the USB Wireless stick:

# ifconfig -a

followed by:

# ifconfig wlan1 (More often it will be wlan0)

for more details.  If the USB Wireless stick is seen, we can proceed to the next step.  The next item to do is to run:

# iwlist scanning

to list all available networks in your area (At least one should be listed – yours).  Note, some will not have an SSID and if you have followed our router configuration above and prevented SSID broadcasts, the network name will be blank.  This is confirmation that your Wireless USB Stick is not only working correctly but also can see other networks in the area.

4 Create a configuration file for the WAN USB Wireless adapter you identified in STEP 3.

Create a file for the card with information similar to the following.  If your device is named wlan1 use that in the file name ifcfg-<CARD NAME>. (ie ifcfg-wlan0 if your device name is wlan0)

# vi /etc/sysconfig/network-scripts/ifcfg-wlan1
# cat /etc/sysconfig/network-scripts/ifcfg-wlan1
DEVICE=wlan1
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.0.3
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
HWADDR=00:15:8B:FC:15:DA
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
NM_CONTROLLED=no

DNS1=192.168.0.1
DNS2=192.168.0.1
#

Note also that your IP may be different and you if you prefer to use DHCP, you could set BOOTPROTO=DHCP instead of specifying the rest of the information.  The DNS and GATEWAY would be the IP address of your router.

5 Restart the network service.

Issue:

# service network restart

The network device should now be configured with the general settings but you should still not be able to connect wirelessly to your router.  For this we will need to setup proper WPA2-PSK + AES authentication below.

 

6 Configure WPA Supplicant conf[iguration] file if you don't already have one.

Next, we will configure the WPA Supplicant config file, if you don't already have one: 

# cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel

network={
    ssid="MySecretNetwork"
    scan_ssid=1
    psk="MySecretNetworkKey"
    key_mgmt=WPA-PSK
}

#

In case you already have the conf file, you should add the items in green to it.  This represents the definitions and your credentials for the network you wish to connect with using your Wireless USB Stick.

PSK is the key you choose when configuring your wireless router.  It should be private and known by you only.

SSID is the wireless network name under which connections will be made. 

IMPORTANT: The above file should have the following permissions (ie accessible to the superuser user ID root):
262906 -rw——- 1 root root 160 Jun 28 23:13 /etc/wpa_supplicant/wpa_supplicant.conf

If you are not already root, you may need to perform the above command through sudo.  You can get more information on sudo through man sudo.

7 Bind WPA Supplicant to the interfaces you will use.

Next configure WPA Supplicant for the interfaces on which you wish to apply the WPA2 keys and credentials on:

# cat /etc/sysconfig/wpa_supplicant
# Use the flag "-i" before each of your interfaces, like so:
#  INTERFACES="-ieth1 -iwlan0"
INTERFACES="-iwlan0 -iwlan1"

# Use the flag "-D" before each driver, like so:
#  DRIVERS="-Dwext"
DRIVERS="-Dwext"

# Other arguments
#   -u   Enable the D-Bus interface (required for use with NetworkManager)
#   -f   Log to /var/log/wpa_supplicant.log
#   -P   Write pid file to /var/run/wpa_supplicant.pid
#        required to return proper codes by init scripts (e.g. double "start" action)
#        -B to daemonize that has to be used together with -P is already in wpa_supplicant.init.d
OTHER_ARGS="-u -f /var/log/wpa_supplicant.log -P /var/run/wpa_supplicant.pid"
#

Save the file.

8 Restart the WPA Supplicant tool.

Restart the wpa_supplicant service in this manner:

# service wpa_supplicant restart
#

9 Ping your router and some external sites to verify that your network is working.

The command to use is:

# ping 192.168.10.1 (Or what the IP of your router is)

IMPORTANT:
Note that the above command will not have instant effect.  The service will now attempt to connect to the network specified in the config file, which may take a few minutes.

If you ping your router you may receive Destination Host Unreachable messages for a while.  After that the ping will work but pinging outside domain names may not work for a few more moments.  This is normal, as this delay is often seen early on when the Wireless USB Stick is initialized and connect to a wireless network.

 

 

 

There is a Linux utility called NetworkManager that aims to automate this but unfortunately in my experience this utility left me disconnected far more times then it got me connected even on entirely clean and freshly installed systems.  (The utility is not yet fully WPA2 ready as of this writing though presumably success stories do exist.) With my Wireless USB Stick setup to my router configuration, it was something gratifying indeed to watch the FIFA World Cup 2010 Games on my Linux HTPC center.

An alternative to the above that I haven't tried yet is Wicd.  Though I haven't tried this utility, presumably it does come recommended.

If you run into issues, the previous article Linux Networking: device eth0 does not seem to be present, delaying initialization has some additional debugging techniques you can use that also apply to WLAN cards.

Cheers!
TK

2 Responses to “Linux Wireless Networking Step by Step HowTo”

  1. [...] Linux Bonding This is a simple howto tutorial for creating and bonding three interfaces, a wireless one (wlan0), one RealTek based GIGe cabled NIC (eth0) and another alternate Intel based GIGe NIC (eth1).  [...]

  2. [...] and wlan0 This is a simple howto tutorial for creating and bonding three interfaces, a wireless one (wlan0), one RealTek based GIGe cabled NIC (eth0) and another alternate Intel based GIGe NIC (eth1).  [...]

Leave a Reply

 

     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License