Comments (10)
Actually, since the comment from the access list is already being brought over to the DHCP Leases, perhaps things could simplified and just have an option to use the comment from DHCP.
from routeros-scripts.
Comments from Telegram Chat, in case it has some more important details:
DHCP comments for dns names would be a nice addition, as it would be in sync with using access list comments for dhcp entries and it would also remove issues with multiple entries and some items reporting information wrong, such as using blocky as a dns proxy. If i have multiple entries, when i look at the statistics it will show one or the other. I am open to discussion about any reason this should not be a good feature request.
also it would remove some of the inconsistencies i have come across. for example, at times phone entries will go in as mac address naming into DNS. etc
I'd be willing to donate a case of beer for the cause :D
or perhaps i could attempt to write it myself and contribute.
from routeros-scripts.
Well, all the DHCP leases and DNS static records stuff is kind of tricky. I am happy that it kind of works currently. 😜
There are some issues with this:
- Currently the order is:
dhcp-to-dns
->collect-wireless-mac
->dhcp-lease-comment
... This make sense as I have the DNS name in place to add it into the notification fromcollect-wireless-mac
. To get the info intodhcp-to-dns
I would have to switch order - which causes other troubles - or try to get the info from access list directly. The latter would require to duplicate the script for local wireless and caps-man. - The comment in access list is not limited in what it is allowed to contain. Actually it is intended to contain human readable information. Squeezing that into valid DNS names could be troublesome. 😝
- Probably more I do not recognize now.
However I do agree that it is inconsistent to have the mac address for some and host name (if available) for other records. So I am preparing some changes now. The plan is to always have an A
type records with the mac address, and a CNAME
type records pointing to the A
record if the host name is available. (To test this install dhcp-to-dns
from next
branch.)
So wondering if you could just create another CNAME
type record that suits your needs. It can always point to the A
type record with the mac address then, and it resolves correctly even if the ip address changes.
from routeros-scripts.
Also could you give some more detail on the issue with blocky dns proxy and the statistics thing that shows one or the other? Or is that solved by using CNAME
type records?
from routeros-scripts.
However I do agree that it is inconsistent to have the mac address for some and host name (if available) for other records. So I am preparing some changes now. The plan is to always have an
A
type records with the mac address, and aCNAME
type records pointing to theA
record if the host name is available. (To test this installdhcp-to-dns
fromnext
branch.)
Could an option be created that would do a CNAME record that is pointing to the A record if the hostname OR a comment is available? I would imagine you could make an option switch in the global-config that would let you ask a preference of which one.
Either hostname OR comment, or prefer comment over hostname or something along those lines.
Also could you give some more detail on the issue with blocky dns proxy and the statistics thing that shows one or the other? Or is that solved by using
CNAME
type records?
Not certain why this does this. I would have to look further into way blocky operates.
from routeros-scripts.
The issues from above would still apply, no?
Thinking about it, but as soon as the comment from access list comes into the game things become a lot more complex.
from routeros-scripts.
I suppose it isn't that complicated from my perspective as my access list comments are pretty simple. I set the comment to the hostname or purpose. For example, my kids laptop is named link, so i just comment it as "link" (big zelda fans here :D). My doorbell is simply "camera-doorbell". My backdoor camera is simply "camera-backdoor", cellphone is simply "dads-cellphone". This carries over to the dhcp server comments. The option would be nice to allow that comment to be placed in as the dns entry as well.
With that said, based on MY personal use case, my suggestion would be to have the MAC address as the A record, a CNAME with the hostname if available, but allow an override to allow the DHCP comment as the A record or CNAME, if that option is defined in config and it is available. I personally do not like the idea of MAC address as a dns record, but i can see the desire to have SOMETHING that is consistent and that is one thing that would be consistent.
I will make an attempt to mock something up and submit a patch to see if you find it usable for your scripts.
from routeros-scripts.
You should not spread the discussion over at least three places... Let's keep it here.
I gave it some more thought and came up with 7d5c839... It does not use plain comment, but would require you to set hostname=link
for your kid's laptop.
Also note that this requires a second execution of the script with the default order of lease scripts if the comment comes from access list.
from routeros-scripts.
No worries @eworm-de. My intention of messaging you over the Telegram chat was not to fragment the conversation. I had some questions about scripting under routeros, and I assumed that would be a quicker way to chat. My intention was to share my work here.
I rather like your solution. I can just put `hostname=link" in the access list and it would eventually carry over, it looks like.
Here is what I came up with today. You can use the modified dhcp-to-dns.rsc below by setting the following in global-config-overlay
UseDHCPConfig true;
How this will work is it will first use a comment from the dhcp server, if available. If not it will use the hostname and lastly if neither is available it will create an A record with the mac address.
Setting that will also forego the creation of the CNAME.
This is just a quick hack to demonstrate the functionality that I had in mind.
dns-to-dhcp;
#!rsc by RouterOS
# RouterOS script: dhcp-to-dns
# Copyright (c) 2013-2023 Christian Hesse <[email protected]>
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
#
# provides: lease-script, order=20
#
# check DHCP leases and add/remove/update DNS entries
# https://git.eworm.de/cgit/routeros-scripts/about/doc/dhcp-to-dns.md
:local 0 "dhcp-to-dns";
:global GlobalFunctionsReady;
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
:global Domain;
:global HostNameInZone;
:global Identity;
:global PrefixInZone;
:global ServerNameInZone;
:global UseDHCPComment;
:global CharacterReplace;
:global IfThenElse;
:global LogPrintExit2;
:global ScriptLock;
$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 ---");
:if ([ :len [ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ] ] = 0) do={
/ip/dns/static/add name=$CommentString type=NXDOMAIN disabled=yes;
$LogPrintExit2 warning $0 ("Added disabled static dns record with name '" . $CommentString . "'.") false;
}
:local PlaceBefore ([ /ip/dns/static/find where (name=$CommentString or (comment=$CommentString and name=-)) type=NXDOMAIN disabled ]->0);
:foreach DnsRecord in=[ /ip/dns/static/find where comment~("^" . $CommentPrefix) !(type=CNAME) ] do={
:local DnsRecordVal [ /ip/dns/static/get $DnsRecord ];
:local MacAddress [ $CharacterReplace ($DnsRecordVal->"comment") $CommentPrefix "" ];
:if ([ :len [ /ip/dhcp-server/lease/find where mac-address=$MacAddress address=($DnsRecordVal->"address") status=bound ] ] > 0) do={
$LogPrintExit2 debug $0 ("Lease for " . $MacAddress . " (" . $DnsRecordVal->"name" . ") still exists. Not deleting DNS entry.") false;
} else={
:local Found false;
$LogPrintExit2 info $0 ("Lease expired for " . $MacAddress . " (" . $DnsRecordVal->"name" . "), deleting DNS entry.") false;
/ip/dns/static/remove $DnsRecord;
/ip/dns/static/remove [ find where type=CNAME cname=($DnsRecordVal->"name") comment=($DnsRecordVal->"comment") ];
}
}
:foreach Lease in=[ /ip/dhcp-server/lease/find where status=bound ] do={
:local LeaseVal;
:do {
:set LeaseVal [ /ip/dhcp-server/lease/get $Lease ];
} on-error={
$LogPrintExit2 debug $0 ("A lease just vanished, ignoring.") false;
}
:if ([ :len ($LeaseVal->"address") ] > 0) do={
:local Comment ($CommentPrefix . $LeaseVal->"mac-address");
:local HostnameSet [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ];
:local HostName [ $CharacterReplace ($LeaseVal->"host-name") " " "" ];
:local Domain ([ $IfThenElse ($ServerNameInZone = true) ($LeaseVal->"server" . ".") ] . $Zone);
:if ($UseDHCPComment = true && [ :len ($LeaseVal->"comment") ] > 0) do={ :set HostnameSet ($LeaseVal->"comment"); }
:if ($UseDHCPComment = true && [ :len ($LeaseVal->"comment") ] = 0 && [ :len $HostName ] > 0) do={ :set HostnameSet ($HostName); }
:local DnsRecord [ /ip/dns/static/find where name=($HostnameSet . "." . $Domain) ];
:if ([ :len $DnsRecord ] > 0) do={
:local DnsIp [ /ip/dns/static/get $DnsRecord address ];
:local DupMacLeases [ /ip/dhcp-server/lease/find where mac-address=($LeaseVal->"mac-address") status=bound ];
:if ([ :len $DupMacLeases ] > 1) do={
$LogPrintExit2 debug $0 ("Multiple bound leases found for mac-address " . ($LeaseVal->"mac-address") . ", using ip address of last one.") false;
:set ($LeaseVal->"address") [ /ip/dhcp-server/lease/get ($DupMacLeases->([ :len $DupMacLeases ] - 1)) address ];
}
:if ($DnsIp = $LeaseVal->"address") do={
$LogPrintExit2 debug $0 ("DNS entry for " . ($HostnameSet . "." . $Domain) . " does not need updating.") false;
} else={
$LogPrintExit2 info $0 ("Replacing DNS entry for " . ($HostnameSet . "." . $Domain) . ", new address is " . $LeaseVal->"address" . ".") false;
/ip/dns/static/set address=($LeaseVal->"address") $DnsRecord;
}
:local Cname [ /ip/dns/static/find where type=CNAME cname=($HostnameSet . "." . $Domain) comment=$Comment ];
:if ([ :len $Cname ] > 0 && [ /ip/dns/static/get $Cname name ] != ($HostName . "." . $Domain)) do={
$LogPrintExit2 info $0 ("Host name changed, updating CNAME (pointing to " . ($HostnameSet . "." . $Domain) . ") to " . ($HostName . "." . $Domain) . ".") false;
/ip/dns/static/set name=($HostName . "." . $Domain) $Cname;
}
} else={
$LogPrintExit2 info $0 ("Adding new DNS entry for " . ($HostnameSet . "." . $Domain) . ", address is " . $LeaseVal->"address" . ".") false;
/ip/dns/static/add name=($HostnameSet . "." . $Domain) type=A address=($LeaseVal->"address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
:if ([ :len $HostName ] > 0 && $UseDHCPComment = false) do={
/ip/dns/static/add name=($HostName . "." . $Domain) type=CNAME cname=($HostnameSet . "." . $Domain) ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
}
}
} else={
$LogPrintExit2 debug $0 ("No address available... Ignoring.") false;
}
}
from routeros-scripts.
Having a name based on the mac address is the most reliable we can have here, and we should not dismiss this. Let's use a CNAME
pointing to the mac address based name for everything else - coming from host name or comment.
So no, I will not accept your changes.
But I think d700dbc comes pretty close to what you requested and should serve you well.
from routeros-scripts.
Related Issues (20)
- 64k limit problem for "tool fetch url" HOT 1
- $ScriptInstallUpdate: Policies differ for script 'global-functions' and its scheduler 'global-scripts'! HOT 1
- netwatch + sendNotification HOT 2
- Add html support to notification telegram HOT 1
- log-forwarding: non expected messages are still forwarded HOT 2
- check-routeros-update and other similar scripts suggested scheduler time HOT 12
- ADD username/password auth for ntfy HOT 7
- Failed Telegram Notification HOT 9
- notification doesn't stat from netwatch HOT 3
- Feature request - optional backup-upload notification HOT 2
- backup-email / backup-upload HOT 7
- How to write a script to obtain WiFi signals and snr? HOT 1
- Self-hosted ntfy.sh certificate issue HOT 3
- Restore LogPrintExit2 for backward compatibility HOT 4
- [Observation] lte/firmware-upgrade: Using once causes the command to not wait for version check to complete before returning a result HOT 1
- Set Email with TLS, Starttls HOT 1
- version 7.15.2 - crash and error HOT 2
- Keep Crash on HeX ROS 7.15.2 HOT 2
- RoutesOS 6 Branch HOT 2
- Backup Upload via SFTP not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routeros-scripts.