Debian: Configure wireless LAN by Systemd

Hi,

this post is a step by step tutorial for setup WLAN in debian by systemd.

Determine the WLAN Adapter and reachable Networks

root@debdev ~# iwconfig
root@debdev ~# ifconfig wlan0 up
root@debdev ~# iwlist wlan0 scanning


Create a profile for your Network

root@debdev ~# wpa_passphrase YOUR_NETWORK_SSID Passphrase > /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

Create a networkd file /etc/systemd/network/wlan0.network for device wlan0 so that systemd handles this interface. Also remove all entries in /etc/network/interfaces which belongs to wlan0.

[Match]
Name=wlan0
[Network]
DHCP=yes

Create a unit for wpa_supplicant. Filename: /lib/systemd/system/wpa_supplicant@.service


[Unit]
Description=WPA Unit
Before=network.target
Wants=network.target
Requires=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device dbus.service 

[Service]
Type=simple
ExecStart=/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant-%i.conf -i %i

[Install]
Alias=multi-user.target.wants/wpa_supplicant@%i.service

Enable systemd network config

root@debdev ~# systemctl enable systemd-networkd.service
root@debdev ~# systemctl enable systemd-resolved.service
root@debdev ~# mv /etc/resolv.conf /etc/resolv.conf.save
root@debdev ~# ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Enable wpa_supplicant

root@debdev ~# systemctl enable wpa_supplicant@wlan0.service
root@debdev ~# systemctl status -l wpa_supplicant@wlan0.service
● wpa_supplicant@wlan0.service - WPA Unit
   Loaded: loaded (/lib/systemd/system/wpa_supplicant@.service; enabled)
   Active: active (running) since Do 2016-08-03 22:18:24 CEST; 5min ago
 Main PID: 372 (wpa_supplicant)
   CGroup: /system.slice/system-wpa_supplicant.slice/wpa_supplicant@wlan0.service
           └─372 /sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant-wlan0.conf -i wlan0

Note: If you got an error: [/lib/systemd/system/wpa_supplicant@.service:3] Failed to add dependency on sys-subsystem… or
Systemd Cannot add dependency wpa_supplicant@%I.service to multi-service.target, ignoring: Invalid argument please check:

  • Have you forgot to disable interface wlan0 in /etc/network/interfaces?
  • Have you got multiple links or an link wpa_supplicant@%I.service to wpa_supplicant@.service in the target directory /etc/systemd/system/multi-user.target.wants
  • Use the escaped instance variable %i instead of %I in the unit file.

This shows the correct link

root@debdev ~# ls -l /lib/systemd/system/multi-user.target.wants/wpa_supplicant*
lrwxrwxrwx 1 root root 43 Aug 3 22:57 wpa_supplicant@wlan0.service -> /lib/systemd/system/wpa_supplicant@.service

And if connected

root@debdev ~# iwconfig
wlan0     IEEE 802.11bgn  ESSID:"YOUR_NETWORK_SSID"
          Mode:Managed  Frequency:2.412 GHz  Access Point: 34:31:C4:69:1C:4E
          Bit Rate=21.7 Mb/s   Tx-Power=20 dBm
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=33/70  Signal level=-77 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:7  Invalid misc:14   Missed beacon:0

Michael




Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.