I'm running a Raspbian on a bunch of Raspberry Pis. They each have a unique hostname set in /etc/hostname
and the dhcp client correctly registers that name with my router.
The problem I'm running into stems from having these Pis connected to the same network, and then same DHCP server, via ethernet and WiFi - There is a race-like condition that means the rest of the network, when using names to address these Pis, can't deterministically prefer the ethernet connections over the WiFi.
I'd like to make the Pis report a different hostname to the network DHCP server when obtaining a lease based on which interface they connect with. This seems to be possible in a static way by adding a lines like the following to /etc/dhcp/dhclient.conf
.
interface "wlan0" {
send host-name "MyHostname-1234-WiFi";
}
The problem I'm looking to solve is how to define that line programmatically. Something like this:
interface "wlan0" {
send host-name "<hostname>-WiFi";
}
Looking into the docs for dhclient.conf(5)
, it suggests I can use the concat
function from dhcp-eval(5)
but I'm not having success. I'm trying this:
interface "wlan0" {
send host-name concat(gethostname(), "-WiFi");
}
Just like in the related
option
statement, you have to explicitly mark expressions using an=
sign:If you dhclient call in verbose mode (
dhclient -cf myconfig.conf -v
) it will tell you about the syntax error it otherwise silently ignores.