Setting nameserver regardless /etc/resolv.conf

Michael Tokarev mjt at tls.msk.ru
Thu Apr 14 15:48:12 MSD 2011


14.04.2011 15:34, Iñaki Baz Castillo wrote:
> 2011/4/8 Iñaki Baz Castillo <ibc at aliax.net>:
>> Hi, my /etc/resolv.conf has:
>>
>>  nameserver 8.8.8.8
>>  nameserver 8.8.4.4
>>
>> But I want that my C program using udns just uses 127.0.0.1 (in which
>> Unbound listens) as nameserver.
>>
>> I expected that setting enviroment variable NAMESERVERS=127.0.0.1
>> before running my program would do the work, but it still uses
>> 8.8.8.8. The only way to make it working seems to be adding 127.0.0.1
>> as the first option in resolv.conf.
>>
>> Do I miss something?
> 
> Any help with this please? :)

Works For Me(tm).

The only trap that comes to mind is that you didn't export
NAMESERVERS variable so it's not available in subprocesses.

Check this:

NAMESERVERS=127.0.0.2 dnsget -vv foo.bar

it will tell where it is sending queries to (if nothing is
listening on 127.0.0.2 it will just time out).

NAMESERVERS=127.0.0.2; dnsget -vv foo.bar

(note the semicolon) -- this will change nothing, dnsget will
use regular nameservers listed in /etc/resolv.conf.  And this:

export NAMESERVERS=127.0.0.2; dnsget -vv foo.bar

will use 127.0.0.1 agin.

man sh.

/mjt


More information about the udns mailing list