Search

Ubuntu - Configure Wifi connexion thru Command line Tools

Contents[Hide]

dropcap-ubuntu-wifi

Nowaday, interface like Network manager makes wifi connexion setup a very simple task.

But in some specific cases (ubuntu server, ubuntu minimal media center, ...), you may need to setup you WEP or WPA wifi connexion directly from command line, without using network manager.

This article explains how to fully configure a WEP or WPA encrypted wifi network from a console terminal, using only command line tools.

It has been tested on Ubuntu Precise 12.04, but it should work on any modern Ubuntu or Debian flavored distro.

1. Collect Wifi adapter Informations

If not already installed, we have to install the wireless-tools and hwinfo packages :

# sudo apt-get install wireless-tools hwinfo

We can now easily determine the name of the wifi interface with the iwconfig command :

# iwconfig
lo no wireless extensions.

wlan0 IEEE 802.11abg ESSID:""
Mode:xxx Frequency:5.2 GHz Access Point: 00:xx:xx:xx:xx:xx
Bit Rate=xx Mb/s Tx-Power=xx dBm
...
eth0 no wireless extensions.

In this example, the wifi interface is named wlan0.

hwinfo tool will even give us more information about the wifi device capabilities and the module handling the device :

# hwinfo --netcard
...
27: PCI 1000.0: 0282 WLAN controller
[Created at pci.318]
Unique ID: y9sn.X4Ey7CeHgQ0
Parent ID: qTvu.bJAoDpzvG5F
SysFS ID: /devices/pci0000:00/0000:00:1c.1/0000:10:00.0
SysFS BusID: 0000:10:00.0
Hardware Class: network
Model: "Intel PRO/Wireless 4965 AG or AGN [Kedron] Network Connection"
Vendor: pci 0x8086 "Intel Corporation"
Device: pci 0x4229 "PRO/Wireless 4965 AG or AGN [Kedron] Network Connection"
SubVendor: pci 0x8086 "Intel Corporation"
SubDevice: pci 0x1001
Revision: 0x61
Driver: "iwl4965"
Driver Modules: "iwl4965"
Device File: wlan0
Features: WLAN
Memory Range: 0xe0000000-0xe0001fff (rw,non-prefetchable)
IRQ: 45 (5428877 events)
HW Address: 00:21:5c:8e:0f:a7
Link detected: yes
WLAN channels: 1 2 3 4 5 6 7 8 9 10 11 12 13 36 40 44 48 52 56 60 64 100 104 108 112 116 120 124 128 132 136 140
WLAN frequencies: 2.412 2.417 2.422 2.427 2.432 2.437 2.442 2.447 2.452 2.457 2.462 2.467 2.472 5.18 5.2 5.22 5.24 5.26 5.28 5.3 5.32 5.5 5.52 5.54 5.56 5.58 5.6 5.62 5.64 5.66 5.68 5.7
WLAN encryption modes: WEP40 WEP104 TKIP CCMP
WLAN authentication modes: open sharedkey wpa-psk wpa-eap
Module Alias: "pci:v00008086d00004229sv00008086sd00001001bc02sc80i00"
Driver Info #0:
Driver Status: iwl4965 is active
Driver Activation Cmd: "modprobe iwl4965"
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #19 (PCI bridge)

Here we get some very interesting informations about the wifi device :

  • it's name is wlan0 (we already knew it ...)
  • it is managed by the iwl4965 module
  • it can accept WEP 64bits, WEP 128bits, WPA AES (CCMP) and WPA TKIP encryption

2. Case of a WEP Network

2.1. Generate WEP key

In a WEP encrypted network, you can setup 2 different strengh of encryption :

  • 64 bit WEP code (a.k.a. 40 bit + init vector), represented as 10 hexadecimal string
  • 128 bit WEP code (a.k.a. 104 bit + init vector), represented as 26 hexadecimal string

So your WEP key should be exactly a 10 or 26 characters hexadecimal string to be valid.

You WEP key should be provided by your Wifi router or Access Point.

2.2. Configure network interface

Now that we have a valid WEP key, we should configure the wifi interface.

Edit /etc/network/interfaces to add :

/etc/network/interfaces

auto wlan0
iface wlan0 inet dhcp
wireless-essid your_network_ssid
wireless-key 0123456789ABCDEF0123456789

3. Case of a WPA Network

3.1. Generate WPA key

WPA-PSK uses pre-shared key as :

  • a passphrase of 8 to 63 ASCII characters
  • a 64 hexadecimal digits key

If a passphrase is used, the 256 bit key is calculated by applying the PBKDF2 key derivation function to the passphrase, using the SSID as the salt and 4096 iterations of HMAC-SHA1.

wpa_passphrase utility will generate a 256-bit pre-shared WPA key from your ASCII passphrase. It is provided by the wpa_supplicant package.

If not installed, first thing is to install it :

# sudo apt-get install wpasupplicant

We can now generate the key :

# wpa_passphrase your_network_ssid your_passphrase
network={
ssid="your_network_ssid"
#psk="your_passphrase"
psk=1f33b3cd4bd8a044ea958af749881bde774cf6a3f85d363f3f826c526ca468bf
}

3.2. Configure network interface

Now that we have the WPA key, we should configure the wifi interface.

Edit /etc/network/interfaces as root to add :

/etc/network/interfaces

...

auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-ssid your_network_ssid
wpa-psk 1f33b3cd4bd8a044ea958af749881bde774cf6a3f85d363f3f826c526ca468bf
# if your SSID is hidden, change value to 2
wpa-ap-scan 1
# type WPA for WPA1, RSN for WPA2
wpa-proto RSN
# type CCMP for AES, TKIP for TKIP
wpa-pairwise CCMP
# type CCMP for AES, TKIP for TKIP
wpa-group CCMP
# type WPA-PSK for shared key (most common), WPA-EAP for enterprise radius server
wpa-key-mgmt WPA-PSK

4. Connect to the Network

Now that your network is configured, the last step is to unload and reload the module in charge of the wifi interface.

The name of the module was previously given by the hwinfo command.

After that operation, the connexion should take place automatically.

# sudo rmmod iwl4965
# sudo modprobe iwl4965

You should now be connected to your wifi network.

Another possibility is to simply reboot the computer.

 

Hope it helps.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus