guarantee RFC standardized hostname
Glenn Satchell
glenn.satchell at uniq.com.au
Thu Aug 25 14:35:35 UTC 2011
man dhcp-eval
...
data-expression-1 ~= data-expression-2 data-expression-1 ~~
data-expression-2
The ~= and ~~ operators (not available on all systems)
perform extended regex(7) matching of the values of two
data expressions, returning true if data-expression-1
matches against the regular expression evaluated by data-
expression-2, or false if it does not match or encounters
some error. If either the left-hand side or the right-
hand side are null, the result is also false. The ~~
operator differs from the ~= operator in that it is case-
insensitive.
So you might want something like this then, where you list all the
"good" characters in the regex string on the right? I haven't tested
this, but I'm sure you get the idea...
if exists host-name and option host-name ~~ "[a-z0-9.-]+" {
ddns-hostname = concat (lcase (option host-name) , "-" ,
binary-to-ascii(10 , 8 , "-" , leased-address));
}
else {
ddns-hostname = concat("dhcp-" , binary-to-ascii(10 , 8 , "-"
leased-address));
}
regards,
-glenn
On 08/25/11 07:25, Kevin Fitzgerald wrote:
> Hi Group,
>
> For quite some time we have been generating DHCP ddns hostnames as follows:
>
> if exists host-name {
> ddns-hostname = concat (lcase (option host-name) , "-" ,
> binary-to-ascii(10 , 8 , "-" , leased-address));
> }
> else {
> ddns-hostname = concat("dhcp-" , binary-to-ascii(10 , 8 , "-" ,
> leased-address));
> }
>
> This is not an uncommon format. It helps us ensure unique host names on
> our network. Lately I notice a handful of user devices that present
> host names with invalid characters, such as android_blah or "nintendo
> 3ds" with a space in the middle (no quotes).
> What are you folks doing to mitigate this? As it stands these users do
> not receive valid NS records and we get a bevy of log messages when
> illegal characters are in the hostname.
>
> - I have seen mention of the use of regex in the man pages for
> dhcp-eval. Is there a method to examine the host-name for invalid
> characters, replacing them with a hyphen or otherwise? (Is there
> REGEX evaluation available within dhcpd.conf)
> - if there is no way to do a character by character replace, can I fail
> down to my else condition, simply prepending dhcp- to the front of the
> IP address?
> --
> K. Fitzgerald
> UALR Information Technology Services
>
>
More information about the dhcp-users
mailing list