This tutorial would help you connect to a wireless router via the terminal, this could be very useful incase you use the ubuntu server and you want to connect to a wireless network. Also incase you want to automate something like to automate the connection to a wireless router at a specific time or whatever.So here's how this is done :

You need to know 4 things for this, im listing them here

1)MAC address of your wifi router
2)ESSID or name of your wifi network
3)Wireless (WEP) key which is like a password to connect to your wireless router
4)Your Wifi interface - This could be eth1,wlan0,ath0 etc..


So firstly in the Terminal(Applications->Accessories->Terminal) type sudo iwlist scanning you'll get something like this

lo Interface doesn't support scanning.

eth0 Interface doesn't support scanning.

eth1 Scan completed :
Cell 01 - Address: 15:51:3C:27:74:J8
ESSID:"STAR341"
Mode:Managed
Frequency:2.462 GHz (Channel 11)
Quality:5/5 Signal level:-29 dBm Noise level:-21 dBm
Encryption key:on
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
12 Mb/s; 24 Mb/s; 36 Mb/s; 9 Mb/s; 18 Mb/s
48 Mb/s; 54 Mb/s
Cell 02 - Address: 46:6G:73:71:K6:C9
ESSID:"KNIGHT111"
Mode:Managed
Frequency:2.437 GHz (Channel 6)
Quality:1/5 Signal level:-87 dBm Noise level:-15 dBm
Encryption key:on
Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s
12 Mb/s; 48 Mb/s

pan0 Interface doesn't support scanning.


So from this output you can get to know the first 3 required stuff

1)MAC address this is the Address value as shown in the output say 15:51:3C:27:74:J8 it would be different for your wifi router
2)ESSID Name - This is mentioned under ESSID for me there are two networks STAR341 and KNIGHT111 which are two different wifi networks
3)Wifi Interface - In my case it is eth1 as if you look at my output , the other interfaces like eth0,lo and pan0 do not support scanning

Now, all you need to know is the WEP key which you should be knowing, incase you are trying to connect to an open network, then no problem , you dont need it at all!!

THE CONNECTING PART

Step 1 : In the already opened Terminal type the following commands one after the other

NOTE : The commands are based on my setup. Stuff like MAC address,ESSID etc would be different in your case , you need to note down yours!!This is the info for my wireless router STAR341

1)MAC address : 15:51:3C:27:74:J8
2)ESSID : STAR341
3)Wifi Interface : eth1
4)WEP key : 123456789 (optional depends on whether your network is an OPEN network without any key or not)

The commands are :

sudo iwconfig eth1 ap 15:51:3C:27:74:J8
sudo iwconfig eth1 essid STAR341
sudo iwconfig eth1 key s:123456789
- THIS COMMAND IS OPTIONAL DEPENDING ON WHETHER YOUR NETWORK HAS A KEY OR NOT
sudo dhclient eth1

The last command is to get an ip address via DHCP from your wifi router!!

NOTE : Do change those values according to your network setup!!

0 comments

Post a Comment