Monitor DNS¶
Source · io.systemd.Resolve.Monitor · systemd v257+ · Root
resolvectl monitor in Go: subscribe to systemd-resolved's query stream and
print every lookup as it completes. The subscription never ends on its own;
Ctrl-C cancels the context, which ends the stream and closes the connection.
Run it¶
Output (illustrative)
monitoring… (Ctrl-C to stop)
success github.com answers=1
success api.github.com answers=1
success go.dev answers=8
failure nope.invalid answers=0
^C
The code¶
How it works¶
- Requires-more.
SubscribeQueryResultsis annotated[Requires 'more' flag], so the generated method returns the iterator directly; there's no single-reply variant. - The first reply is a handshake with
Ready: true, sent once the subscription is active. - Shutdown via context.
signal.NotifyContextcancels on Ctrl-C. The loop checksctx.Err()first so an interrupt exits cleanly instead of reporting the cancellation as a failure. - Root only. The monitor socket is restricted to privileged clients.