2

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

update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
    ssid="ssid1"
    psk="pass"
}
network={
    ssid="ssid2"
    psk="pass"
}

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.

Milliways
  • 54,718
  • 26
  • 92
  • 182
Matteo
  • 21
  • 1
  • 2

1 Answers1

4

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.

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • 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 06:56
  • @Matteo Raspbian now uses `dhcpcd` by default. See my tutorial [How do I set up networking/WiFi/Static IP](http://raspberrypi.stackexchange.com/a/37921/8697) for how to set this. The settings you list, with my corrections, would work if you disable `dhcpcd`. – Milliways Mar 11 '16 at 07:00