Actually I want to dinamically assign bootfile-name based on clients MAC.

I have tried this config:

option bootfile-name concat( binary-to-ascii(16, 8, "", substring (hardware, 1, 6)), ".cfg");

But this is wrong config (as dhcp server isn't starting at all). If instead of concat(...) I put just real filename (e.g. "000102030405.cfg") everything is ok. But this is not what I need. Is there any way to dynamically set bootfile-name?


Well, good news. I found an answer by myself. The answer itself was in man pages. All you need is to use EXPRESSIONS. This is correct for any option (not only bootfile-name), to which you want assign a value from client's request.

From the man dhcp-options:

   Sometimes it's helpful to be able to set the value of a DHCP option based on
   some value that the client has sent.   To do this, you can use expression
   evaluation. The dhcp-eval(5) manual page describes how to write expressions.
   To assign the result of an evaluation to an option,
   define the option as follows:

     option my-option = expression ;

   For example:

     option hostname = binary-to-ascii (16, 8, "-", substring (hardware, 1, 6));

So, as you can see, the only difference between this code and mine is equal sign!

For curious one, the answer to my question is:

option bootfile-name = concat( binary-to-ascii(16, 8, "",
                               substring (hardware, 1, 6)), ".cfg");

Did you noticed "="?


110022334455 becomes 11022334455 in the ASCII output

see also: https://kb.isc.org/article/AA-01039/0/Formatting-MAC-addresses-in-dhcpd-or-why-does-binary-to-ascii-strip-leading-zeroes.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.