dhcp-to-dns: get domain from dhcp server's network definition
This commit is contained in:
parent
ac5d84173f
commit
ee94024dca
|
@ -13,10 +13,7 @@
|
|||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||
|
||||
:global Domain;
|
||||
:global HostNameInZone;
|
||||
:global Identity;
|
||||
:global PrefixInZone;
|
||||
:global ServerNameInZone;
|
||||
|
||||
:global CharacterReplace;
|
||||
:global EitherOr;
|
||||
|
@ -27,9 +24,6 @@
|
|||
|
||||
$ScriptLock $0 false 10;
|
||||
|
||||
:local Zone \
|
||||
([ $IfThenElse ($PrefixInZone = true) "dhcp." ] . \
|
||||
[ $IfThenElse ($HostNameInZone = true) ($Identity . ".") ] . $Domain);
|
||||
:local Ttl 5m;
|
||||
:local CommentPrefix ("managed by " . $0 . " for ");
|
||||
:local CommentString ("--- " . $0 . " above ---");
|
||||
|
@ -70,7 +64,14 @@ $ScriptLock $0 false 10;
|
|||
:local Comment ($CommentPrefix . $LeaseVal->"mac-address");
|
||||
:local MacDash [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ];
|
||||
:local HostName [ $CharacterReplace [ $EitherOr ([ $ParseKeyValueStore ($LeaseVal->"comment") ]->"hostname") ($LeaseVal->"host-name") ] " " "" ];
|
||||
:local NetDomain ([ $IfThenElse ($ServerNameInZone = true) ($LeaseVal->"server" . ".") ] . $Zone);
|
||||
:local Network [ /ip/dhcp-server/network/find where ($LeaseVal->"address") in address ];
|
||||
:local NetworkVal;
|
||||
:if ([ :len $Network ] > 0) do={
|
||||
:set NetworkVal [ /ip/dhcp-server/network/get ($Network->0) ];
|
||||
}
|
||||
:local NetworkInfo [ $ParseKeyValueStore ($NetworkVal->"comment") ];
|
||||
:local NetDomain ([ $IfThenElse ([ :len ($NetworkInfo->"name-extra") ] > 0) ($NetworkInfo->"name-extra" . ".") ] . \
|
||||
[ $EitherOr [ $EitherOr ($NetworkInfo->"domain") ($NetworkVal->"domain") ] $Domain ]);
|
||||
|
||||
:local DnsRecord [ /ip/dns/static/find where comment=$Comment (!type or type=A) ];
|
||||
:if ([ :len $DnsRecord ] > 0) do={
|
||||
|
|
|
@ -34,12 +34,27 @@ On first run a disabled static dns record acting as marker (with comment
|
|||
"`--- dhcp-to-dns above ---`") is added. Move this entry to define where new
|
||||
entries are to be added.
|
||||
|
||||
The configuration goes to `global-config-overlay`, these are the parameters:
|
||||
The configuration goes to dhcp server's network definition. The domain is
|
||||
used to form the dns name:
|
||||
|
||||
/ip/dhcp-server/network/add address=10.0.0.0/24 domain=example.com;
|
||||
|
||||
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.
|
||||
|
||||
/ip/dhcp-server/network/add address=10.0.0.0/24 domain=example.com comment="domain=another-domain.com, name-extra=dhcp";
|
||||
|
||||
This example would result in name `00-11-22-33-44-55.dhcp.another-domain.com`
|
||||
for the same lease.
|
||||
|
||||
If no domain is found in dhcp server's network definition a fallback from
|
||||
`global-config-overlay` is used. This is the parameter:
|
||||
|
||||
* `Domain`: the domain used for dns records
|
||||
* `HostNameInZone`: whether or not to add the dhcp/dns server's hostname
|
||||
* `PrefixInZone`: whether or not to add prefix `dhcp`
|
||||
* `ServerNameInZone`: whether or not to add DHCP server name
|
||||
|
||||
### Host name from DHCP lease comment
|
||||
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
|
||||
# This is used for DNS and backup file.
|
||||
:global Domain "example.com";
|
||||
:global HostNameInZone true;
|
||||
:global PrefixInZone true;
|
||||
:global ServerNameInZone false;
|
||||
|
||||
# You can send e-mail notifications. Configure the system's mail settings
|
||||
# (/tool/e-mail), then install the module:
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
:local 0 "global-functions";
|
||||
|
||||
# expected configuration version
|
||||
:global ExpectedConfigVersion 98;
|
||||
:global ExpectedConfigVersion 99;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
96="Added support for notes in 'netwatch-notify', these are included verbatim into the notification.";
|
||||
97="Modified 'dhcp-to-dns' to always add A records for names with mac address, and optionally add CNAME records if the host name is available.";
|
||||
98="Extended 'check-certificates' to download new certificate by SubjectAltNames if download by CommonName fails.";
|
||||
99="Modified 'dhcp-to-dns', which dropped global configuration. Settings moved to dhcp server's network definitions.";
|
||||
};
|
||||
|
||||
# Migration steps to be applied on script updates
|
||||
|
|
Loading…
Reference in New Issue