dhcpd 服务器无效 MAC 检测

dhcpd 服务器无效 MAC 检测

在我的 DHCP 配置中,我有一个提交挂钩来保存设备信息。我的问题是某些 MAC 地址变得无效:

8:7c:39:cf:b6:3f- 这应该从零开始

8:d0:b7:52:f9:68- 还有这个

我的dhcpd.conf

set clientmac = binary-to-ascii(16,8,":",substring(hardware,1,6));

答案1

这取决于您用什么来解析它,有人可能会说省略前缀零是完全有效的,而这正是我们大多数时候所做的,因为没有定义应该有多少位数字。

但是,如果我们跳过关于这是否无效以及为什么无效的部分,而是问“如何以所需的格式获取它”,我们就可以提供答案。

在这种情况下isc 有一篇关于此的知识库文章

这不是一个错误。问题在于二进制到 ASCII 函数对转换后的二进制数字的预期用途一无所知,并且在打印数值时包含前导零的情况并不常见。

但是,经过一些额外的操作仍然可以获得所需的结果:

set foo = concat (
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2)
);

(它的工作原理是分别转换每个“组件”,在其前导零中添加一个零(如果需要的话);取最后两个十六进制字符,然后将它们再次连接在一起。)

答案2

这不是答案,但我只是想分享这个配置。DHCP 服务器将 bootfile-name(选项 67)设置为包含客户端的 mac 地址。但 mac 被更改为以00或结尾80。这是 Cisco 交换机的基本 mac 地址。因此,无论交换机从其 mac 地址池中使用哪个 mac。它仍将获得相同的配置文件。

# Option 66
option tftp-server-name "198.51.100.19";

# Option 67
# Set to "switch-config/by-mac/<mac-of-client>"
# If the mac ends with 80-ff, set it to 80, else 00.
# Because the base MAC either ends with 00 or 80.
if substring(suffix (concat ("0", binary-to-ascii (2, 8, "", substring(hardware,6,1))),8), 0, 1) = "1"
{
option bootfile-name = concat(
"switch-config/by-mac/",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2),
"80",
"");
} else {
option bootfile-name = concat(
"switch-config/by-mac/",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2),
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2),
"00",
"");
}

相关内容