Personal tools

Connecting to WiFi network using systemd and wpa-supplicant

From SomLabs Wiki

Jump to: navigation, search

Connecting to WiFi network using systemd and wpa-supplicant


In order to connect to the WiFi network a proper configuration needs to be provided. This tutorial shows how to do this using the wpa_supplicant tool and the systemd service manager.

First, create the /etc/wpa_supplicant directory and the /etc/wpa_supplicant/wpa_supplicant-wlan0.conf file with the following configuration:

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1

network={
  ssid="<NETWORK_SSID>"
  psk="<NETWORK_PASSWORD>"
  key_mgmt=WPA-PSK
  proto=WPA2
  pairwise=CCMP TKIP
  group=CCMP TKIP
  scan_ssid=1
}

The network in the example is protected with the WPA2 standard and requires a password. The <NETWORK_SSID> and <NETWORK_PASSWORD> fields need to be changed according to the existing network configuration.

Create the /etc/systemd/network/25-wlan.network file:

[Match]
Name=wlan0

[Network]
DHCP=ipv4

Enable the wpa_service for the wlan0 interface:

systemctl enable wpa_supplicant@wlan0.service

Restart the systemd-networkd and wpa_supplicant services:

systemctl restart systemd-networkd.service
systemctl restart wpa_supplicant@wlan0.service

and check the interface status:

ip a

The wireless network (wlan0) should now be enabled and configured after each system boot:

3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
	link/ether a0:cc:2b:2c:6b:8d brd ff:ff:ff:ff:ff:ff
	inet 192.168.43.234/24 brd 192.168.43.255 scope global wlan0
	   valid_lft forever preferred_lft forever
	inet6 2a00:f41:581c:fc61:a2cc:2bff:fe2c:6b8d/64 scope global dynamic mngtmpaddr 
	   valid_lft 3574sec preferred_lft 3574sec
	inet6 fe80::a2cc:2bff:fe2c:6b8d/64 scope link 
	   valid_lft forever preferred_lft forever
NXP Partner ST Partner Renesas Partner