Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set specific DNS server using dns.resolver (pythondns)

Tags:

python

dns

I am using dns.resolver from dnspython.

Is it possible to set the IP address of the server to use for queries ?

like image 379
Massimo Avatar asked Oct 09 '10 23:10

Massimo


People also ask

Is there a way to use a specific DNS for a specific domain?

This can absolutely be done using the standard DNS resolution provided by some operating systems. Just not by Linux. To control which interface to use I added the @vpn0 at the end of the DNS servers. This can be useful to use it only when a VPN is up.

What is the difference between DNS server and DNS resolver?

A Domain Name System (DNS) Client is any computer that issues DNS queries to a Domain Name System (DNS) Server. DNS Resolver is a software service running on any computer. DNS Resolver service forwards DNS Queries to the DNS Server for Name Resolution, on behalf of Operating System and other applications.


1 Answers

Although this is somewhat of an old thread, I will jump in. I've bumped against the same challenge and I thought I would share the solution. So, basically the config file would populate the 'nameservers' instance variable of the dns.resolver.Resolver you are using. Hence, if you want to coerce your Resolver to use a particular nameserver, you can do it direcly like this:

import dns.resolver  my_resolver = dns.resolver.Resolver()  # 8.8.8.8 is Google's public DNS server my_resolver.nameservers = ['8.8.8.8']  answer = my_resolver.query('google.com') 

Hope someone finds it useful.

like image 196
Marcin Wyszynski Avatar answered Sep 18 '22 08:09

Marcin Wyszynski