The Wayback Machine - https://web.archive.org/web/20240723232006/https://www.geeksforgeeks.org/connecting-to-the-internet-using-command-line-in-linux/
Open In App

Connecting to the Internet Using Command Line in Linux

Last Updated : 10 May, 2020
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

Many of the times you may use a Linux system that does not have a GUI after install and it needs an internet connection to set up a desktop environment, also you may use Linux servers without a GUI and you need to connect over a wireless network using the command line. Below you will see Steps to connect to a wireless network using the command line.

Determine your Network Interface

The first thing you need to do is determining your Wireless Interface, to do so give the following command:

iwconfig

This will list out all the active network interfaces, most of the time it will be a wlan0 for your wireless network but can be something other, depending on your hardware.

Turn on your Wireless Interface

Now you need to ensure that your network interface is up and working, to do so give the following command.

sudo ifconfig wlan0 up 

wlan0 is your network interface, make sure you change it if your one is different.

Scan for available wireless access points

Now you will need to scan for all the available Access points, to do so give the following command

sudo iwlist scan | more

where more will help you get systematic scroll as the list could be long and you do not want that some entries disappear and you cannot scroll up as you are working in the command-line interface. Look at the ESSID, that is the name of your wireless network. To find an open network just check items that show Encryption Key set to off.

Create a WPA supplicant configuration file

The most common and widely tool used is WPA supplicant, most of the distros have it in default, just give the command

wpa_passphrase

Now if you see any error you are in a deadlock situation as you cannot use this tool or it’s not installed. To create a configuration file for wpa_supplicant, run the following command:

wpa_passphrase ESSID > /etc/wpa_supplicant/wpa_supplicant.conf

Where ESSID will be your Access point name which you have noted from iwlist command, now after running the command your prompt is still not ended, now you need to type the security key of the Access point you need to connect to and press Enter and your prompt ends now.

After creating file check if the command worked, just give command:

cd /etc/wpa_supplicant

Type the following:

tail wpa_supplicant.conf

and you should see something like below:

network={
ssid="yournetwork"
#psk="yourpassword"
psk=564871f3638a28fd6f68sdd1fe41d1c75f0124ad34536a3f0747fe417432d888888
}

Find name of your wireless driver

Before proper connectivity there is more piece of information you will need which is the name of your driver of wireless network card, just give the command:

wpa_supplicant -help | more

The command will list the section of drivers which will look like this:

drivers:
nl80211 = Linux nl80211/cfg80211
wext = Linux wireless extensions (generic)
wired = Wired Ethernet driver
none = no driver (RADIUS server/WPS ER)

Now, in this case, my appropriate driver is nl80211, this will be used in further connectivity.

Connect to the internet

The first step is to run the wpa_supplicant command :

sudo wpa_supplicant –B -D “driver” -i “interface” -c /etc/wpa_supplicant/wpa_supplicant.conf

where “driver” will be your driver(nl80211 in my case) without double quotes and “interface” will be your interface(wlan0 in my case) without double quotes.

Finally run the command:

sudo dhclient

This is for the DCHP client –dhclient– which will establish networking routing on the local Network. Now still to check connectivity you can just ping any website.



Similar Reads

How to Compare Files Line by Line in Linux | diff Command
In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process is the diff command. In this article, we will explo
9 min read
How to Create a Text File Using the Command Line in Linux
There are a couple of quick ways to create a text file from the Linux Command Line or Terminal. Some of them have been explained in the following article. 1) touch commandThis is the most standard command to quickly create an empty text file. The command is quite simple to type and makes it quite easier to create several text files at once. The com
6 min read
How to Manage KVM Virtual Environment using Command Line Tools in Linux
KVM, short for Kernel-based Virtual Machine, is a complete virtualization solution for Linux running on x86 hardware (Intel VT or AMD-V). Since version 2.6.20, the mainline Linux kernel has featured KVM, a complete virtualization solution for Linux running on Intel 64 and AMD 64 hardware that is fast and stable for the majority of workloads. It con
8 min read
Uninstall Node.JS Using Linux Command Line
To uninstall Node.js from your Linux system using the command line, you can follow these steps. The specific commands may vary depending on your Linux distribution, so I'll provide instructions for a few common package managers: APT (Debian/Ubuntu), YUM (Red Hat/CentOS), and DNF (Fedora). Check if Node is Already Installed or NotEnter the following
3 min read
How to Convert DOS line endings to Linux line endings using Vim
DOS and Unix/Linux file formats differ slightly such that the ASCII characters used at the line endings are different. Unix file format uses an LF character to end a line, LF stands for LineFeed, which means moving the cursor down. Unix-based systems and Mac OS X & later use this format. While the DOS file format uses a CR character before the
2 min read
Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
How to Download YouTube Videos in Linux Command Line?
The videos can be downloaded from the online source through the Linux terminal using the youtube-dl tool. youtube-dl is a Python-based small command-line tool that makes it possible to download the videos from Youtube, Facebook, Dailymotion, and few more similar sites. It is written in PyGTK and requires Python interpreter to run this program, it’s
2 min read
Kali Linux - Command Line Essentials
Command-line plays a vital role while working with Kali Linux as most of its tools don't have a Graphical User Interface and if you are performing ethical hacking or penetration testing then most of the time you will have to work with command Line Interface itself. While executing a command in Kali Linux we enter a command on the terminal emulator
3 min read
Deepl - Command Line Language Translator Tool for Linux
Deepl is the best language translator command-line tool that detects the language of input text and translates it into the desired language using advanced machine learning and neural networking algorithms. It is open source and powered by a German tech Company under the MIT license. It supports the following languages English (EN)Italian (IT)Spanis
3 min read
Article Tags :
three90RightbarBannerImg