dhcpcd-discuss

Persistent static IP, via CLI

Igor Pellegrini

Thu Dec 17 17:53:16 2020

Hello everybody,

I'm pretty new to dhcpcd, we just met yesterday on a RaspberryPi, and I am trying to configure the network *without* relying on the `/etc/dhcpcd.conf`.
(I want to write some network configuration scripts, without messing with appending/removing instructions into the conf file).

The intention is to use DHCP on the interface, but always stick to the same IP, if this is available.
Ideally dhcpcd would be resilient to changing WiFi network and get an automatic lease when the IP is not available or we are in another subnet.

Unfortunately I've got no luck and I am struggling with the little feedback that running commands returns.
Also I am not very confident with networking and linux configuration.

This is what I've tried:
```
sudo dhcpcd --release wlan0
sudo dhcpcd -S ip_address=$WIFI_IP/$SUBNET_MASK \
                     -S routers=$GATEWAY \
                     -S domain_name_servers=$DNS1,$DNS2 \
                     wlan0
```
(yes, the `$WIFI_IP` is an available IP on the subnet)

This removes the leased IP, but then when restoring wlan0 it still gets the `old_ip_address`.
And I didn't manage to get the one I specified.

I also tried `dhcpcd --reconfigure --persistent`, `dhcpcd --request $WIFI_IP`, `dhcpcd --rebind wlan0`, but none of them seems to be effective.

My questions are:

1. how do I set the static IP so that it uses the one in $WIFI_IP, being sure that it is persisted and not lost when doing the reboot of my system?

2. how do I ensure that the configuration has been persisted?
There are no changes in `/etc/dhcpcd.conf` after running the commands above.
I wonder if `--persistent` is actually intended to write that file; and if it should be called as separate command or if it can be added to any command (but I guess it works just with `--rebind` or few others?)

3. how do I ensure that the syntax of my commands is correct? And how do I ensure that they take effect? Even using `--debug` I do not receive relevant informations about the request or the response, except for
>sending commands to master dhcpcd process
>send OK

Can you help me in wrapping my head about what I'm doing/understanding incorrectly? =)

PS - it's almost 20 years I don't write to a mailing list, I hope I'm doing it correctly ^__^

Follow-Ups:
Re: Persistent static IP, via CLIRoy Marples
Archive administrator: postmaster@marples.name