Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to use SSH to connect to a remote server in Linux | ssh Command
Next article icon

Connecting to the Internet Using Command Line in Linux

Last Updated : 10 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
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.



Next Article
How to use SSH to connect to a remote server in Linux | ssh Command

M

Madhusudan_Soni
Improve
Article Tags :
  • Linux-Unix
  • Write From Home

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences