Connecting to the Internet Using Command Line in Linux
Last Updated : 10 May, 2020
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 Check Network Connectivity in Linux | ping Command
Ensuring a stable and reliable internet connection is crucial for seamless navigation and efficient communication in the world of Linux. The "ping" command is a powerful tool that allows users to check the status of their internet connection and diagnose network-related issues. In this article, we w
7 min read
Manage Network Connections From the Linux Command Line with nmcli
Network connectivity is a critical aspect of modern computing, and Linux provides a robust command-line tool for managing network connections: nmcli. Network Manager Command-Line Interface (nmcli) is a powerful and versatile utility that allows users to control and configure network settings directl
5 min read
How to use SSH to connect to a remote server in Linux | ssh Command
Secure Shell, commonly known as SSH, is like a super-secure way to talk to faraway computers, called servers. It's like a secret tunnel on the internet that keeps your conversations safe and private. Imagine you're sending a letter, and instead of sending it openly, you put it in a magic envelope th
8 min read
How to Use Linux Commands in Windows with Cygwin
Cygwin is a collection of tools that provide a Linux Operating System's terminal look, feel, and some of its basic functionality for users of Windows OS who want to have a go over the basic commands of Linux without worrying about installing a Linux OS. To use this tool, first of all, we need to dow
3 min read
How to Test Internet on Linux Using speedtest-cli?
While troubleshooting your system for slow internet access, the best way to figure is to measure the internet speed first. To check Internet speed on Linux we will be using third party tool speedtest_cli. It is a simple command-line client based on python for measuring internet bandwidth using speed
1 min read
domainname Command in Linux With Examples
domainname command in Linux is used to return the Network Information System (NIS) domain name of the host. You can use hostname -d command as well to get the host domainname. If the domain name is not set up in your host then the response will be "none". In networking terminology, the domain name i
3 min read
iptables-restore command in Linux with examples
The iptables-restore and ip6tables-restore commands are essential tools for managing IP and IPv6 tables in Linux. These commands are used to restore firewall rules from a specified file or directly from the standard input (STDIN). This feature is particularly useful for system administrators who nee
3 min read
getent command in Linux with examples
The 'getent' command in Linux is a powerful tool that allows users to access entries from various important text files or databases managed by the Name Service Switch (NSS) library. This command is widely used for retrieving user and group information, among other data, stored in databases such as '
5 min read
How to check the routing table in Linux | route Command
The IP/kernel routing table acts as a crucial map, determining how network packets are forwarded between different hosts and networks. By utilizing the route command, Linux administrators and users can establish static routes, enabling precise control over network connectivity and optimizing data tr
4 min read
How to Change the Mac Address in Kali Linux Using Macchanger
Imagine your computer has a special ID card for connecting to the internet, called a MAC address. Itâs like a name tag that tells networks who you are. Sometimes, for privacy or testing, you might want to change this ID. If youâre using Kali Linux, a system made for people who study security and hac
2 min read