On 2017-04-18 20:41, Mick wrote:
I can think of at least two ways you can attempt to achieve what you want.

1. Set the Raspi to use DHCP only

Assuming you have access to your home's router, you can configure on it a static IP address for the MAC address of the Raspi. The home router will not allocate any such reserved IP address to any other device, but reserve it for the Raspi's MAC address.

At work the Raspi will obtain a random IP address from the work's router as expected. This is by far the simplest option.

The line you need in /etc/conf.d/net of the Raspi will look like this:

config_eth0="dhcp"

(Change eth0 above for the name of Raspi's wireless interface).

That's what I've been doing in the past, but my Cisco router had problems with that. It tried to give away addresses I have specifically reserved and it ended up cutting the connections and refusing to let new machines connect as long as there was a conflict.

Besides, I like having configuration files on my computers, which I can exchange and adjust as I like, without the need to click through heavily overloaded router configuration WebApps.

2. Configure the Raspi to selectively set itself a static IP address

In this option you will set up in the Raspi's /etc/conf.d/net a static IP address 192.168.0.10/24, when the gateway matches the wireless MAC address of the home router. For any other gateway the Raspi will fall back to using dhcp.

Something like this should work:

# Define the gateway you want to configure gateways_eth0="192.168.0.254,AA:BB:CC:DD:EE:FF,192.168.0.10"

# Define the default route for gateway 192.168.0.254 routes_192168000254_AABBCCDDEEFF="default via 192.168.0.254"

# Define the IP and netmask when using gateway 192.168.0.254 config_192168000254_AABBCCDDEEFF="192.168.0.10/24"

# Define the DNS servers to use with gateway dns_servers_192168000254_AABBCCDDEEFF="192.168.0.254"

# Then you need to add a line for all other routers the Raspi may connect to: fallback_eth0="dhcp"


NOTES
=====
192168000254 is the syntax used to represent an IP address for the home router of 192.168.0.254

AABBCCDDEEFF is the syntax used to represent a MAC address for the home router of AA:BB:CC:DD:EE:FF

If your Raspi wireless NIC is not eth0, please adjust the fallback directive above accordingly.

You may need to duplicate the above for any other NICs your Raspi may be end up with, for which you would want to configure a static IP address.

Huh, neat. This looks indeed like it could be exactly what I was looking for.

Thank you very much, I didn't know about this syntax!

I'll try it the next days and report back afterwards!

--
Kind regards

Flo

Reply via email to