dhcpcd-discuss

Re: dhcpcd for static addresses on the Raspberry Pi

Roy Marples

Wed Mar 30 07:22:34 2016

Hi Richard

On Tuesday 29 March 2016 15:51:46 Richard Urwin wrote:
> I'm a moderator over on the Raspberry Pi forum.
> 
> You might be aware of the Raspberry Pi -- a $25 Single Board Computer that
> has been very popular over the last few years (over 8 million sold.) Many
> of our users are school children or other folk that don't have an indepth
> knowledge of or interest in networking -- they just want something that
> works and clear instructions. As of the last few months the default
> operating system for the Pi is now based on Debian Jessie, with dhcpcd in
> control of the configuration of the network interfaces.
> 
> 
> For most of our users this works very well and they never need to touch any
> configuration files; the Pi gets a DHCP allocation and all is well.
> 
> However a small but significant number of users need to allocate a static
> IP address and cannot make that allocation on a DHCP server.
> 
> The simple way to do that is with a dhcpcd.conf file that looks like:
> interface eth0
> static ip_address=192.168.1.101/24
> static routers=192.168.1.1
> However, SBCs are portable by nature and moving one with this configuration
> to a different network means it needs reconfiguring with an attached
> keyboard and screen. It is far better to use arping lines to recognise the
> network that it is attached to and configure itself appropriately, maybe
> with a fallback allocation if it doesn't recognise the network and can't
> find a DHCP server.

...

> How should we recommend that our users configure static IP addresses for
> two interfaces?


Well, to be blunt, the problems you are describing sound of your own making.
In todays world there is little need of static IP configuration. I have many Pi 
like devices (mainly OpenWRT based units) and yes I do have a Pi. None of them 
have a static IP and dhcpcd runs with a stock config. Here I run a DHCP server 
with static IP allocations to the units that need to be up 100% or are 
extremely brickable.

Sometimes I take these units out of the production loop (for upgrade, 
maintenance, etc) and place them into an ad-hoc network where there is no DHCP 
server. I still access these units by hostname and it works fine - thanks to 
IPv4LL (provided by dhcpcd) and mDNS (provided by something else).

I really don't recall the last time I accessed any of my units by IP address 
alone :)

Now if you're still wanting to go with something not IPv4LL for reasons of 
your own, you can still use arping profiles.

> This is all well and good, but when the Pi has two network interfaces --
> invariably eth0 and wlan0 -- we don't understand how we can use arping, or
> any other method, to allocate a different IP address to the two interfaces.
> The profiles seem to be shared between all the interfaces.

They are shared between the interfaces.
If both interfaces exist on the same L2 network and both run arping profiles 
then they will get the same address. Truthfully I've not tested this but it 
should still work - the interface with the lowest metric will be "preferred".

On the other hand, if there is >1 unique node then it's possible if you arping 
different ip's per interface

interface eth0
arping 192.168.0.1 10.0.0.1

interface wlan0
arping 192.168.0.2 10.0.0.2

profile 192.168.0.1
static ip_address=192.168.0.10/24

profile 192.168.0.2
static ip_address=192.168.0.11/24

profile 10.0.0.1
static ip_address=10.0.0.8/24

profile 10.0.0.2
static ip_address=10.0.0.20/24

> I've noticed some very old posts in this list using the MAC address as a
> profile name, but no documentation I have found describes this, and it
> would only help for a single arping of course.

Documented here:
http://roy.marples.name/projects/dhcpcd/ci/81ae07e7749cda18?sbs=0

The MAC address arping method is mainly of use when changing networks to one 
in the same IP range but with a different static address. It's of no use to get 
different addresses if both interfaces are on the same L2 network.

Hopefully this answers your questions :)

Roy

References:
dhcpcd for static addresses on the Raspberry PiRichard Urwin
Archive administrator: postmaster@marples.name