dns_query(9)
π
dns_query(9) β like, the Kernel API Manual page for dns_query, bestie β¨
Okay so picture this: you're deep in kernel land, and you need to actually resolve a DNS name from inside the kernel. Not from userspace, not with some janky workaround β from the kernel. That's what dns_query is for, and honestly? It ate. π«Ά
β¨ NAME β¨
dns_query β query the DNS, obviously π
π SYNOPSIS π
int dns_query (struct net *net , const char *type , const char *name ,
size_t namelen , const char *options , char **_result , time64_t
*_expiry , bool invalidate );
That's the whole vibe right there. Eight arguments. Count 'em. π₯
π¦ ARGUMENTS π¦
Okay bestie, here's the tea on every single one of these:
netβ the network namespace you wanna operate in. Like, which network world are we doing this in? That one. πtypeβ the query type. OrNULLif you just want a straight hostβIP lookup, no fancy stuff. πnameβ the name to look up. The thing we're actually curious about. πnamelenβ length ofname. Yes, it's separate. Yes, you have to pass it. πoptionsβ request options. OrNULLif there are no options, which honestly? Fair. β¨_resultβ where the returned data goes. OrNULL, if you're just vibing and don't need the data back. π_expiryβ where to store the result's expiry time. OrNULLif you don't care when it goes stale. β°invalidateβ<hotpink>always invalidate the key after use</hotpink>. Like, always. That's the whole flag. Periodt. π
πΈ DESCRIPTION πΈ
So here's what actually happens: the data gets returned in the pointer at *result β if you provided one β and guess what, bestie, the caller is responsible for freeing it. That's you. You're the caller. You free it. No cap. π
The description you pass should be of the form:
"[<query_type>:]<domain_name>"
and the options need to be appropriate for the query type you requested β like, don't just throw random options at a type that doesn't understand them, that's not the move. π
And if no query_type is given? Then the query is a straight hostname β IP address lookup. Simple. Clean. Iconic. β¨
The DNS resolution lookup itself is performed by upcalling to userspace by way of requesting a key of type dns_resolver. So like, the kernel pops its head up, asks userspace real nice, userspace handles it, and the answer comes back down. Teamwork, honestly. π«Ά
On success it returns the size of the result. Otherwise? A -ve error code. So if the number you get back is negative, that's your sign something went sideways. π
π₯ SEE ALSO π₯
- Kernel file
./net/dns_resolver/dns_query.cβ go read the source, bestie, it's right there π
And that's the page!! π Cute lil sign-off time: this gem lives over in ./net/dns_resolver, dated October 2026, so if you're reading it in some other timeline... wyd. ππ¦
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms