For the past few years, I have been using my trusty D-Link DWA-125 wireless dongle on my PC to connect to a wireless network. I have written about how to connect to WiFi via the command line but that was for unsecured networks. Recently, I've been fumbling around with Debian and did a minimal netinstall (to build it up with a GUI desktop) -- sort of a "from scratch" installation, like how Arch Linux installation is done. Since netinstall without a desktop environment drops you off at the CLI on first boot, I needed to find a way to connect to a WiFi network without the use of GUI network managers.
You will need to know the interface name to use. In my case, it's `wlan0`. It also needs to be activated (or "up"). It also goes without saying that you need to be `root` to do these things.
# ip link set dev wlan0 up
Check if the interface `wlan0` is indeed up. If it is up, it should give some output regarding the status of the interface.
# iwconfig wlan0
Now it's time to scan for SSIDs or WiFi access points. Of course, if you know what the SSID is, you don't need to do this step.
# iwlist wlan0 scanning | grep -i ESSID
To connect, `wpa_supplicant` will be used. In order to use it, a configuration file needs to be made using `wpa_passphrase`. In this example, I will use ESSID name of "ssid" and passphrase of "passphrase" (substitute accordingly). Note that you type the command `wpa_passphrase ssid > ssid.conf` and press ENTER ONCE! It may seem that the command is hanging, but when the cursor gets to the next line, just type in the passphrase (password) for connecting to the WPA2-Personal network. This will then create a file named "ssid.conf".
# wpa_passphrase ssid > ssid.conf passphrase
Now, using the configuration file, we can connect to the wireless network. Options: -B to run in background mode, -i for the interface, -c for the configuration file and -D for the driver. Make sure you are executing this in the directory where the "ssid.conf" file was created.
# wpa_supplicant -B -iwlan0 -cssid.conf -Dwext
Once connection (or handshake?) is established, get an IP via DHCP (I don't know how to do this for static IPs, sorry).
# dhclient wlan0
If everything goes fine and dandy, you are now connected to the Internets! You can test it using `ping` command. If it returns received packets, then your connected.
# ping -c 5 www.google.com
You can then proceed to whatever it is you need to do.
If you find something wrong, inadequate or have suggestions to make this guide better, let me know in the comments.
No comments:
Post a Comment