Connect to a wireless network via the command line

  • Sumo

Connect to a wireless network via the command line

Sometimes you decide that you don’t want to use any GUI to connect to your wireless network. Especially when it doesn’t seem to work correctly if at all.

One of the main benefits of Linux and any other Unix based operating system is its ability to empower users to do things on their own.
So tonight when the latest Ubuntu updates broke my laptop’s wireless, I decided to write a little script to fix it.

So I decided to connect to my wireless network via using the command line alone.
This also was the kick in the butt I needed to get my Ubuntu server up and running on a wireless network.

You will need to know the following:

  • ifconfig
  • iwlist
  • iwconfig
  • dhclient

Find your network interface, unless you know it (my laptop is always wlan0)


if you don’t see your network interface but you know it by hard try this:

ifconfig NETWORK_ID up

Find the network you want to connect to:

iwlist network_interface scan

Let’ configure your network card

iwconfig NETWORK_ID essi "NAME" key s:password


iwconfig NETWORK_ID essi "NAME" key hex_password

Where NAME is the wireless network you want to connect to.

Now all we need is to get the IP from the DHCP server:

dhclient network_interface

You could have it all in a script:

ifconfig wlan0 up
iwconfig wlan0 essi "$1" key s:$2
dhclient wlan0

Save it as wireless_up and then chmod a+x wireless_up.
Now you just need to either do ./wireless_up network_id my_password or bash wireless_up network_id my_password in the same directory.
You could also move the script to a global location (say for example /usr/sbin) or add the directory where you have it as part of your local path.
The choice is yours.

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Author: Luis Tineo

Husband, Father, performance improvement junkie, biker and video gamer, Linux user and in my day job I'm a Software Engineer at BuyerQuest.

Share This Post On