Linux.com

Home Learn Linux Linux Tutorials How to Configure Wireless on Any Linux Desktop

How to Configure Wireless on Any Linux Desktop

 

If you are a mobile Linux user one of the first things you need to do is to connect that mobile device to a wireless access point. By default, the standard Wi-Fi tools for the Linux desktops are straight-forward and reliable. That of course presumes you are using the standard desktops (GNOME or KDE). But what happens when you opt for a different desktop such as E17 or Fluxbox? Or what if the "default" standards aren't flexible enough or feature-rich enough for your needs. In those instances you need to take a look at a different toolset for connecting you to a wireless access point.

What are your options? You could go for a GUI or command the command line. I would like to offer options for both GUI and command line with the help of Wifi Radar and ifconfig.

Assumptions

I will assume that you do have wireless hardware that does work in Linux. If you have found yourself with a wireless card that does not seem to work you might consider installing the latest Ubuntu and enabling the proprietary driver for your device. Most often this will have your wireless working much quicker than trying to go the ndiswrapper route.

I will also assume you have both SSID and the authentication key for your wireless connection, otherwise you probably wouldn't be attempting to make this connection in the first place, right?

Wifi Radar

For many, Wifi Radar is a Python/PyGTK2 application that offers quite a bit more features and flexibility than the average tool (it will even speak the status of your connection - when connecting or disconnecting - so you know, without looking, if you are connected.) Wifi Radar is easy to install as well as use.

Wifi Radar network listing Since Wifi Radar is found in most all default distribution repositories, the installation is as simple as installing any Linux application. Just open up your Add/Remove Software tool and install. Once Wifi Radar is installed you can find it in Applications > Internet. When you start up Wifi Radar it will auto scan for any wireless networks and will display the available access points for you (see Figure 1). To connect to a network just select the network and click Connect and you will be prompted for a password (if the access point is set up to require one).

Wifi Radar general configuration options You can also dig deep within the preferences of WiFi Radar. If you do this, do it with caution. Much of the configurations are commands that are set up to work with the wireless networking system and many of these commands are fairly complex. What options you can safely tinker with are in the General tab. In this tab (see Figure 2) you can set Wifi Radar to auto-detect your wireless device (which is not set by default) and you can also set the Speak option. By default the Speak option uses the say command which is buggy at best. Instead, reconfigure this to use the espeak command. Once you do this the Speak option will work.

You will notice that WiFi Radar does not have a system tray icon. Don't worry - when you close the application you will not be disconnected from your network.

Now let's take a look at setting up a wireless connection from the command line.

Command Line

Believe it or not, this isn't as challenging as it might seem. I will demonstrate how this is done on a Ubuntu machine. For other distributions you might have to alter the location of scripts or the name.

What you will need, in order to be able to establish this connection, are the following:

  • ifconfig: Enable your wireless device.
  • iwlist: List the available wireless access points.
  • iwconfig: Configure your wireless connection.
  • dhclient: Get your IP Address via dhcp.
  • wpa_supplicant: For use with WPA authentication.

Make sure you have all of the above tools on  your computer before you continue. To test for this tools you can, from within your terminal window, issue the commands:

  • which ifconfig
  • which iwlist
  • which iwconfig
  • which dhclient
  • which wpa_supplicant

You should see the path where each tool is installed. If you receive an error that a command is not installed you will need to install it. This should not be the case, since these are standard tools that are required for wireless networking.

Let's take a look at how this is done when you are connecting to a non-WPA authentication-based wireless network.

Now that you have confirmed they are installed start off with the command:

ifconfig wlan0 up

Where wlan0 is the name of your wireless device (this is most often the default). The above command will bring your wireless device up so it is ready to use. The next phase is to scan for any wireless access points with the command:

iwlist wlan0 scan

From the output of the scan you should see a line (or lines) like:

ESSID: "NETWORK_NAME"

Where NETWORK_NAME is the name of an available wireless network.

Now that you have your network name (and you know it's available) you can connect to that network with the command:

iwconfig wlan0 essid NETWORK_NAME key WIRELESS_KEY

Where NETWORK_NAME is the name of the network you want to connect to and WIRELESS_KEY is the security key for that network. NOTE: The iwconfig command defaults to HEX values for wireless keys. If you need to use ascii you have to prepend the "s" prefix to your key like so:

iwconfig wlan0 essid NETWORK_NAME key s:WIRELESS_KEY

With your connection made, you now have to get an IP address for your machine using the dhclient command like:

dhclient wlan0

Simplify the Process

Naturally you do not want to have to issue all of those command in order to bring up a wireless network. You can make this a lot easier by creating a script to handle the task. A possible script might look like this:

#! /bin/bash
ifconfig wlan0
iwconfig wlan0 essid NETWORK_NAME key WIRELESS_KEY
dhclient wlan0

Where NETWORK_NAME and WIRELESS_KEY are unique to the network you are connecting to. Save that file with the name wireless_up and give it executable permissions with the command chmod u+x wireless_up and you are ready to use that file to bring up your wireless. You can even move that file to /usr/local/bin so the command is global. All you would have to do to bring up your wireless connection is issue the command wireless_up and you're ready to go.

WPA

For WPA-based networks you will need to take a different approach. Do the following:

1. Issue the command wpa_passphrase SSID PASSWORD (Where SSID is your network ID and PASSWORD is your wireless password). This will generate a psk string that you will use in the configuration file.

2. Edit the /etc/wpa_supplicant.conf file to reflect:

Network={

   ssid=SSID

   psk=PSK

}

Where SSID is the actual ID of your wireless network and PSK is the string generated by the wpa_passphrase command.

3. Run the wpa_supplicant daemon with the command:

wpa_supplicant -B -i INTERFACE -DWext -c /etc/wpa_supplicant.conf

Where INTERFACE is the name of your wireless interface.

4. Now make sure you are associated with your network with the command iwconfig INTERFACE (Where INTERFACE is the name of your wireless interface).

5. Get an IP address with the command: dhclient INTERFACE (Where INTERFACE is the name of your wireless interface).

You should now be on the wireless network.

You can automate this by creating an entry in /etc/network/interfaces like this:

auto INTERFACE

iface INTERFACE inet dhcp

   pre-up wpa_supplicant -Bw -Dwext -i INTERFACE -c /etc/wpa_supplicant.conf

  post-down killall -q wpa_supplicant

Where INTERFACE is the name of your wireless interface. 

Final thoughts

There are plenty of ways to connect to a wireless network in Linux. So long as your hardware is working, you shouldn't have a problem finding a tool that will help you get connected. Whether it's a GUI or command line, Linux has you covered on the wireless front.

 

Comments

Subscribe to Comments Feed
  • MikieD12 Said:

    ok say the linux box got it seen with software and connects you then you be hanging out say at Micky D's (McDonalds) and they got this stupid sign in web page you got a hit first before you can get into the internet and the Linux sys isn't looking for that but a direct connect to the internet with no page to stop you first how you do set it up to let you open up the browser like in windows and have it go to that page by just typing in any web address and it sends it to the McDondals page first then opens up the internet to use?

  • Dann Said:

    There is a typo in one of your wpa_supplicant commands. In the first instance, it says "-DWext", but that fails and has to be changed to "-Dwext" to complete without error. (in command #3 in WPA section)

  • kunal Said:

    I HAVE INSTALLED KALI THRGH VM WARE BUT IT DOES NOT SHOW ANY WIFI CONNECTION SO I CANT USE FERN WIFI CRACKER PLZ...... HELP ME IN THIS CONTEXT....... contact me through my email only sir....

  • Chuck Said:

    You missed step #1: getting the device driver loaded. I wouldn't criticize like this but you are the #1 google result for "linux wireless howto".

  • Ati Said:

    Thanks for the guide. I followed. the guide for the wpa-based networks. I issued my SSID and the wifi password (which i understand is just the normal decimal pass that I once set and had difficulty remembering it!)- the passphrase generated a psk which I then used in the wpa_supplicant.conf. when I run: wpa_supplicant -B -i INTERFACE -DWext -c /etc/wpa_supplicant.conf I get: Passphrase must be 8...63 charactters I do not understand how to get it right. Many thanks, Ati

  • Tim Said:

    When I do this I get "operation not supported" then core dump.'' Ubuntu 12.04. lwhw and strace extracts follows *-network description: Wireless interface product: AR922X Wireless Network Adapter vendor: Atheros Communications Inc. physical id: 0 bus info: pci@0000:04:00.0 logical name: wlan0 version: 01 serial: 64:66:b3:55:07:50 width: 32 bits clock: 66MHz capabilities: pm bus_master cap_list ethernet physical wireless configuration: broadcast=yes driver=ath9k driverversion=3.8.0-29-generic firmware=N/A latency=168 link=no multicast=yes wireless=IEEE 802.11bgn resources: irq:19 memory:db800000-db80ffff bind(4, {sa_family=AF_NETLINK, pid=0, groups=00000001}, 12) = 0 ioctl(3, SIOCGIFFLAGS, {ifr_name="wlan0", ifr_flags=IFF_UP|IFF_BROADCAST|IFF_MULTICAST}) = 0 ioctl(3, SIOCSIWPMKSA, 0x7fffbd7ab040) = -1 EOPNOTSUPP (Operation not supported) ioctl(3, SIOCSIWMODE, 0x7fffbd7ab040) = 0 ioctl(3, SIOCGIWRANGE, 0x7fffbd7ab0a0) = 0 ioctl(3, SIOCGIWMODE, 0x7fffbd7ab030) = 0 ioctl(3, SIOCSIWAP, 0x7fffbd7aafe0) = 0 ioctl(3, SIOCSIWESSID, 0x7fffbd7aafe0) = 0 access("/proc/net", R_OK) = 0 access("/proc/net/unix", R_OK) = 0 socket(PF_FILE, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5 ioctl(5, SIOCGIFINDEX, {ifr_name="wlan0", ifr_index=3}) = 0 close(5) = 0 socket(PF_FILE, SOCK_DGRAM|SOCK_CLOEXEC, 0) = 5 ioctl(5, SIOCGIFINDEX, {ifr_name="wifi0", ???}) = -1 ENODEV (No such device) close(5) = 0 sendto(4, "-\0\0\0\23\0\1\0\1\0\0\0\0\0\0\0\0\0\0\0\3\0\0\0\0\0\0\0\0\0\0\0"..., 45, 0, NULL, 0) = 45 ioctl(3, SIOCSIWAUTH, 0x7fffbd7ab0a0) = 0 socket(PF_PACKET, SOCK_DGRAM, 36488) = 5 ioctl(5, SIOCGIFINDEX, {ifr_name="wlan0", ifr_index=3}) = 0 bind(5, {sa_family=AF_PACKET, proto=0x888e, if3, pkttype=PACKET_HOST, addr(0)={0, }, 20) = 0 ioctl(5, SIOCGIFHWADDR, {ifr_name="wlan0", ifr_hwaddr=64:66:b3:55:07:50}) = 0 ioctl(3, SIOCSIWENCODEEXT, 0x7fffbd7ab130) = 0 ioctl(3, SIOCSIWENCODEEXT, 0x7fffbd7ab130) = 0 ioctl(3, SIOCSIWENCODEEXT, 0x7fffbd7ab130) = 0 ioctl(3, SIOCSIWENCODEEXT, 0x7fffbd7ab130) = 0 ioctl(3, SIOCSIWENCODEEXT, 0x7fffbd7ab130) = -1 EINVAL (Invalid argument) dup(2) = 6 fcntl(6, F_GETFL) = 0x1 (flags O_WRONLY) close(6) = 0 write(2, "ioctl[SIOCSIWENCODEEXT]: Invalid"..., 42ioctl[SIOCSIWENCODEEXT]: Invalid argument ) = 42 ioctl(3, SIOCSIWENCODEEXT, 0x7fffbd7ab130) = -1 EINVAL (Invalid argument) write(2, "ioctl[SIOCSIWENCODEEXT]: Invalid"..., 42ioctl[SIOCSIWENCODEEXT]: Invalid argument ) = 42 ioctl(3, SIOCSIWAUTH, 0x7fffbd7ab1b0) = -1 EOPNOTSUPP (Operation not supported) ioctl(3, SIOCSIWPMKSA, 0x7fffbd7ab1a0) = -1 EOPNOTSUPP (Operation not supported)

  • fixitman Said:

    I "assume" most people who read this, had no idea what an SSID Key or whatever you were talking about, so this article didn't help them at all.

  • fixitman Said:

    Maybe if Linux users didn't all want to do everything in a DOS window, green text on a black screen, and just set up an icon on tthe taskbar or available from the windows start menu, and explained how to click on start/programs to install an .exe to handle using wireless, it would be better. There is no discoverable SSID key on my router, it simply broadcasts one automatically, and any Windows device can easily connect to it with the password. Apparently in Linux you have to have some magic wand to wave over the text-only files to make them work instead of having a simple icon that lets you connect. Frustrated. Back to windows XP. WHY do they change crap all the time.

  • Robert Said:

    you are an ass, if linux had any brains they would provide wifi ready distros but this is linux the stupidest os on the market

  • Andy Canfield Said:

    Quote: "So long as your hardware is working, you shouldn't have a problem finding a tool that will help you get connected." Yeh, find a tool on the Internet, which you can't get to! At one point my Ubuntu rescue boot had an Internet connection (good hardware) but normal boot could not (bad software). Solution: Save a copy of this web page on your hard disk today, while it's accessible. And download all the tools BEFORE you are cut off.

  • LearningLinux Said:

    I tried iwconfig wlan0 essid NETWORK_NAME key WIRELESS_KEY and even iwconfig wlan0 essid NETWORK_NAME key s:WIRELESS_KEY . but it is returning like invalid arguement for the my wireless key .

  • ciprianhanga Said:

    Posting this and then not responding to any of the readers' questions. Way to go, champ. Real professional.

  • yyykang Said:

    Thanks for your helps. I've just fixed my wireless.

  • Adrian Said:

    Finally got minimal server wireless connected! Learned a lot! Thanks.


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board