Skip to content

Instantly share code, notes, and snippets.

@Denilson-Semedo
Created April 7, 2024 18:16
Show Gist options
  • Save Denilson-Semedo/f0e689fb6f4e7ca70a8ecc19fe8b1366 to your computer and use it in GitHub Desktop.
Save Denilson-Semedo/f0e689fb6f4e7ca70a8ecc19fe8b1366 to your computer and use it in GitHub Desktop.
WiFi Connection on Linux using wpa_supplicant

Setting up WiFi Connection on Linux using wpa_supplicant

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.

Prerequisites

  • A Linux distribution installed on your system.
  • wpa_supplicant package installed.
  • Basic knowledge of using the command line interface (CLI).

Steps to Connect to WiFi using wpa_supplicant

1. Configure wpa_supplicant.conf

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.

2. Bring up the Wireless Interface

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

3. Start wpa_supplicant

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).

4. Obtain an IP Address

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.

5. Check Connection Status

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment