andysilch
Posts: 12
Joined: Wed Oct 03, 2012 12:23 pm
Location: Reading, UK

Multiple WiFi with mix of static and DHCP

Thu May 25, 2017 12:29 pm

Hi,
I have searched this forum and done a lot googling, and tried many variation of setting this up but have not succeeded yet. I am trying to use the dhcpcd method with RPi 3. Stuffing it all in interfaces was the 'old' method, but I need to do it properly.

What I need is to be able to connect to 2 WiFis at home with static IP and then use DHCP when I am at work (and perhaps several more locations). I have reset /etc/network/interfaces to the default and set up wpa_supplicant.conf with a single WiFi and /etc/dhcpcd.conf with static IP for eth0 and wlan0. This all works. What I now want to do is add the other 2 WiFi networks, one static and the other DHCP.

Do I need to change interfaces to show wpa-roam instead of wpa-conf? How, and where, do I make the distinction between static and DHCP for the various network-ids? Someone must have got this working!

Ta, Andy.

klricks
Posts: 6445
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Multiple WiFi with mix of static and DHCP

Thu May 25, 2017 1:02 pm

Instead of static config, use DHCP reservations to MAC address in your home router. Leave the RPi config unchanged (DHCP)
That way the RPi will always get the same IP of your choice when at home and then fall back to standard DHCP from other networks when away from home.
If you use Ethernet and WIFI then be sure to assign different IP's to the Wired and WIFI MAC's
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

andysilch
Posts: 12
Joined: Wed Oct 03, 2012 12:23 pm
Location: Reading, UK

Re: Multiple WiFi with mix of static and DHCP

Thu May 25, 2017 2:10 pm

Hi klricks,

Thanks for the reply. I knew I should have added that what I require is what I require :) . I do not want to go down the MAC reservation route, I cannot predetermine what the router is going to assign beforehand. I can 'always use this address' after it has selected something for me. As I said I connect to (at least) 2 different WiFis in my house and the address has to be the same for both (all). I have some 30+ devices connected to my network and they have had the same IP Address for decades in some cases. I constantly need to ssh in to them and I often need to NAT into them from outside. A lot of the items are a bit old and have no concept of xxx.local, so the problem is as described. I have an 'out and about' router / switch when I sometimes need to take some of the devices to different locations (possibly not with outside internet access) but I still need to connect to each one individually on the LAN with the same address. The RPis are slightly different in that I need to take them 'out and about' to other people's networks, hence the DHCP requirement.

Thanks again for the suggestion, I'm sure it could solve someone else's situation, Andy.

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Multiple WiFi with mix of static and DHCP

Thu May 25, 2017 2:37 pm

I've been playing with it for a while, and this seems to work. Let me know if it works for you.
In /etc/dhcpcd.conf when assigning static network settings, change
interface wlan0
to
ssid your_ssid

andysilch
Posts: 12
Joined: Wed Oct 03, 2012 12:23 pm
Location: Reading, UK

Re: Multiple WiFi with mix of static and DHCP

Thu May 25, 2017 3:41 pm

@SurferTim

Yes, just what I wanted. I now can connect with 3 of my local WiFis and can set them up as 2 static addresses and 1 DHCP by judicious editing and commenting out various parts of wpa_supplicant.conf in between reboots. (I got a bit carried away and now have 8 SSIDs set up with various combinations.)

Thank you very much for solving that for me, I have been trying that on and off for a few days.

Ta, Andy.

Return to “Troubleshooting”