From ch_geronimo at foxmail.com Tue Dec 5 17:13:16 2023 From: ch_geronimo at foxmail.com (=?ISO-8859-1?B?Q0hfZ2Vyb25pbW8=?=) Date: Wed, 6 Dec 2023 01:13:16 +0800 Subject: Linux server management debian 10 and centos dhcp service host-name based Client Classing Message-ID: I have already asked a question on serverfault(https://serverfault.com/questions/1149090/linux-server-management-debian-10-and-centos-dhcp-service-host-name-based-client), but I didn't receive any useful response. So, I'm reaching out to you for help. Sorry for bothering you. I want to allocate a client's IP address based on the host-name provided by the client, but the results are often unpredictable.   I have tried to imitate the Client Classing in dhcpd.conf(5) by assigning    clients with host-name "Debian-xx" to the 192.168.100.0/24 subnet    clients with host-name "Centos-xx" to the 192.168.1.0/24 subnet.   I am using DHCP version 4.4.1. When I check the logs using "dhcpd -d", I noticed that the classing is not taking effect or there are errors. For example, the "Centos-xxx" clients might be assigned to the 192.168.100.0 or 192.168.255.0 subnet, and the assignments seem to be inconsistent.   This is the content of my dhcpd.conf file. ``` default-lease-time 10; use-host-decl-names on; max-lease-time 20; authoritarive ; log-facility local2; class "centos-server"{ match if (substring(option host-name ,0,6)="Centos") ; } class "debian-server"{ match if (substring (option host-name  ,0,6)="Debian") ; } subnet 192.168.0.0 netmask 255.255.0.0 { option routers 192.168.0.2; option subnet-mask 255.255.255.0; pool{ allow members of "centos-server"; range 192.168.100.1 192.168.100.254; } pool{ allow members of "dbian-server"; range 192.168.1.1 192.168.1.254; } pool{ range 192.168.255.1 192.168.255.254; } } on commit { log(debug, concat("test for   ",  substring(option host-name,0,6 ) ));  if ( ( substring( option host-name , 0, 6 ) ="Debian") ) { log(debug,"Debian!"); } else if ( ( substring( option host-name , 0, 6 ) ="Centos") ) { log(debug,"Centos!"); } else { log(debug,"i dont konw"); } } ``` This is the content of my dhclient.conf ``` send host-name = gethostname(); request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, domain-search, host-name, dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers, netbios-name-servers, netbios-scope, interface-mtu, rfc3442-classless-static-routes, ntp-servers; ``` I experimented with modifying the expression after "match if," such as using "or (1=1)," but the client may still not be assigned to that class.   I tried to see if it was an issue with "host-name" and "option host-name," but it doesn't seem to be the key issue.   I suspect there is an error in the conditional expression within the class, but the commit logs, I found that the log results alternated between "Centos!" and "I don't know".   I searched for related issues, such as this link [dhcpd class match on hostname or mac address](https://serverfault.com/questions/778719/dhcpd-class-match-on-hostname-or-mac-address), but it seems that the answers did not provide a good solution to the problem.   I want to know where my mistake lies, how to modify it, or if there are websites that provide solutions.   If you can provide assistance, I would be extremely grateful. -------------- next part -------------- An HTML attachment was scrubbed... URL: