其实我想根据客户端MAC地址分配bootfile-name。
我试过这个configuration:
option bootfile-name concat( binary-to-ascii(16, 8, "", substring (hardware, 1, 6)), ".cfg");
但是这是错误的configuration(因为DHCP服务器根本没有启动)。 如果不是concat(…)我把真正的文件名(例如“000102030405.cfg”),一切都好。 但这不是我所需要的。 有什么办法可以dynamic设置bootfile-name吗?
好吧,好消息。 我自己find了答案。 答案本身就在手册页中。 所有你需要的是使用expression式 。 这对任何选项(不仅是bootfile-name)都是正确的,你想从客户请求中分配一个值。
从man dhcp-options :
SETTING OPTION VALUES USING EXPRESSIONS 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));
所以,正如你所看到的,这个代码和我的唯一区别是等号 !
好奇的是,我的问题的答案是:
option bootfile-name = concat( binary-to-ascii(16, 8, "", substring (hardware, 1, 6)), ".cfg");
你有没有注意到“=”?