dhcpd 伺服器 MAC 偵測無效

dhcpd 伺服器 MAC 偵測無效

在我的 DHCP 配置中,我使用 commit hook 來保存設備資訊。我的問題是一些 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改為以00or結尾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",
"");
}

相關內容