0

Ive got a PI set up where I want to switch between acting as an AP and acting like a normal user of a wifi network.

Currently I have to reboot to make this work, but i'm certain there's just a tiny piece of the puzzle I'm overlooking.

In AP mode all traffic is resolved to the internal web browser, and I think its this that gets stuck somewhere.

My current process is:

         # switch to AP mode
         cp interfaces.fixed /etc/network/interfaces
         systemctl enable hostapd.service
         systemctl enable dnsmasq.service
         systemctl enable bluetooth
         systemctl disable wpa_supplicant.service
         systemctl reboot

and

         # switch to client mode
         cp interfaces.dhcp /etc/network/interfaces
         systemctl disable hostapd.service
         systemctl disable dnsmasq.service
         systemctl disable bluetooth
         systemctl enable wpa_supplicant.service
         systemctl reboot

Logically I think i should be able to swap the [dis|en]able for st[op|art], but if I do this then the Pi gets an IP address, but no traffic escapes.

What am I missing?

  • To start your services you need start or enable --now. I also wrote something to do this automatically, it works with stretch and buster. You may want to have a look at it and adopt it to your needs. – jake Sep 15 at 22:32
  • Using "start" is insufficient for some reason. Perhaps its systemd not owning everything - I'll have a look at your post when i have had a sleep, it doesn't quite do what I want (surprise!) because I am enabling the AP/client depending config found on an optional USB key, the USB key currently configures the network by having the passphrase and the interfaces file on it. For security I don't want the passphrase being on the device because anyone can open the box and see it whereas I have eyes on the box whenever it has the key in it – Will8 Sep 15 at 22:45
  • enable is to cause a service to start on boot. You need to stop services before starting incompatible services. If using Raspbian (which uses dhcpcd to manage networks) this needs to be stopped (or prevented from configuring WiFi interfaces) – Milliways Sep 16 at 0:09
  • You need to systemctl restart systemd-networkd after an update to interfaces file if you don't want to reboot, and start services instead of just enabling. See what @jake did in Automatically Create Hotspot if no Network is Available - it looks like it covers your needs. – Dmitry Grigoryev Sep 16 at 7:21
0

You do not tell us why you want to have it complex. That would be interesting. You can have both connections at the same time so normally there is not need to switch anything. But if you want to do it you can use systemd-networkd. With it you can make clean services for each task, one service for the access point and one service for the client connection. Using dependencies you can just start the service you want, no need to stop the other. That is done automatically.

How to manage this you can look at Switch between wifi client and access point without reboot.

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.