brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: resolvectl query --legend=no prints only the answer

Linux
~/tips/tip-dns-resolvectl-legend-no

resolvectl query -4 --legend=no example.com

Prints resolvectl lookup results without headers, so scripts get only the answers.

The output of resolvectl query is made for a person: a header, the answers and a few lines about where the answer came from. For a script I want only the answers.

resolvectl query -4 --legend=no example.com

The manual says the legend, meaning column headers and meta information about the response, is shown by default. --legend=no turns it off. The -4 flag asks only for IPv4 addresses, and -6 does the same for IPv6.

You can also pick the record type and let the tool list the valid values:

resolvectl query --type=MX example.com --legend=no
resolvectl query --type=help

I like this better than parsing getent output when I want a lookup through systemd-resolved itself, because it also uses its cache and per-link settings.

Since the local cache is part of that, a fresh answer needs one more option. --cache=no skips the local DNS record cache for a lookup (the manual lists it as added in systemd version 248, and it is on by default):

resolvectl query --cache=no --legend=no example.com

Caveat: the result depends on the resolver of that machine, so it can differ from what dig @1.1.1.1 shows. Keep that in mind when you compare. The command also needs systemd-resolved to be running, so on a system without it you get an error.

Further reading: resolvectl(1) manual

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link