Community discussions

MikroTik App
 
User avatar
tplecko
Member Candidate
Member Candidate
Topic Author
Posts: 120
Joined: Mon Jun 11, 2007 12:18 pm
Location: Croatia
Contact:

Feature Request: Add/remove static DNS record on DHCP lease bound/unbound

Wed Mar 09, 2016 4:03 pm

As the subject states...
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Feature Request: Add/remove static DNS record on DHCP lease bound/unbound

Wed Mar 09, 2016 4:29 pm

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.
 
User avatar
tplecko
Member Candidate
Member Candidate
Topic Author
Posts: 120
Joined: Mon Jun 11, 2007 12:18 pm
Location: Croatia
Contact:

Re: Feature Request: Add/remove static DNS record on DHCP lease bound/unbound

Wed Mar 09, 2016 4:40 pm

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.
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Feature Request: Add/remove static DNS record on DHCP lease bound/unbound

Wed Mar 09, 2016 7:52 pm

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.
 
User avatar
tplecko
Member Candidate
Member Candidate
Topic Author
Posts: 120
Joined: Mon Jun 11, 2007 12:18 pm
Location: Croatia
Contact:

Re: Feature Request: Add/remove static DNS record on DHCP lease bound/unbound

Thu Mar 10, 2016 11:29 am

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.

Who is online

Users browsing this forum: Google [Bot], NxtGen [Bot] and 183 guests