Discussion
Loading...

Discussion

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social  ·  activity timestamp 4 days ago

Dear #SysAdmin fedi – I am sure this has to exist, but I cannot find a tool like that.

I need a CLI tool that would canonicalize a DNS zone file. As in: put all the entries in a well-defined order, replace whitespace with a predefined pattern, organize the SOA section in a reproducible manner.

My basic need is being able to tell two zone files are 100% functionally equivalent, even if one uses tabs, the other spaces, and if entries are in completely random order, etc.

Anyone?

#DevOps .

  • Copy link
  • Flag this post
  • Block
Thorne Lawler
Thorne Lawler
@thorne@rants.au replied  ·  activity timestamp 3 days ago

@rysiek I think PowerDNS has zone-file ingestion tools, so you could turn two zone files into SQL and compare that…?

  • Copy link
  • Flag this comment
  • Block
Guillaume-Jean Herbiet
Guillaume-Jean Herbiet
@gjherbiet@mamot.fr replied  ·  activity timestamp 3 days ago

@rysiek Have a look at the `ldns` utilities by @nlnetlabs (https://nlnetlabs.nl/projects/ldns/about/) or its replacement (but not yet with feature parity) `dnst` (https://nlnetlabs.nl/projects/domain/dnst/).

On #Debian, install `ldnsutils` and try `ldns-readzone` and `ldns-compare-zones`: https://nlnetlabs.nl/projects/ldns/documentation/

#dns

NLnet Labs

ldns - Documentation

Creating documentation The (html) documentation is created with doxygen and the manual pages are created with a perl program. From the source directory, a simple (g)make doc should create everything. Online documentation You can find the latest documentation, along with tutorials and guides here. Utilities A few utilities are …
NLnet Labs

domain - dnst

dnst has the goal of being an ever-evolving toolbox of commands to aid DNS operators in the maintenance and operation of their zones and nameservers. As ldns has been in maintenance mode since 2020, dnst aims to offer a collection of programs that serve as modern, drop-in replacements for some …
NLnet Labs

ldns - About

The goal of ldns is to simplify DNS programming in C. ldns supports all low-level DNS and DNSSEC operations. It also defines a higher level API which allows a programmer to for instance create or sign packets. ldns allows developers to easily create RFC compliant software and build proof of …
  • Copy link
  • Flag this comment
  • Block
jon ⚝
jon ⚝
@yala@degrowth.social replied  ·  activity timestamp 4 days ago

@rysiek
Would coverting to the dnscontrol js format maybe help? It is said to be semantically equivalent to BIND zone files.

  • Copy link
  • Flag this comment
  • Block
zeromind
zeromind
@zeromind@urusai.social replied  ·  activity timestamp 4 days ago

@rysiek We've been using dnspython (Python library) at work to parse zone files.
You could use it to parse a zone file and write the result to a new file.
The same approach might also work for other programs/libraries.

Should be good enough for comparing what it would be parsed as, but the result is not exactly the same as the source:
From a quick test with the example.com zone from Wikipedia; it a least sets the default TTL ($TTL) for all records that don't specify one, turns absolute records pointing to its own domain into relative ones, and seems to sort the records.

e.g. python3 -c "import dns.zone; import sys; dns.zone.from_file(sys.argv[1]).to_file(sys.argv[2])" example.zone example.zone.parsed

  • Copy link
  • Flag this comment
  • Block
Hey Gus
Hey Gus
@elebertus@mastodon.social replied  ·  activity timestamp 4 days ago

@rysiek https://dnspython.readthedocs.io/en/latest/zone-make.html#dns.zone.from_file if you can’t find a tool to your liking a simple python script might work using dnspython.

There’s quite a few helper functions in the Zone class as well for manipulating zones read in by dns.zone.from_file

Making DNS Zones — dnspython 2.9.0 documentation

  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@elebertus I think named-checkzone is what I needed, but I also like the Python script approach, good idea! Thank you!

  • Copy link
  • Flag this comment
  • Block
Hey Gus
Hey Gus
@elebertus@mastodon.social replied  ·  activity timestamp 4 days ago

@rysiek ya for sure! I figure if you’re doing some validation stuff and write python this would let you write the exact test cases / comparisons you need to solve your problem.

  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@elebertus I am templating a pretty gnarly mostly-manually-edited so far zone with thousands of labels. The test case is: "does the new cleaner templated version yield exactly the same zone." 🙂

  • Copy link
  • Flag this comment
  • Block
Hey Gus
Hey Gus
@elebertus@mastodon.social replied  ·  activity timestamp 4 days ago

@rysiek heck you could even probably straight up write unit tests then. So that’s actually kinda cool 😎

  • Copy link
  • Flag this comment
  • Block
Malcolm Herbert
Malcolm Herbert
@mherbert@social.chinwag.org replied  ·  activity timestamp 4 days ago

@rysiek named-checkzone does this and it's part of the isc-bind package, something like:

named-checkzone -q -f text -F text -o - -s full zonename zonefile

I often do this exact check with

diff -u <( named-checkzone ... oldfile ) <( named-checkzone ... newfile )

I generally find that "-s relative" is better for working with day-to-day because the layout looks a bit nicer

  • Copy link
  • Flag this comment
  • Block
Malcolm Herbert
Malcolm Herbert
@mherbert@social.chinwag.org replied  ·  activity timestamp 4 days ago

@rysiek ... I should add I'm not yet through my first coffee for the morning and haven't looked at the script I wrote to do this, so it's a bit hand-wavy and I might have screwed up some ordering of options, but there's a hefty crumb for the bread trail anyway ... :)

  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@mherbert this might be exactly what I need, thank you!

On Debian 13 the package is bind9-utils, by the way (important to me as this means I can install a package with this tool without installing all of Bind).

  • Copy link
  • Flag this comment
  • Block
Malcolm Herbert
Malcolm Herbert
@mherbert@social.chinwag.org replied  ·  activity timestamp 4 days ago

@rysiek I'm a big believer in native cli tool first, as far as possible but yeah, I'm terrible at describing the environment my examples assume, apologies

  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@mherbert not at all, you provided exactly the amount of information I needed!

  • Copy link
  • Flag this comment
  • Block
JP
JP
@daedalus@eigenmagic.net replied  ·  activity timestamp 4 days ago

@rysiek Does `rndc dumpdb` do what you want? Or are you looking for something that acts on the zone files directly, without loading them into bind?
@bert_hubert might know of such a tool

  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@daedalus @bert_hubert yeah, something that would not have to load it into BIND would be definitely preferable.

  • Copy link
  • Flag this comment
  • Block
Three plus or minus five
Three plus or minus five
@ThreeSigma@mastodon.online replied  ·  activity timestamp 4 days ago

@rysiek
Maybe run each file through sort, then apply a simple diff with ignore-whitespace?

  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@ThreeSigma there's a bunch of sed/grep/awk magic I could do, but I'd prefer not having to do that. the SOA section in particular is going to be an issue, and probably a bunch of other things (IN is optional, for example).

It quickly gets complicated.

  • Copy link
  • Flag this comment
  • Block
mig5
mig5
@mig5@goto.mig5.net replied  ·  activity timestamp 4 days ago

@rysiek I did a little searching and came across https://github.com/VintageOps/dns-zone-compare which looks interesting

GitHub

GitHub - VintageOps/dns-zone-compare: Zonecompare is a simple tool to read and compare two DNS zonefiles for the same domain, and output the differences (not found or different), and the similarities, with extensive options to cope with different use-cases, and to configure the way we want data to be presented(text or json).

Zonecompare is a simple tool to read and compare two DNS zonefiles for the same domain, and output the differences (not found or different), and the similarities, with extensive options to cope wit...
  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@mig5 oooh, this might do the trick, thank you!

  • Copy link
  • Flag this comment
  • Block
r0k
r0k
@r0k@mastodon.social replied  ·  activity timestamp 4 days ago

@rysiek I don't have first-hand experience in this area, but I did some searching and found this. Maybe it meets the need?

https://networkingtoolbox.net/dns/zone/linter

Networking Toolbox

Zone Linter | Networking Toolbox

Normalize and canonicalize BIND zone files with error checking and formatting
  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@r0k is this a CLI tool?

  • Copy link
  • Flag this comment
  • Block
r0k
r0k
@r0k@mastodon.social replied  ·  activity timestamp 4 days ago

@rysiek sorry, I didn't realize that this was one tool in a toolkit of _many_

though it looks like the toolkit as a whole can be run locally via docker, etc.

https://github.com/lissy93/networking-toolbox

sorry if that makes it a bad suggestion for your use case

GitHub

GitHub - Lissy93/networking-toolbox: 🛜 100+ offline-first networking tools and utilities

🛜 100+ offline-first networking tools and utilities - Lissy93/networking-toolbox
  • Copy link
  • Flag this comment
  • Block
Michał "rysiek" Woźniak · 🇺🇦
Michał "rysiek" Woźniak · 🇺🇦
@rysiek@mstdn.social replied  ·  activity timestamp 4 days ago

@r0k it's not about it being a part of toolkit or not. It's not a CLI tool, but some weird web app type thing (even if it can be run locally). I explicitly asked for a CLI tool.

  • Copy link
  • Flag this comment
  • Block
r0k
r0k
@r0k@mastodon.social replied  ·  activity timestamp 4 days ago

@rysiek ok, my mistake

  • Copy link
  • Flag this comment
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-beta.35 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct