3

I am configuring my raspberry pi zero w for a project in which I am using a micro-USB Ethernet (eth0) and WiFi (wlan0) as network interfaces. I am using wpa_supplicant to configure wlan0 to connect to a wireless access point. For my specific application, it is critical that wlan0 is kept down on boot and does not make any connection with networks specified in wpa_supplicant.conf until a user connects and interacts through the console. (Running something like ifconfig wlan0 up to bring the interface online and then running wpa_supplicant to load the configuration file manually.) It is not sufficient to erase/rename wpa_supplicant.conf on shutdown as this must configuration must be able to withstand random reboots / power-cycling.

Things I have tried:

  • I found that wpa_supplicant was a child process of systemd by default, so I tried modifying dhcpd to stop wpa_supplicant from starting on boot

  • tried writing a systemd service to bring the interface down on boot (ifconfig down), but I am too inexperience with systemd to configure this correctly

  • tried editing /etc/default/networking and adding the line EXCLUDE_INTERFACE=wlan0 to no effect (although this did strangely seem to delay the boot process)

Any ideas how I should go about configuring my pi in this manner? The ultimate goal is to ensure no outside wireless observer can see the pi until someone manually makes a wireless connection.

The Coding Clan
  • 184
  • 1
  • 14
randomdude887
  • 33
  • 1
  • 4

1 Answers1

5

There a different ways you could achieve what you want.

Method 1 – use systemd-networkd

If you want to use systemd just follow step 1 and step 3 of this tutorial. Just omit this command systemctl enable wpa_supplicant@wlan0, so wpa_supplicant won't bring your interface up at boot. If you want to start it manually run sudo systemctl start wpa_supplicant@wlan0.service.

Method 2 – use dhcpcd

The default way to manage network interfaces in raspbian is dhcpcd. I did not use this for a long time, but I guess if you add denyinterfaces wlan0 to /etc/dhcpcd.conf it won't bring up your interface either.

Then you can start it manually by running, but you have to make a config file without denyinterfaces wlan0:

wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0
dhcpcd -f /etc/dhcpcd-wlan0.conf wlan0

Method 3 – disable dhcpcd

If wlan0 is the only interface you use, you could also disable dhcpcd.service and just run it when it's needed. To disable it run sudo systemctl disable dhcpcd.service. Then you can manually start it with sudo systemctl start dhcpcd.service.

jake
  • 1,347
  • 10
  • 23
  • I have tried to the dhcpd method but when I try to bring up wlan0 later and run wpa_supplicant to load my wpa_supplicant.conf, wlan0 doesn't seem to connect to the network. I'm not sure if this is because wlan0 isn't making a DHCP request or what is going on exactly. If you have any other tips / resources I could look into for using dhcpd to do this, I would much prefer it over bootstrapping systemd to manage my network interfaces as shown in the provided tutorial. thanks for the tips! – randomdude887 Aug 16 '19 at 11:31
  • @randomdude887 You just use one interface, right? So you could also disable dhcpcd.service and just start it when needed. – jake Aug 16 '19 at 11:36
  • I need my ethernet interface (eth0) to be online from boot and getting DHCP lease so I can ssh into it from the network that interface is connected to, so i don't think disabling dhcpd.service will help me much here – randomdude887 Aug 16 '19 at 11:55
  • @randomdude887 So try to run dhcpcd wlan0 after having started wpa_supplicant. – jake Aug 16 '19 at 11:58
  • @randomdude887 and let me know if it works. – jake Aug 16 '19 at 12:26
  • denyinterfaces works to keep the interface down and I am able to successfully re-enable it and connect wlan0 to an AP when desired, but dhcpcd wlan0 isn't getting me a DHCP lease. Ideas? – randomdude887 Aug 16 '19 at 13:00
  • @randomdude887 run dhcpcd -d wlan0. And look for error messages. – jake Aug 16 '19 at 13:22
  • seems issue resolved itself (?) still trying to figure out why running dhcpcd wlan0 works now. will keep you posted. much thanks again – randomdude887 Aug 16 '19 at 13:24
  • @randomdude887 updated the answer. You need another config file for wlan0. – jake Aug 16 '19 at 13:37