Linux

Isc-Dhcpserver 靜態 DHCP 缺少客戶端主機名

  • June 23, 2017

我的 isc-dhcpserver (Ubuntu 16.04) 遇到了一個奇怪的問題。

當客戶端從伺服器請求時,我可以在 /var/log/syslog 中看到以下輸出:

Jun 21 21:41:25 drake dhcpd[265]: DHCPREQUEST for 192.168.0.113 (192.168.0.254) from ea:25:63:d9:6c:10 (webdev) via eth1
Jun 21 21:41:25 drake dhcpd[265]: DHCPACK on 192.168.0.113 to ea:25:63:d9:6c:10 (webdev) via eth1

/var/lib/dh​​cp/dhcpd.leases 對於這個租約看起來像這樣:

lease 192.168.0.113 {
 starts 3 2017/06/21 19:41:25;
 ends 4 2017/06/22 01:41:25;
 cltt 3 2017/06/21 19:41:25;
 binding state active;
 next binding state free;
 rewind binding state free;
 hardware ethernet ea:25:63:d9:6c:10;
 client-hostname "webdev";

現在讓我們將其修改為靜態 DHCP:/etc/dhcp/dhcpd.conf:

host webdev {
       hardware ethernet ea:25:63:d9:6c:10;
       fixed-address 192.168.0.220;
}

/var/log/syslog 的輸出缺少客戶端主機名:

Jun 21 22:37:37 drake dhcpd[1627]: DHCPDISCOVER from ea:25:63:d9:6c:10 via eth1
Jun 21 22:37:37 drake dhcpd[1627]: DHCPOFFER on 192.168.0.220 to ea:25:63:d9:6c:10 via eth1
Jun 21 22:37:37 drake dhcpd[1627]: DHCPREQUEST for 192.168.0.220 (192.168.0.254) from ea:25:63:d9:6c:10 via eth1
Jun 21 22:37:37 drake dhcpd[1627]: DHCPACK on 192.168.0.220 to ea:25:63:d9:6c:10 via eth1

即使mac地址連結到靜態IP,有沒有辦法讓dhcp伺服器在日誌文件中顯示客戶端主機名?

我真的認為我以前做過這個……據我所知,這在我以前的舊 Slackware 伺服器上執行良好。

執行 isc-dhcpserver 的伺服器正在執行應用了最新更新的 Ubuntu 伺服器 16.04。

嘗試使用日誌功能。我在ISC 郵件列表中找到了範例:靜態客戶端:如何記錄主機名並創建租約條目? 添加到 dhcpd 配置文件的全域部分:

on commit {
 if (static){set isst = "static";} else {set isst = "dynamic";}
 log (info, concat ("COMMIT IP,", binary-to-ascii (10,8,".",leased-address),
   ",MAC,", suffix (concat ("0", substring(binary-to-ascii (16, 8, ":",hardware), 2, 17)),17),
   ",hostname,", option host-name,
   ",host-decl-name,", pick-first-value(host-decl-name, "(none)"),
   ",dhcp-client-identifier,",pick-first-value(binary-to-ascii(16,8,"",option dhcp-client-identifier),"(none)"),
   ",vendor-class-identifier,", pick-first-value(option vendor-class-identifier, "(none)"),
   ",agent.remote,", pick-first-value(option agent.remote-id, "(none)"),
   ",agent.circuit,", pick-first-value(option agent.circuit-id, "(none)"),
   ",leasetime,", binary-to-ascii (10,32,"",encode-int (lease-time,32)),
   ",asstype,", isst)
 );
}

但是 dhcp-client 必須在 DHCPREQUEST 或 DHCPDISCOVER 中發送其客戶端主機名作為選項 12。並非所有 dhcp-clients 預設情況下都會這樣做。

引用自:https://serverfault.com/questions/857145