I use a RPI 1 as wifi repeater with two wireless dongles. I configured it using hostapd and dnsmasq.

I want the pi only to be connected to the internet if there is somebody connected to my access point. So I wrote this service:

Description=Start hostapd_cli

ExecStart=/usr/sbin/hostapd_cli -p /var/run/hostapd -a /home/pi/autoConnect.sh -i wlan0 


Where autoConnect.sh is:

if [[ "$2" == "AP-STA-CONNECTED" ]]; then
    if ! ip link show wlan1 | grep -q "UP"; then
        sudo ip link set wlan1 up

elif [[ "$2" == "AP-STA-DISCONNECTED" ]]; then
    sleep 120 &&
    if ! sudo hostapd_cli all_sta | grep -q "AUTHORIZED"; then
        sudo ip link set wlan1 down

It work's, but after a reboot the pi connects to the internet, which I want to avoid. Adding


to /etc/dhcpcd.conf didn't do the trick. (Starting wpa_supplicant through my script is not possible, because it fails when I have to restart hostapd.)

So I would like to know how to set an interface down by default?

(Maybe you got even hints for a better solution in general.)


I followed Ingo's suggestions and changed completely to systemd and disabled the wpa_supplicant@wlan1.service. I now use this service and script to automatically connect and disconnect to the internet:

# /etc/systemd/system/wpa-cli@wlan0.service
Description=wpa_cli to auto connect wifi on event
After=network-online.target wpa_supplicant@%i.service sys-subsystem-net-devices-%i.device

ExecStart=/sbin/wpa_cli -i %I -a /home/pi/autoConnectWLAN.sh -B


The script:


case "$2" in
        systemctl start wpa_supplicant@wlan1.service 

        sleep 60
        if ! wpa_cli -i wlan0 all_sta | grep -q "AUTHORIZED"; then
            systemctl stop wpa_supplicant@wlan1.service


I now wonder if it would be possible to achieve what I want by just defining dependencies between the two wpa_supplicant@.services.


You also asked: "Maybe you got even hints for a better solution in general." I prefer to use systemd-networkd because it has all in one. Using two USB/wifi dongle simplifies it a lot. So my hint is to look at Access point as WiFi repeater with additional WiFi-dongle. It does not fit exactly your needs but it should not be a big problem to adapt it to your problem.

Both interfaces wlan0 and wlan1 are handled independent from the other with interface specific versions of wpa_supplicant services (e.g. wpa_supplicant@wlan0.service). You can setup each interface for what you need and set dependencies between the two services.

And to answer your question: with this setup it is easy to disable e.g. wlan0 on startup with:

rpi ~$ sudo systemctl disable wpa_supplicant@wlan0.service

(If you like to get some assistance please don't hesitate to ask).

  • Thanks for the answer. I'd like to change completely to systemd. Unfortunately I got stuck here, where you guessed it to be a problem with the old hardware.
    – jake
    Feb 18 '19 at 19:51
  • I finally made it working. How would achieve what I want with systemd? Is there a possibility to do it without using wpa_cli -a SCRIPT.sh?
    – jake
    Mar 6 '19 at 22:33
  • @jake I have just found that it could be that there was a wrong option set for wpa_supplicant used by systemd-networkd: Replacing hostapd with wpa_supplicant but I do not have a feedback now if this fixed the problem, waiting for it.
    – Ingo
    Mar 7 '19 at 0:37
  • 1
    @jake I will look but have just no idea. The problem is to get information from a running service (the access point). You cannot use dependencies because they are only used to start/stop/delay etc. services depending on other services. With a running service systemd is satisfied. Running wpa_cli as daemon for this is a good idea. But if we can use systemd-notify in any way I would prefer this.
    – Ingo
    Mar 25 '19 at 10:53
  • 1
    @jake I have made ifplugd available again for Raspbian: Make ifplugd available again since Raspbian Stretch. But it doesn't make much difference to use wpa_cli -a SCRIPT.sh. So only a comment to this.
    – Ingo
    May 27 '19 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.