I can't get my raspberry pi to work properly with the wlan.

The behaviour I'd like to obtain is: At boot tries to connect to a wlan if there is one available get a ip through DHCP and it's fine, otherwise remain searching for a wlan, and when there is one available connect to it and pick an IP with DHCP. This is the behaviour of my phone, straightforward.

I have Alpine Linux on Raspberry Pi 1.

Here my /etc/network/interfaces

auto lo
iface lo inet loopback

iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface default net dhcp

here wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

The behaviour I get is that ok, at boot it finds a listed wlan and connects to it but without sending dhcp, so I don't have any address. The same happens if the wlan is found at any time: it connects without sending dhcp discovery. If I try (at any time):

ifup wlan0

then DHCP discovery is sent and everything works properly, but I want to have this automatically!

Is there a way to run ifup wlan0 when wpa_supplicant connects to a new wlan? Because if I have an old IP and wpa_supplicant changes wlan then the old IP is not working properly.

| improve this question | | | | |
  • I know you have here allow-hotplug wlan0 - but have you tried putting in auto wlan0 – nwaltham Mar 11 '16 at 12:51
  • yes, not working. – Matteo Mar 11 '16 at 13:39

The correct syntax is iface wlan0 inet manual.

The network details are supplied by wpa_supplicant then the iface default net dhcp gets IP address from dhcp.

Using wpa-roam rather than wpa-conf enables the interface to change from one to another.

I don't know Alpine Linux, but this no longer works reliably on Raspbian.

| improve this answer | | | | |
  • Thank you for the answer. I tried to change like that but nothing happened. Why this no longer works reliably on Raspbian? What else is Raspbian using? – Matteo Mar 11 '16 at 6:56
  • @Matteo Raspbian now uses dhcpcd by default. See my tutorial How do I set up networking/WiFi/Static IP for how to set this. The settings you list, with my corrections, would work if you disable dhcpcd. – Milliways Mar 11 '16 at 7:00

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.