1

I have two questions, that are related. My situation. I have two wifi networks available. Both are registered in wpa_supplicant.conf One has priority 10, another 20.

When I turn on wlan0 it picks 20 first if available, if not - picks 10. If it picks 20, and I then switch AP off, it automatically switches to 10.

Problem #1: When it initially connected to 20 it got new IP (via DHCP) (192.168..) When I switched network 20 and it reconnected to 10 I still have same IP. (192.168..) If connect to 10 first IP is like 10.0....

Problem #2: Is there a way to make it switch to higher priority AP when it still connected to previous one? Automatically.

UPD: More info on setup

OS: standard Debian. WiFi module: "Wi-Pi"

/etc/wpa_supplicant/wpa_supplicant.conf:

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

network={
        ssid="TereHomikust"
        psk="***"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
        priority=10
}

network={
        ssid="small device"
        psk="***"
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP
        auth_alg=OPEN
        priority=20
}

/etc/network/interfaces:

auto wlan0

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 inet dhcp

small device network is AP running in Android phone. TereHomikust is my home network. I want ideally for my RPi always be connected to network with highest priority. Since both networks has different IP/mask setup and both provide DHCP service - I want to have appropriate IP when connected to each of those networks.

Currently, when RPi connected to small device with TereHomikust also available and I kill small device it reconnects to TereHomikust but keeps IP that it got from first networks' DHCP.

1 Answers1

1

If you are using Debian rather than Raspbian (which has different networking configuration) the /etc/network/interfaces should contain:-

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

What you have is not correct for any setup. manual allows external programs to configure IP and wpa-roam allows wpa_supplicant to react to network changes.

I don't know anything which will change from a working network to another, but this should trigger change if the current network becomes unavailable.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • I use Raspvian (noob etc) Isn't Raspbian is Debian? I've seen iface wlan0 inet dhcp many many places, tutorials and it makes sense for me. As in - this interface should be configured with DHCP. Where is manual is when I want static configuration. (UPD, yeah, that' definitely not correct) What am I missing in my understanding? – Aleksandr Motsjonov Aug 07 '16 at 10:16
  • I guess the answer is that all those tutorials are old. and something has changed in ~2015sh? I found this. Quote

    With the new network mods, DHCP is taken care of by a new package called dhcpcd. In order for this to work, the iface lines in /etc/network/interfaces need to be "manual" rather than "dhcp".

    – Aleksandr Motsjonov Aug 07 '16 at 10:24
  • Thank you. This did the trick. I will agree, that my second "Problem" is a bit strange and I guess I don't need it so much. I can restart machine when I need this. Thx. – Aleksandr Motsjonov Aug 07 '16 at 10:29
  • @AleksandrMotsjonov Raspbian is based on Debian but is customised for the Pi, and the current release uses a different networking system. See How do I set up networking/WiFi/Static IP for recommended configuration. What I have listed will work, but IMO dhcpcd works better (and manual applied even before). – Milliways Aug 07 '16 at 10:33