I installed Ubuntu Server on an older machine at the office. The office only has a WiFi network, no Ethernet, and the computer does not have a wireless chip built-in. I bought a D-Link WiFi USB adapter and plugged it in. Great, but how to tell Ubuntu to use the newly installed wireless adapter via the terminal, without a GUI?
Let’s configure the wireless adapter via the command-line interface. Useful for computers without a GUI like Ubuntu Server, but this will also work for say, a Raspberry Pi over SSH or any other Linux machine.
Detect the Wireless USB Adapter
Check if the machine detected the USB adapter first. Run lsusb to list the USB devices the computer knows about:
There it is, our D-Link Corp. wireless USB adapter.
Find the Adapter Name
Now we need to find the USB device’s logical name, the name we can use to refer to it. Meet lshw.
Look for a device with a logical name starting with a 'w' (for wireless) and take note of its name: ‘wlan0’. Notice the WiFi interface is currently disabled.
Manually Enable the Network Connection
We now have the USB device’s logical name and know how to address it. Let’s manually connect to a wireless network but make sure it’s turned on first:
We use ‘wlan0’ as a generic device name here but remember to replace it with the logical name found in the previous step.
Time to connect to the wireless network, replace the SSID with your wireless network name. Use nmcli dev wifi for a list of available networks if you don’t know the network name.
It might look like Ubuntu hangs but it’s waiting for you to type the password for the WiFi network. Enter the password and press enter, a ‘wlan.conf’ file will be created in the same directory with the network name and matching password. Use this file to connect to the network:
There won’t be a lot to do without an IP address so ask the router for one:
You are now connected to your local network or hotspot. Check if your Ubuntu box can reach out to the internet:
Persist the Configuration for Ubuntu
This is all fine… until you reboot and do the whole thing over again. It would be wise to store this somewhere so Ubuntu knows how to enable the network connection after a reboot. Add the following configuration settings to the /etc/network/interfaces file.
Replace the wlan0, ssid, and password with your own and replace 192.168.0.1 with the IP address of the router. Save the config, disable the wireless interface, and turn it on once more.
Still connected? Great, the internet awaits you.