You find that DNS queries take a long time from your machine, and you decide to fix this by installing a local DNS resolver. You ask the internet, which says:
You could use
bind9,nscd, ordjbdns.
There’s an odd one out in this list. One of them is not a DNS server at all!
An ordinary DNS server listens on UDP port 53.
When running a local caching DNS resolver,
local processes will contact localhost:53 for any DNS lookups.
But, unlike the other caching DNS resolvers,
nscd does not listen on any ports!
Instead, nscd listens on a socket, /var/run/nscd/socket.
How, though, do local processes know to connect to /var/run/nscd/socket?
The answer is that local processes don’t know to connect to /var/run/nscd/socket.
Or rather, some do, and some don’t.
The processes that do know about /var/run/nscd/socket
are those linked against glibc and using getaddrinfo from that library.
Only GNU’s implementation of the C standard library
has the knowledge of /var/run/nscd/socket.
If your process is linked against a different libc (e.g. musl),
or if your process uses a different runtime (e.g. the Go runtime),
it knows nothing of /var/run/nscd/socket.
This is your first reason for not using nscd.
Other systems have not implemented support for /var/run/nscd/socket
because there is no specification, or even informal documentation, for nscd.
Why?
Because nscd is entirely internal to glibc.
The source code for the daemon is part of glibc,
even though the daemon is not part of the libc library.
If you try installing nscd anyway,
you’ll find the second reason for not using nscd:
it’s horribly unstable.
I can’t keep it running for more than a few seconds
before I get log lines like this in the system log:
Feb 3 19:36:17 vagrant-ubuntu-trusty-64 kernel: [11799.496494] nscd[3677]: segfault at 43c000010 ip 00007fba29180753 sp 00007fba1e4741f0 error 4 in nscd[7fba2916c000+25000]
Feb 3 19:39:46 vagrant-ubuntu-trusty-64 kernel: [12008.644917] nscd[3758]: segfault at 0 ip 00007ff37679cdfa sp 00007ff36ce901e8 error 4 in libc-2.19.so[7ff376714000+1be000]
Feb 3 19:51:09 vagrant-ubuntu-trusty-64 kernel: [12691.893221] nscd[3856]: segfault at 0 ip 00007f82d31aadfa sp 00007f82c989e1e8 error 4 in libc-2.19.so[7f82d3122000+1be000]
This is not just my experience. Denys Vlasenko explains:
nscd problems are not exactly unheard of. Over the years, there were quite a bit of bugs in it. This leads people to invent babysitters which restart crashed/hung nscd. This is ugly.
After looking at nscd source in glibc I arrived to the conclusion that its design is contributing to this significantly. Even if nscd’s code is 100.00% perfect and bug-free, it can still suffer from bugs in libraries it calls.
As designed, it’s a multithreaded program which calls NSS libraries. These libraries are not part of libc, they may be provided by third-party projects (samba, ldap, you name it).
Thus nscd cannot be sure that libraries it calls do not have memory or file descriptor leaks and other bugs.
Since nscd is multithreaded program with single shared cache, any resource leak in any NSS library has cumulative effect. Even if a NSS library leaks a file descriptor 0.01% of the time, this will make nscd crash or hang after some time.
Vlasenko writes this in the context of his single-threaded nscd replacement for BusyBox.
But he notes “as of 2008-08 it is not in wide use”.
But it won’t be in widespread use, ever,
and there won’t be any other stable replacements for nscd, either,
because the nscd protocol is internal to glibc,
with no stability guarantees.
Instead of nscd, use a local DNS server registered in /etc/resolv.conf.
The protocol is specified and stable, all processes respect resolv.conf, and there are many implementations.
Try out named from bind9, or dnscache from djbdns.
Similar posts
More by Jim
What does the dot do in JavaScript?
foo.bar, foo.bar(), or foo.bar = baz - what do they mean? A deep dive into prototypical inheritance and getters/setters. 2020-11-01
Smear phishing: a new Android vulnerability
Trick Android to display an SMS as coming from any contact. Convincing phishing vuln, but still unpatched. 2020-08-06
A probabilistic pub quiz for nerds
A “true or false” quiz where you respond with your confidence level, and the optimal strategy is to report your true belief. 2020-04-26
Time is running out to catch COVID-19
Simulation shows it’s rational to deliberately infect yourself with COVID-19 early on to get treatment, but after healthcare capacity is exceeded, it’s better to avoid infection. Includes interactive parameters and visualizations. 2020-03-14
The inception bar: a new phishing method
A new phishing technique that displays a fake URL bar in Chrome for mobile. A key innovation is the “scroll jail” that traps the user in a fake browser. 2019-04-27
The hacker hype cycle
I got started with simple web development, but because enamored with increasingly esoteric programming concepts, leading to a “trough of hipster technologies” before returning to more productive work. 2019-03-23
Project C-43: the lost origins of asymmetric crypto
Bob invents asymmetric cryptography by playing loud white noise to obscure Alice’s message, which he can cancel out but an eavesdropper cannot. This idea, published in 1944 by Walter Koenig Jr., is the forgotten origin of asymmetric crypto. 2019-02-16
How Hacker News stays interesting
Hacker News buried my post on conspiracy theories in my family due to overheated discussion, not censorship. Moderation keeps the site focused on interesting technical content. 2019-01-26
My parents are Flat-Earthers
For decades, my parents have been working up to Flat-Earther beliefs. From Egyptology to Jehovah’s Witnesses to theories that human built the Moon billions of years in the future. Surprisingly, it doesn’t affect their successful lives very much. For me, it’s a fun family pastime. 2019-01-20
The dots do matter: how to scam a Gmail user
Gmail’s “dots don’t matter” feature lets scammers create an account on, say, Netflix, with your email address but different dots. Results in convincing phishing emails. 2018-04-07
The sorry state of OpenSSL usability
OpenSSL’s inadequate documentation, confusing key formats, and deprecated interfaces make it difficult to use, despite its importance. 2017-12-02
I hate telephones
I hate telephones. Some rational reasons: lack of authentication, no spam filtering, forced synchronous communication. But also just a visceral fear. 2017-11-08
The Three Ts of Time, Thought and Typing: measuring cost on the web
Businesses often tout “free” services, but the real costs come in terms of time, thought, and typing required from users. Reducing these “Three Ts” is key to improving sign-up flows and increasing conversions. 2017-10-26
Granddad died today
Granddad died. The unspoken practice of death-by-dehydration in the NHS. The Liverpool Care Pathway. Assisted dying in the UK. The importance of planning in end-of-life care. 2017-05-19
How do I call a program in C, setting up standard pipes?
A C function to create a new process, set up its standard input/output/error pipes, and return a struct containing the process ID and pipe file descriptors. 2017-02-17
Your syntax highlighter is wrong
Syntax highlighters make value judgments about code. Most highlighters judge that comments are cruft, and try to hide them. Most diff viewers judge that code deletions are bad. 2014-05-11
Want to build a fantastic product using LLMs? I work at Granola where we're building the future IDE for knowledge work. Come and work with us! Read more or get in touch!
This page copyright James Fisher 2018. Content is not associated with my employer. Found an error? Edit this page.