In Linux systems, connecting to a WiFi network often involves configuring wpa_supplicant
, a versatile tool for managing WiFi connections. This tutorial will guide you through the process of setting up a WiFi connection using wpa_supplicant
on a Linux system.
- A Linux distribution installed on your system.
wpa_supplicant
package installed.- Basic knowledge of using the command line interface (CLI).
Firstly, you need to create or edit the wpa_supplicant.conf
configuration file located at /etc/wpa_supplicant.conf
. Open the file in a text editor and add the following content:
network={
ssid="wifi_name"
psk="wifi_key"
}
Replace wifi_name with the SSID of your WiFi network and wifi_key with the password.
Next, bring up the wireless interface. Execute the following command to enable the WiFi interface (replace wlan0 with your interface name if different):
sudo ip link set wlan0 up
Now, start wpa_supplicant with the configuration file you've just edited. Use the following command:
sudo wpa_supplicant -B -iwlan0 -c /etc/wpa_supplicant.conf -Dnl80211,wext
This command starts wpa_supplicant in the background (-B), specifies the wireless interface (-iwlan0), the configuration file (-c /etc/wpa_supplicant.conf), and the wireless drivers to use (-Dnl80211,wext).
Finally, obtain an IP address for the wireless interface using DHCP. Run the following command:
sudo dhclient wlan0
This command requests an IP address for the wlan0 interface from the DHCP server.
To verify that the connection is established successfully, execute the following command:
ip a s
This command will display the status of all network interfaces. You should see the IP address assigned to the wlan0 interface indicating that the connection is successful.
By following these steps, you can easily connect to a WiFi network on a Linux system using wpa_supplicant. This method provides a flexible and reliable way to manage WiFi connections from the command line interface.
Credits: Edino