On Tuesday 18 Apr 2017 20:41:54 Florian Gamböck wrote:
> Hi Mick,
> 
> thank you for your response!
> 
> On 2017-04-18 16:41, Mick wrote:
> > I had to read this message twice and I am not yet sure I understand
> > correctly what it is you are trying to achieve.
> > 
> > Do you want whichever NIC of your PC connects first to a specific SSID
> > to always obtain IP 192.168.0.10/24 and any NIC which connects second
> > to use DHCP?
> 
> Not necessarily the first NIC, but the NIC with a specific MAC address,
> say 001122334455.
> 
> But now that you mention it, as long as one NIC gets the static IP (but
> only for the specified SSID) and all the others will be handled by DHCP,
> I don't care which one of the NICs is statically addressed.
> 
> Sorry for not being able to describe it well.
> 
> What I am trying to achieve: I have a Raspberry Pi as a server, without
> monitor, without keyboard. Just a Raspi and a Wifi stick. I want the
> Raspi to use DHCP when I take it with me and power it on at my
> workplace. Thanks to Avahi I don't need to know the IP address it gets
> at my workplace.
> 
> When I am at home, there are reasons why I can't rely on Avahi (Android
> Phones for example that do not have the possibility to resolve
> raspi.local). So I want it to have a static IP at home. Now, if for
> whatever reason I lose the connection to Raspi -- for example once my
> router at home freaked out and wouldn't let Raspi connect with a static
> IP -- I want to have the possibility to plug another Wifi stick into
> Raspi which then gets connected via DHCP, so I can at least connect to
> it.
> 
> As I see it, I can't use config_001122334455, because I would not be
> able to connect at my workplace anymore (different network properties).
> I now use config_MySSID to get a static address at home, but what about
> a second Wifi stick being connected? It would use the same config and
> end up getting the same IP address that didn't work with the first
> stick.
> 
> In general, it would be intersting to logically combine the
> configuration via SSID with the configuration via MAC. I can also think
> of a scenario where I have two wifi networks and two wifi sticks, each
> one getting a static IP on their connected network. But if I take the
> Raspi into another network, I would want NIC_1 to be DHCPed and NIC_2 to
> be nulled.
> 
> I hope I could help you to better understand what I am trying to achieve
> and what my current problem is. If possible I want to solve it via pure
> netifrc, but I would also be happy if someone said that it isn't
> possible at all via netifrc, so I can stop researching in this direction
> and think of something different.

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


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.

-- 
Regards,
Mick

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

Reply via email to