Suffix

Published by Simon Schoeters

Configuring a wireless network adapter on Ubuntu

I installed Ubuntu Server on an older machine at the office recently. We only have WiFi access, no ethernet, and the machine does not have a wireless chip. I got a D-Link WiFi USB adapter and plugged it in. Fine, but now, how do I tell Ubuntu to use the newly installed wireless adapter when you only have a CLI and no GUI?

Easy… well, not exactly, but it works.

Detecting the USB adapter

Let's first check if the machine detected the USB adapter. Run lsusb to list the USB devices the machine knows about:

$ lsusb
Bus 002 Device 003: Fitipower Integrated Technology Inc
Bus 002 Device 002: Intel Corp. Integrated Rate Hub
Bus 002 Device 001: Linux Foundation 2.0 root hub
Bus 001 Device 004: D-Link Corp.

There it is, our D-Link Corp. wireless USB adapter. Nice.

Naming the adapter

Now we need to find the USB device's logical name, the name we can use to refer to it. Meet lshw.

$ lshw -C network
*-network DISABLED
   description: Wireless interface
   physical id: 2
   bus info: usb@1:1.6
   logical name: wlan0
   capabilities: ethernet physical wireless
   configuration: broadcast=yes driver=rt2800usb driverversion=4.4.0-62-generic firmware=0.29 ip=x.x.x.x link=yes multicast=yes wireless=IEEE 802.11abgn

Look for a device with a logical name starting with a 'w' (for wireless) and take note of it's name.

Manual connection

We now we have a USB device and we know how to address it. Let's try to manually connect to a wireless network, make sure it's running first:

$ ifconfig wlan0 up

We'll use wlan0 as a generic device name here but you'll need to replace it with the logical name you found in the previous step.

Now connect to your wireless network:

$ wpa_passphrase <ssid> > wlan.config

It looks like the program hangs but it's simply waiting for you to give it the password to access the wireless network. Enter the password and press enter, it will create a wlan.conf file in the same directory containing the password and network name.

Connect to the network:

$ wpa_supplicant -Dwext -i wlan0 -c wlan.conf -B

There won't be a lot to do without IP address so let's ask our router to give us one:

$ dhclient -r
$ dhclient wlan0

You should now be connected with the router. Check if you can see the internet:

$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=42 time=16.4 ms

Persist the config

This is all fine… until you reboot and need to do the whole thing over again. Not optimal. It would be wise to store this somewhere so Ubuntu can reconnect to this network after a reboot. Let's use what we learned above and save that in a file. Open the /etc/network/interfaces file and add the following:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
wpa-ssid <ssid>
wpa-psk <password>
gateway 192.168.0.1
dns-nameservers 8.8.8.8 192.168.0.1

You'll need to replase the wlan0 with the logical name you found ealier and 192.168.0.1 with the address of your router of course. Once done take down the interface and bring it back up:

$ ifconfig wlan0 down
$ ifconfig wlan0 up

Still connected? Great, the internet awaits you.