0

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");
}

1 Answers1

2

Just like in the related option statement, you have to explicitly mark expressions using an = sign:

  send host-name "static-value";
  send host-name = concat(gethostname(), "dynamic-value");

If you dhclient call in verbose mode (dhclient -cf myconfig.conf -v) it will tell you about the syntax error it otherwise silently ignores.

anx
  • 6,875
  • 4
  • 22
  • 45