![](http://2.bp.blogspot.com/-dW7YJlBLccQ/XMp-MW7uRzI/AAAAAAAAAcA/OYdVUp9lU8wrQ2ov0FpzCQc-9sDbxcc1ACLcBGAs/s1600/Linux-Rescue-Mode.jpg)
If situation forces you to boot your Linux machines in rescue mode due to whatsoever reason and you need to access WiFi networking to make internet connectivity available from command line then this tutorial will help you.
The steps illustrated in this guide will help you to establish WiFi networking on a Red Hat, CentOS, Fedora or Ubuntu Linux machine.
You will need to replace red highlighted text with yours.
Verify Available WiFi Adapters
You can find available WiFi adapter name by executing the following command:
sudo iw dev
Output
phy#1
Interface wlp5s0
ifindex 4
type managed
Bring Up WiFi Interface
You need to bring your wifi adapter up and running in order to scan available WiFi networks using the following command:
sudo ip link set wlp5s0 up
Search WiFi Access Point
Now you need to scan WiFi access points to gather the ssid and security protocol information using the following command:
sudo iw wlp5s0 scan
You will see output similiar to like below. The thing you need to remember is SSID and the security protocol (WPA/WPA2 vs WEP). In our example, the SSID is Ground-Floor and the security protocol is RSN, also commonly referred to as WPA2. The security protocol is important because it determines what tool you use to connect to the wifi network.
BSS 8c:67:20:ce:10:30 (on wlp5s0)
TSF: 4211507413842 usec (51d, 10:20:40)
freq: 2462
beacon interval: 100
capability: ESS Privacy ShortSlotTime (0x0411)
signal: -53.00 dBm
last seen: 105 ms ago
Information elements from Probe Response frame:
SSID: Ground-Floor
Supported rates: 1.0* 2.0* 5.5* 11.0* 18.0 24.0 36.0 54.0
DS Parameter set: channel 11
ERP: Barker_Preamble_Mode
RSN: * Version: 1
* Group cipher: CCMP
* Pairwise ciphers: CCMP
* Authentication suites: PSK
* Capabilities: 16-PTKSA-RC (0x000c)
Extended supported rates: 6.0 9.0 12.0 48.0
Generating Configuration File
For this guide, we will establish connection to Ground-Floor SSID and for that we need to generate a configuration file by executing the following command:
sudo wpa_passphrase Ground-Floor>> /etc/wpa_supplicant/wpa_supplicant.conf yourwifipassword
Connecting to WiFi Network
Since you have generated configuration file in above example, now you need to establish connection to that WiFi network using the following command:
sudo wpa_supplicant -B -D wext -i wlp5s0 -c /etc/wpa_supplicant/wpa_supplicant.conf
Explanation:
- -B means run wpa_supplicant in the background.
- -D specifies the wireless driver. wext is the generic driver.
- -c specifies the path for the configuration file.
Execute the following command to verify that you are indeed connected to the SSID.
sudo iw wlp5s0 link
Output
Connected to 8c:67:20:ce:10:30 (on wlp5s0)
SSID: Ground-Floor
freq: 2412
RX: 26951 bytes (267 packets)
TX: 1400 bytes (16 packets)
signal: -51 dBm
tx bitrate: 6.5 MBit/s MCS 0
bss flags: short-slot-time
dtim period: 0
beacon int: 100
In case you ran into any problem like Not Connected or resource busy then reboot your machine
Getting an IP Address
At this point, you need to initiate dhcp client request to get an ip address from your WiFi access point using the following command:
sudo dhclient wlp5s0
Verify IP Address
You can verify your machine ip address either by typing the ipconfig command or ip addr show command like below:
sudo ip addr show wlp5s0
Wrapping up
Congratulation, you are now connected to WiFi networking from command line and now you can use yum, apt like command to install, remove and update your Linux packages or even you can recover your Linux machine from a failure.