How To Connect To The Internet Using The Linux Command Line

Linux Terminal Internet Connection
Linux Terminal Internet Connection.


This guide shows how to connect to the internet via a WI-FI network using the Linux command line.

If you have installed a headless distribution (I.E, a distribution that doesn’t run a graphical desktop) then you won’t have network manager tools to help you connect. It may also be the case that you have accidentally deleted key components from your desktop or you have installed a distribution that has a bug and the only way to connect to the internet is via the Linux terminal.

With access to the internet from the Linux command line you can use tools such as wget to download web pages and files. You will also be able to download videos using youtube-dl. The command line package managers will also be available for your distribution such as apt-get, yum and PacMan. With access to package managers you have all you need to install a desktop environment should you require one.

Determine Your Wireless Network Interface

From within the terminal enter the following command:


You will see a list of network interfaces.

The most common wireless network interface is wlan0 but can be other things such as in my case it is wlp2s0.

Turn The Wireless Interface On

The next step is to make sure the wireless interface is turned on.

Use the following command to do this:

sudo ifconfig wlan0 up

Replace the wlan0 with the name of your network interface.

Scan For Wireless Access Points

Now that your wireless network interface is up and running you can search for networks to connect to.

Type the following command:

sudo iwlist scan | more

A list of available wireless access points will appear. The results will look something like this:

Cell 02 - Address: 98:E7:F5:B8:58:B1


Frequency:2.437 GHz (Channel 6)

Quality=68/70 Signal level=-42 dBm

Encryption key:on


Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s

24 Mb/s; 36 Mb/s; 54 Mb/s

Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s



Extra: Last beacon: 4ms ago

IE: Unknown: 000E484F4E4F525F504C4B5F45324346

IE: Unknown: 010882848B962430486C

IE: Unknown: 030106

IE: Unknown: 0706434E20010D14

IE: Unknown: 200100

IE: Unknown: 23021200

IE: Unknown: 2A0100

IE: Unknown: 2F0100

IE: IEEE 802.11i/WPA2 Version 1

Group Cipher : CCMP

Pairwise Ciphers (1) : CCMP

Authentication Suites (1) : PSK

IE: Unknown: 32040C121860

IE: Unknown: 2D1A2D1117FF00000000000000000000000000000000000000000000

IE: Unknown: 3D1606081100000000000000000000000000000000000000

IE: Unknown: 7F080400000000000040

IE: Unknown: DD090010180200001C0000

IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00

It all looks fairly confusing but you only need a couple of bits of information.

Look at the ESSID. This should be the name of a network which you want to connect to. You can also find open networks by looking for items that have the Encryption Key set to off.

Write down the name of the ESSID that you wish to connect to.

Create A WPA Supplicant Configuration File

The most common tool used to connect to wireless networks which require a WPA security key is WPA Supplicant.

Most distributions come with this tool pre-installed. You can test this out by typing the following into the terminal:


If you get an error saying the command cannot be found then it isn’t installed. You are now in a chicken and egg scenario whereby you need this tool to connect to the internet but can’t connect to the internet because you don’t have this tool. You can of course always use an ethernet connection instead to install wpasupplicant.

To create the configuration file for wpa_supplicant to use run the following command:

wpa_passphrase ESSID > /etc/wpa_supplicant/wpa_supplicant.conf


The ESSID will be the ESSID you noted down from the iwlist scan command in the previous section.

You will notice that the command stops without coming back to the command line.

Enter the security required for the network and press return.

To check that the command worked navigate to the .config folder using the cd and tail commands:

cd /etc/wpa_supplicant

Type the following:

tail wpa_supplicant.conf

You should see something like this:






Find The Name Of Your Wireless Driver

There is one more piece of information you need before connecting to the internet and that is the driver for your wireless network card.

To find this out type in the following command:

wpa_supplicant –help | more

This will provide a section called drivers:

The list will be something like this:


nl80211 = Linux nl80211/cfg80211

wext = Linux wireless extensions (generic)

wired = Wired Ethernet driver

none = no driver (RADIUS server/WPS ER)


Generally wext is a catchall driver which you can attempt to use if nothing else is available. In my case the appropriate driver is the nl80211.

Connect To The Internet

The first step to getting connected is running the wpa_supplicant command:

sudo wpa_supplicant -D<nameofdriver> -i<nameofnetworkinterface> -c/etc/wpa_supplicant/wpa_supplicant.conf -B

You should replace <nameofdriver> with the driver that you found in the previous section. The <nameofnetworkinterface> should be replaced with the network interface discovered in the section “Determine Your Network Interface”.

Basically this command is running wpa_supplicant with the driver specified using the network interface specified and the configuration created in the section “Create a WPA Supplicant Configuration File”.

The -B runs the command in the background so you get access to the terminal back.

Now you need to run this one final command:

sudo dhclient <nameofnetworkinterface>

That is it. You should now have an internet connection.

To test it type the following:


More From Us