HowTo:Connecting to a wireless network via command line
23 01 2008 This guide is only intended for those who implement WEP /WPA-PSK /WPA2-PSK encryptions
Before we begin the actual guide, a few preliminary things on the agenda:
Find your wireless card’s Interface Name; you must know the proper interface of the wireless connection. To find this you can use the lshw command Which lists certain hardware details. Since you only want to discover network interfaces you find that by executing the following command:
lshw -C network
the flag -C displays the alias for the given class of the hardware. I choose it over ‘lspci/’lsusb” as it prints me a more accurate description.You may see multiple interfaces, find the one that parallels the wireless device in question.
Also make sure you have the configured your wpa_supplicant. The package, look here: http://hostap.epitest.fi/wpa_supplicant/
And here’s my output:
*-network
description: Wireless interface
physical id: 1
logical name: wlan0
serial: 00:17:3f:3c:b8:02
capabilities: ethernet physical wireless
configuration: broadcast=yes driver=ndiswrapper+netmw245 driverversion=1.45+Belkin,08/30/2006,1.0.1.8 ip=10.10.10.3 link=yes multicast=yes wireless=IEEE 802.11gYes, the dreaded Belkin pre-N adapter using poorly written marvel chipset drivers, netmw254 being one of them. Currently using the g specification since I returned the corresponding Belkin route. In any event, I just should get back to topic.For a WEP Connection(assumed you have your ASCII password or 64-bit/128-bit hex key)
To initiate connectivity you must execute the following commands in command line
sudo ifconfig <logical name> down[<<this brings down the interface for the specified interface>>]
sudo dhclient -r <interface/logical name>[<<Release IP address akin with specified interface>>]
now with the IP address released we bring up the interface
sudo ifconfig <logical name> up[<<this brings up the interface for the specified interface>>]
Now the ESSID/Password entry, commands are as follows:
sudo iwconfig <logical name> essid "essid_must_be_entered_in_quotes"
Now for the ASCII password entry or hex key
sudo iwconfig <interface> key 's:ASCII KEY'[<< discern the s: prefix as it is needed, do not use quotes>>]
or
sudo iwconfig <interface> key HEXKEY
Now we specify the mode, by default my infrastructure mode is ‘managed’,but the modes aviable managed (default), ad-hoc or master. In managed mode, it forces the wireless to attempt and connect to the specified ESSID and nothing else.
sudo iwconfig <interface> mode Managed[<< ah-hoc and master is also aviable>>]
Now we request an IP address from our DNS server
sudo dhclient <logical name>Same story with WPA-psk/WPA2-psk, just make sure you configure wpa_supplicant properly in /etc/wpa_supplicant.conf
In some cases you might need to run wpa_supplicant.conf. Also if you’re
sudo wpa_supplicant -w -D<drivername> -i<interface> -c/etc/wpa_supplicant.confBy doing this you are asking wpa_supplicant to wait for the interface to be added, if needed…Customarily,wpa_supplicant will exit itself if the interface is not present
Also it specifies the name of the driver and the interface to listen on.Once all is executed it will append a path to the wpa_supplicant config file.
The value listed here is dependent on the driver you have installed.Typing
man wpa_supplicantwill give you options for avilable drivers, just for a quick reference.
ndiswrapper=wext (use wext and not ndiswrapper despite what man page documentation might recommend)
In some instances, an atheros chip set would most likely have the madwifi(assuming you have it installed)
My input was:
sudo wpa_supplicant -w -Dwext -iwlan0 -c/etc/wpa_supplicant.confUsually the output of a successful connection results in something like this. Here’s my output
body
{
font-family: Monospace, monospace;
font-size: 10pt;
}
.style_0
{
color: #000000;
background-color: #ffffff;
}larry@larry-desktop:~$ sudo dhclient wlan0
There is already a pid file /var/run/dhclient.pid with pid 134993416
Internet Systems Consortium DHCP Client V3.0.4
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/Listening on LPF/wlan0/00:12:17:35:17:10
Sending on LPF/wlan0/00:12:17:35:17:10
Sending on Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 7
DHCPOFFER from 10.10.10.3
DHCPREQUEST on wlan0 to 255.255.255.255 port 67
DHCPACK from 10.10.10.3
bound to 10.10.10.3 – renewal in 289233 seconds.
It attained the IP address of 10.10.10.3 in my output.
This guide was heavily referenced from kevdog from ubuntu forums
Cheers! You never know when the GUI might fail you.
-Larry























You’re my Linux savior..
You get to my in my favorites folder
Thanks, this totally saved me when I borked my xorg.conf file. You have a special place in my feed reader now.
I tried about 10 other methods, from various web sites, of getting a wireless interface connected from the command line. None worked, but luckily I found your page and had working on the first try. Excellent guide.