As the subject states…
perhaps this is possible with the lease script feature…
The script could either perform a ddns-update or add/modify the local IP > DNS > Static entries.
According to the Wiki:
lease-script:
Script that will be executed after lease is assigned or de-assigned. Internal “global” variables that can be used in the script:
leaseBound - set to “1” if bound, otherwise set to “0”
leaseServerName - dhcp server name
leaseActMAC - active mac address
leaseActIP - active IP address
You could use this information to accomplish your goal - but it sure would be a nice built-in feature as well.
Tryed that, but I’m stuck at getting the hostname to match with the IP.
the script eather runs too fast, or I am missing something.
:if ($leaseBound = “1”) do={
:local DhcpHostName “$[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name]”;
:log error “Creating new DNS entry for $DhcpHostName → $leaseActIP”
/ip dns static add address=“$leaseActIP” name=“$DhcpHostName” ttl=1d
} else={
:log error “Removing old DNS entry for $DhcpHostName → $leaseActIP”
}
runnung the line from terminal
:local DhcpHostName “$[/ip dhcp-server lease get [find where active-mac-address=$leaseActMAC && active-address=$leaseActIP] host-name]”;
with the MAC and IP in place of the variables, works fine
but this script returns an empty string.
The problem with running it from the terminal is that those globals are not set - they only exist when the script is called from a DHCP lease event.
I think the issue would also be pre-existing entries with the same IP address already being in the static entries.
As i said:
When i run that line from the terminal and replace the variables with the specific values, i get the host name i expect.
When the script runs - and i use the variables, the following happens:
I can LOG the IP and MAC as expected - configming that the variables have correct values, but the lice that gets the hostname returns an empty string.