6

I configured wpa_supplicant so I have a wifi connection after boot up. Now I want to stop it for while and start it again. I tried:

rpi ~$ sudo ifdown wlan0
ifdown: unknown interface wlan0

But wlan0 exists:

rpi ~$ ip addr show dev wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:06:e8:8b brd ff:ff:ff:ff:ff:ff
inet 192.168.10.112/24 brd 192.168.10.255 scope global wlan0

Trying to use systemd also fails. wpa_supplicant.service is already disabled:

rpi ~$ systemctl status wpa_supplicant.service 
● wpa_supplicant.service - WPA supplicant
   Loaded: loaded (/lib/systemd/system/wpa_supplicant.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

I have looked at /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant but cannot figure out how to use it.

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • It's an actual program and you can kill it, although if you are using the system networking stuff there's a good chance something will just start it up again. You're also running a dhcp client on that interface, and that is a program you can kill or stop (dhclient or I think dhcpcd; with the former you can use dhclient -r to stop it) but the same caveat probably applies. – goldilocks Jul 03 '18 at 14:28

1 Answers1

5

After a while now I understand how it works. wpa_supplicant is managed by dhcpcd using a hook. Neither ifupdown networking, managed with /etc/network/interfaces, is involved nor the systemd service. wpa_supplicant.service is completely ignored by dhcpcd and has no functionality. To stop/start wpa_supplicant you have four possibilies.


If you want to quick stop/start temporary the wifi connection you can just down/up the interface. This will not stop wpa_supplicant. It is still running in the background and can respond to other requests. I use wpa_cli to control wpa_supplicant.

rpi ~$ sudo ip link set dev wlan0 down
rpi ~$ wpa_cli ping
PONG
rpi ~$ sudo ip link set dev wlan0 up


If you want that wpa_supplicant does not do anything to be sure that there are no side effects with wifi you can terminate it completely. To start it again you have to restart dhcpcd:

rpi ~$ wpa_cli terminate
Selected interface 'p2p-dev-wlan0'
OK
rpi ~$ wpa_cli ping
Failed to connect to non-global ctrl_ifname: (nil)  error: No such file or directory
rpi ~$ sudo systemctl restart dhcpcd.service


If you want to disable wlan0 persistent to be used by wpa_supplicant you can add this line to /etc/dhcpcd.conf. It will also do not start wpa_supplicant if there is no other wifi interface available. Otherwise it is started to manage other wifi interfaces.

denyinterfaces wlan0


If you want to disable wpa_supplicant in general you can add this line to /etc/dhcpcd.conf:

nohook wpa_supplicant
Ingo
  • 42,107
  • 20
  • 85
  • 197
  • This answer states that wpa_supplicant is not controlled/managed by (among other things) systemd. Based on a simple experiment on my RPi 3B+, RPi OS Lite, bullseye host, it seems that the systemd service *may* now be involved. Running systemctl status wpa_supplicant.service yields an output that says wpa_supplicant is loaded, and active (running). – Seamus Feb 11 '23 at 23:17