내 DHCP 구성에는 장치 정보를 저장하기 위한 커밋 후크가 있습니다. 내 문제는 일부 MAC 주소가 유효하지 않게 된다는 것입니다.
8:7c:39:cf:b6:3f
- 0부터 시작해야 합니다.
8:d0:b7:52:f9:68
- 이것도
나의dhcpd.conf
set clientmac = binary-to-ascii(16,8,":",substring(hardware,1,6));
답변1
구문 분석에 무엇을 사용하는지에 따라 다르며, 접두사 0을 생략하는 것이 완전히 유효하다고 주장할 수 있으며, 몇 자릿수가 있어야 하는지에 대한 정의가 없기 때문에 우리가 대부분의 시간에 수행하는 작업입니다.
그러나 이것이 유효하지 않은지, 그 이유가 무엇인지에 대한 부분을 건너뛰고 대신 "이것을 원하는 형식으로 얻으려면 어떻게 해야 합니까?"라고 묻는다면 답변을 제공할 수 있습니다.
이것은 버그가 아닙니다. 문제는 이진수를 ASCII로 변환하는 함수가 변환된 이진수의 의도된 사용에 대해 아무것도 "알지" 못하고 숫자 값을 인쇄할 때 앞에 0을 포함하는 것이 일반적이지 않다는 것입니다.
그러나 약간의 추가 조작을 통해 여전히 원하는 결과를 얻을 수 있습니다.
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)
);
(각 "구성 요소"를 개별적으로 변환하고 앞에 0을 추가하고(필요한 경우) 마지막 두 개의 16진수 문자를 가져온 다음 모두 다시 연결하는 방식으로 작동합니다.)
답변2
답변은 아니지만 이 구성을 공유하고 싶습니다. DHCP 서버는 클라이언트의 mac 주소를 포함하도록 bootfile-name(옵션 67)을 설정합니다. 그러나 Mac은 00
or 로 끝나도록 변경되었습니다 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",
"");
}