On some HP models, a setting ("DHCPv4 FQDN RFC 4702 Compliance") I was able to disable fixed the hostname issue, but on some very new ones, this doesn't seem to help.
So I set a DNS manually.
BUT, if the user restarts the device, the script I found (I found it at this site) unregisters the static DNS I've added.
So I would like to modify the script to check the TTL value of the DNS entry, and it it is 1d, I'd like it to not delete the DNS entry.
Here is the script I am using, can anyone help me?
I believe that last condition (" :if ( [ :len $dnsDhcpId ] > 0 ) do=\") needs to be modified but I'm not familiar with this programming language.
*****
Code: Select all
:local DHCPtag
:if ( [ :len $leaseActIP ] <= 0 ) do={ :error "empty lease address" }
:if ( $leaseBound = 1 ) do=\
{
:local ttl
:local domain
:local hostname
:local fqdn
:local leaseId
:local comment
/ip dhcp-server
:set ttl [ get [ find name=$leaseServerName ] lease-time ]
network
:set domain [ get [ find $leaseActIP in address ] domain ]
.. lease
:set leaseId [ find address=$leaseActIP ]
# Check for multiple active leases for the same IP address. It's weird and it shouldn't be, but just in case.
:if ( [ :len $leaseId ] != 1) do=\
{
:log info "DHCP2DNS: not registering domain name for address $leaseActIP because of multiple active leases for $leaseActIP"
:error "multiple active leases for $leaseActIP"
}
:set hostname [ get $leaseId host-name ]
:set comment [ get $leaseId comment ]
/
:if ( [ :len $hostname ] <= 0 ) do={ :set hostname $comment }
:if ( [ :len $hostname ] <= 0 ) do=\
{
:log error "DHCP2DNS: not registering domain name for address $leaseActIP because of empty lease host-name or comment"
:error "empty lease host-name or comment"
}
:if ( [ :len $domain ] <= 0 ) do=\
{
:log error "DHCP2DNS: not registering domain name for address $leaseActIP because of empty network domain name"
:error "empty network domain name"
}
:set fqdn "$hostname.$domain"
/ip dns static
:if ( [ :len [ find name=$fqdn and address=$leaseActIP and disabled=no ] ] = 0 ) do=\
{
:log info "DHCP2DNS: registering static domain name $fqdn for address $leaseActIP with ttl $ttl"
add address=$leaseActIP name=$fqdn ttl=$ttl disabled=no
} else=\
{
:log error "DHCP2DNS: not registering domain name $fqdn for address $leaseActIP because of existing active static DNS entry with this name or address"
}
/
} \
else=\
{
/ip dns static
:local dnsDhcpId
:set dnsDhcpId [ find address=$leaseActIP ]
:if ( [ :len $dnsDhcpId ] > 0 ) do=\
{
:log info "DHCP2DNS: removing static domain name(s) for address $leaseActIP"
remove $dnsDhcpId
}
/
}