1

I've two wifi networks, home and work with different static ip, routers, dns. In /etc/dhcpcd.conf I can only configure one of them.

I've heard of dhcpd hooks and found this link. But I'm pretty sure that this can be simplified by just setting $new_ip_address, $new_routers and $new_domain_name_servers in some hook file.

Ideally what I would need is a different /etc/dhcpd-"$ssid".conf per ssid

  • Your question is internally inconsistent. – Milliways Sep 27 '18 at 10:50
  • can you elaborate please? – francesc Sep 27 '18 at 11:12
  • You don't seem to know what OS; your link is about multiple interfaces, but you seem to want to use multiple networks - not to mention you haven't said what Pi. Why do you want to set static IP anyway? – Milliways Sep 27 '18 at 11:16
  • Ooops, my fault, I've corrected it (/etc/dhcpd-"$ssid".conf). Mine is RPi 3B+ Raspbian Stretch. I'm obliged to use static IP (headless setup). The question is: how do I configure different static IP, routers and domain_name_servers depending on the ssid Rpi connects to? See my answer – francesc Sep 27 '18 at 13:10
1

How about arping? No need to use hooks. in /etc/dhcpcd.conf:

interface wlan0
arping 192.168.1.1
arping 10.0.30.1

# home    
profile 192.168.1.1
static ip_address=192.168.1.101/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1

# work
profile 10.0.30.1
static ip_address=10.0.30.199/24
static routers=10.0.30.1
static domain_name_servers=10.0.2.6

Best solution I've found so far

| improve this answer | |
  • IIRC You can use 'ssid' instead of 'profile' in dhcpcd.conf. So try ssid ssidname followed by the static lines. Have not used it myself, so cannot confirm if it works or not – Dirk Sep 27 '18 at 14:00
  • @Dirk At home it works. I'll try at work and confirm it. Thanks – francesc Sep 27 '18 at 15:50
  • @Dirk Nope. Doesn't work. I checked more throroughly and ssid is ignored completely. It always selects the last static ip_address disregarding ssid section – francesc Sep 27 '18 at 18:06
0

See Host Specific Configuration as described in How to set up networking/WiFi

It is not possible to base this on router SSID but you can set as many networks as you like, based on router MAC or IP address.

See man dhcpcd.conf although the example is brief and sketchy.

| improve this answer | |

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.