Apologies for the tortured title but I'll explain the question more clearly:
We have a headless Pi compute module (CM4) which needs to be remotely configurable, and that includes being able to send it a command to configure a static IP address, gateway, netmask, etc. (or set it to DHCP) and have this setting persist across reboots.
I've done this before in various embedded Linuxes and there seems to be several ways of doing it depending on when the StackOverflow question was last asked and which specific Linux flavour you're using... so I am here asking what's the right way of doing this in 2022 on a CM4 running the latest Raspbian?
Ideally something doable / callable from within standard C code.
EDIT: No, we cannot just do this from the DHCP server as there's no guarantee there IS one in any given installation or that it's configurable, it's an operational requirement of THIS hardware that it can be set to a static IP configuration regardless of the network it's currently plugged into.
dhcpcd
: Have you tried?: Create twodhcpcd.conf
files inetc
(e.gdhcpcd.static.conf
, anddhcpcd.dynamic.conf
), and then do amv dhcpcd.dynamic.conf dhcpcd.conf
to "swap" to the one you want. Afterwards, you'll need to telldhcpcd
to re-read itsdhcpcd.conf
file. – Seamus Oct 17 '22 at 15:03ip
with popen() or something. – John U Oct 17 '22 at 15:13dhcpcd
in the not-distant future, and of course some are moving already. Personally, I feeldhcpcd
is the better choice, but... Anyway - yes, write one conf file for using dynamic address assignment, and another for static - if you feel you need a static config at all. – Seamus Oct 18 '22 at 05:47