1 |
On Tuesday 18 Apr 2017 20:41:54 Florian Gamböck wrote: |
2 |
> Hi Mick, |
3 |
> |
4 |
> thank you for your response! |
5 |
> |
6 |
> On 2017-04-18 16:41, Mick wrote: |
7 |
> > I had to read this message twice and I am not yet sure I understand |
8 |
> > correctly what it is you are trying to achieve. |
9 |
> > |
10 |
> > Do you want whichever NIC of your PC connects first to a specific SSID |
11 |
> > to always obtain IP 192.168.0.10/24 and any NIC which connects second |
12 |
> > to use DHCP? |
13 |
> |
14 |
> Not necessarily the first NIC, but the NIC with a specific MAC address, |
15 |
> say 001122334455. |
16 |
> |
17 |
> But now that you mention it, as long as one NIC gets the static IP (but |
18 |
> only for the specified SSID) and all the others will be handled by DHCP, |
19 |
> I don't care which one of the NICs is statically addressed. |
20 |
> |
21 |
> Sorry for not being able to describe it well. |
22 |
> |
23 |
> What I am trying to achieve: I have a Raspberry Pi as a server, without |
24 |
> monitor, without keyboard. Just a Raspi and a Wifi stick. I want the |
25 |
> Raspi to use DHCP when I take it with me and power it on at my |
26 |
> workplace. Thanks to Avahi I don't need to know the IP address it gets |
27 |
> at my workplace. |
28 |
> |
29 |
> When I am at home, there are reasons why I can't rely on Avahi (Android |
30 |
> Phones for example that do not have the possibility to resolve |
31 |
> raspi.local). So I want it to have a static IP at home. Now, if for |
32 |
> whatever reason I lose the connection to Raspi -- for example once my |
33 |
> router at home freaked out and wouldn't let Raspi connect with a static |
34 |
> IP -- I want to have the possibility to plug another Wifi stick into |
35 |
> Raspi which then gets connected via DHCP, so I can at least connect to |
36 |
> it. |
37 |
> |
38 |
> As I see it, I can't use config_001122334455, because I would not be |
39 |
> able to connect at my workplace anymore (different network properties). |
40 |
> I now use config_MySSID to get a static address at home, but what about |
41 |
> a second Wifi stick being connected? It would use the same config and |
42 |
> end up getting the same IP address that didn't work with the first |
43 |
> stick. |
44 |
> |
45 |
> In general, it would be intersting to logically combine the |
46 |
> configuration via SSID with the configuration via MAC. I can also think |
47 |
> of a scenario where I have two wifi networks and two wifi sticks, each |
48 |
> one getting a static IP on their connected network. But if I take the |
49 |
> Raspi into another network, I would want NIC_1 to be DHCPed and NIC_2 to |
50 |
> be nulled. |
51 |
> |
52 |
> I hope I could help you to better understand what I am trying to achieve |
53 |
> and what my current problem is. If possible I want to solve it via pure |
54 |
> netifrc, but I would also be happy if someone said that it isn't |
55 |
> possible at all via netifrc, so I can stop researching in this direction |
56 |
> and think of something different. |
57 |
|
58 |
I can think of at least two ways you can attempt to achieve what you want. |
59 |
|
60 |
1. Set the Raspi to use DHCP only |
61 |
|
62 |
Assuming you have access to your home's router, you can configure on it a |
63 |
static IP address for the MAC address of the Raspi. The home router will not |
64 |
allocate any such reserved IP address to any other device, but reserve it for |
65 |
the Raspi's MAC address. |
66 |
|
67 |
At work the Raspi will obtain a random IP address from the work's router as |
68 |
expected. This is by far the simplest option. |
69 |
|
70 |
The line you need in /etc/conf.d/net of the Raspi will look like this: |
71 |
|
72 |
config_eth0="dhcp" |
73 |
|
74 |
(Change eth0 above for the name of Raspi's wireless interface). |
75 |
|
76 |
|
77 |
2. Configure the Raspi to selectively set itself a static IP address |
78 |
|
79 |
In this option you will set up in the Raspi's /etc/conf.d/net a static IP |
80 |
address 192.168.0.10/24, when the gateway matches the wireless MAC address of |
81 |
the home router. For any other gateway the Raspi will fall back to using |
82 |
dhcp. |
83 |
|
84 |
Something like this should work: |
85 |
|
86 |
# Define the gateway you want to configure |
87 |
gateways_eth0="192.168.0.254,AA:BB:CC:DD:EE:FF,192.168.0.10" |
88 |
|
89 |
# Define the default route for gateway 192.168.0.254 |
90 |
routes_192168000254_AABBCCDDEEFF="default via 192.168.0.254" |
91 |
|
92 |
# Define the IP and netmask when using gateway 192.168.0.254 |
93 |
config_192168000254_AABBCCDDEEFF="192.168.0.10/24" |
94 |
|
95 |
# Define the DNS servers to use with gateway |
96 |
dns_servers_192168000254_AABBCCDDEEFF="192.168.0.254" |
97 |
|
98 |
# Then you need to add a line for all other routers the Raspi may connect to: |
99 |
fallback_eth0="dhcp" |
100 |
|
101 |
|
102 |
NOTES |
103 |
===== |
104 |
192168000254 is the syntax used to represent an IP address for the home router |
105 |
of 192.168.0.254 |
106 |
|
107 |
AABBCCDDEEFF is the syntax used to represent a MAC address for the home router |
108 |
of AA:BB:CC:DD:EE:FF |
109 |
|
110 |
If your Raspi wireless NIC is not eth0, please adjust the fallback directive |
111 |
above accordingly. |
112 |
|
113 |
You may need to duplicate the above for any other NICs your Raspi may be end |
114 |
up with, for which you would want to configure a static IP address. |
115 |
|
116 |
-- |
117 |
Regards, |
118 |
Mick |