Reputation: 95
This snippet works perfect
import dns
import dns.resolver
default = dns.resolver.get_default_resolver()
nameserver = default.nameservers[0]
except that if I change /etc/resolv.conf by hand and call again get_default_resolver function it doesn't bring me the updated address. I need to restart python console to see the change effect.
What am I missing? Should I do the change to resolv.conf using the same library?
Thanks in advance,
Upvotes: 0
Views: 1349
Reputation: 41
If you're on a non-Debian based Linux and using glibc then you have to be aware that glibc caches resolv.conf and won't look at it again unless explicitly told to. Essentially it is up to your application to tell glibc if resolv.conf has changed and needs to be reloaded by calling __res_init
. See Python not getting IP if cable connected after script has started and https://sourceware.org/bugzilla/show_bug.cgi?id=984 for details.
Upvotes: 4