1

Rasbian on a Rasberry PI zero.

I have disabled the networking and dhcpcd services from startup and want to start networking and get an IP from within my own script, which is initiated from a custom systemd service.

This is the part of the script that is puzzling me:

wpa_passphrase ssid password > /etc/wpa_supplicant/wpa_supplicant.conf
systemctl start networking.service
dhcpcd wlan0

Running dhcpcd wlan0 from within the script will not assign an IP (ifconfig after login), but running sudo dhcpcd wlan0 will get me an IP if I run it after startup and login. Anyone know if this is a timing issue (wait for networking.service) or if I need to do something differently to get an IP via dhcpcd within the script.

I have also tried adding some delay (sleep 100) and running systemctl start dhcpcd (instead of dhcpcd wlan0).

I know this is not the standard way of doing this, but disabling networking and dhcpcd and start it from within my script will make startup more efficient (less up/down and waiting for network before doing more initiation etc.). I do a lot of custom configuration and instantiation from within my script.

Henrik

0

I solved it myself:

I had to change the /etc/network/interfaces configuration file. I changed:

auto wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

To:

auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

This also means that I can remove the dhcpcd wlan0 line in the script. Now I get an IP at startup, even when initiating the networking service from within the script.

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.