On Wednesday 19 Apr 2017 12:46:09 Florian Gamböck wrote:
> 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.

Hmm ... I never had this experience with Cisco IOS.  It may be worth updating 
the router and WAP firmware in case this was due to a bug.  The router should 
never allocate IP addresses from its reserved IP address table, although it 
will not be able to stop PCs using these addresses themselves if they were 
manually configured so.

> 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.

If it is a Cisco running IOS there should be SSH access to run CLI commands 
for it.  If however it is a Cisco-branded cheap appliance, then it would 
probably not have any relationship with IOS, but it may be able to run OpenWRT 
or equivalent on its SoC.


> > 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!

Have a look at the documentation provided by netifrc, it is well commented 
with detailed examples:

less /usr/share/doc/netifrc-0.5.1/net.example.bz2


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

-- 
Regards,
Mick

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to