dhcp-to-dns: support to ignore networks

Closes: https://github.com/eworm-de/routeros-scripts/issues/119
This commit is contained in:
Christian Hesse 2026-03-16 11:27:14 +01:00
parent 3e34f2d88a
commit b5e6b9cb55
2 changed files with 15 additions and 5 deletions

View file

@ -72,15 +72,21 @@
:continue;
}
:local Comment ($CommentPrefix . ", macaddress=" . $LeaseVal->"active-mac-address" . ", server=" . $LeaseVal->"server");
:local MacDash [ $CleanName ($LeaseVal->"active-mac-address") ];
:local HostName [ $CleanName [ $EitherOr ([ $ParseKeyValueStore ($LeaseVal->"comment") ]->"hostname") ($LeaseVal->"host-name") ] ];
:local Network [ /ip/dhcp-server/network/find where ($LeaseVal->"active-address") in address ];
:local NetworkVal;
:if ([ :len $Network ] > 0) do={
:set NetworkVal [ /ip/dhcp-server/network/get ($Network->0) ];
}
:local NetworkInfo [ $ParseKeyValueStore ($NetworkVal->"comment") ];
:if ($NetworkInfo->"dns-ignore" = true) do={
$LogPrint debug $ScriptName ("Lease for " . $LeaseVal->"active-mac-address" . " is in ignored network... Skipping.");
:continue;
}
:local Comment ($CommentPrefix . ", macaddress=" . $LeaseVal->"active-mac-address" . ", server=" . $LeaseVal->"server");
:local MacDash [ $CleanName ($LeaseVal->"active-mac-address") ];
:local HostName [ $CleanName [ $EitherOr ([ $ParseKeyValueStore ($LeaseVal->"comment") ]->"hostname") ($LeaseVal->"host-name") ] ];
:local NetDomain ([ $IfThenElse ([ :len ($NetworkInfo->"name-extra") ] > 0) ($NetworkInfo->"name-extra" . ".") ] . \
[ $EitherOr [ $EitherOr ($NetworkInfo->"domain") ($NetworkVal->"domain") ] $Domain ]);
:local FullA ($MacDash . "." . $NetDomain);

View file

@ -50,8 +50,12 @@ A bound lease for mac address `00:11:22:33:44:55` with ip address
`10.0.0.50` would result in an A record `00-11-22-33-44-55.example.com`
pointing to the given ip address.
Additional options can be given from comment, to add an extra level in
dns name or define a different domain.
Additional options can be given from comment, first of all you can opt-out
for specific networks:
/ip/dhcp-server/network/add address=10.0.0.0/24 domain=example.com comment="dns-ignore=true";
Use this to add an extra level in dns name or define a different domain.
/ip/dhcp-server/network/add address=10.0.0.0/24 domain=example.com comment="domain=another-domain.com, name-extra=dhcp";