I use my RPI as wifi repeater using hostapd and dnsmasq.

Since I'm using hostapd_cli to disconnect the pi from the internet if the repeater is not in use, I often can’t connect to my access point and I have to restart hostapd or dnsmasq.

How is it possible that hostapd_cli makes my access point inaccessible?

I start hostapd_cli by using rc.local:

hostapd_cli -a /home/pi/autoConnectWLAN.sh &

The script contains:


if sudo hostapd_cli all_sta | grep -q "ASSOC" && ! ip link show wlan1 | grep -q "UP"; then
  sudo ip link set wlan1 up 

  if ! pgrep -x "wpa_supplicant"; then
    sudo wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-wlan1.conf -Dnl80211,wext -iwlan1 -B 

elif ! sudo hostapd_cli all_sta | grep -q "ASSOC" && ip link show wlan1 | grep -q "UP"; then
  sudo ip link set wlan1 down

1 Answer 1


Please take note that using /etc/rc.local has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using rc.local.

In addition your script is doing things that assumes that hostapd is up and running. That may or may not be possible because there is no dependency to start your script After=hostapd.service.

The same is with wpa_supplicant. You start it in your script. If you use a default raspbian image then wpa_supplicant is managed by dhcpcd. I cannot see that you do things to avoid conflicts by starting wpa_supplicant a second time on another way.

In general you are completely ignoring the init system systemd with its dependencies to manage services. I'm sure this is the reason why hostapd_cli makes your access point inaccessible. You should use a systemd Unit file to start your access point (but that wasn't asked).

  • Thanks for your answer. You are right, I don't really like to use systemd. Maybe that's the problem. But I added nohook wpa_supplicant for both devices to dhcpcd.conf. And I added until pidof hostapd; do sleep 0.5; done before I start hostapd_cli...
    – jake
    Commented Dec 8, 2018 at 15:24
  • @jake There was a big discussion about pro and contra of systemd and I respect if one doesn't like it. Yes, systemd violates old historical unix paradigm. But most distributions come with systemd, incl. Raspbian, so you have to decide what path you will follow. If you decide to follow classical unix guidelines then you should also use an operating system following it, otherwise you will run more and more into problems like your question. As far as I know debian has a new fork still using SysV init system because of this discussion. I have decided to use systemd. I believe its the mainstream.
    – Ingo
    Commented Dec 8, 2018 at 17:03
  • @jake How I solved your problem with systemd you may have al look at Access point as WiFi repeater, optional with bridge. With it you can simply start and stop the AP with sudo systemctl [start|stop] hostapd.service. Because you refer to wlan1 I guess you are using two wifi devices (one usb/wifi dongle?). Then you can look at RPI3 Raspbian Stretch regular connection on wlan0 AP on wlan1.
    – Ingo
    Commented Dec 8, 2018 at 17:18
  • 1
    You're right, I have to get used to it. I use two wifi dongles on a pi 1. I will maybe try to set it up with systemd on a fresh install.
    – jake
    Commented Dec 8, 2018 at 18:09
  • I'm following your answer in the provided link. But how can I get static device names and change mac-address? Using /etc/systemd/network/00-default.link?
    – jake
    Commented Dec 8, 2018 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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