Nslookup (or dig) using default nameserver at 127.0.0.1

All the HashiCorp examples I have found use 127.0.0.1 explicitly as the nameserver in their dig/nslookup cmdline examples.

Example:

There is one example which doesn’t use it explicitly, but makes no mention as to how to set it up as default.

(This above cmd is inside the Docker container, so it might be OK to skip that, but that still doesn’t answer, how a simple nslookup or dig commands will automatically hit 127.0.0.1 on the base machine (or outside the container)).

What I am alluding to is that, I could not find the setup/configuration needed to put 127.0.0.1 as the first nameserver as default as part of HashiCorp docs.

So, the question is:
What is the HashiCorp recommended of setting the first nameserver to 127.0.0.1, assuming Consul is running at 127.0.0.1:8600 and we would be forwarding 538600.

Example DNSMasq configuration used from here:

I feel the missing piece is the DHCP client bit which would add 127.0.0.1 as the first nameserver.

Example: (for dhclient)

    cat >> /etc/dhcp/dhclient.conf <<EOF
prepend domain-name-servers 127.0.0.1;
EOF

The DHCP client setup then allows the following commands to work without requiring the explicit nameserver:

$> nslookup foobar.service.consul
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: foobar.service.consul
Address: 10.b.c.d
Name: foobar.service.consul
Address: 10.b.c.d
Name: foobar.service.consul
Address: 10.b.c.d

This would also allow raw_exec tasks to refer to each other using just the service name syntax, right?

@blake

Hi @shantanugadgil, apologies for the very delayed reply here. You’re correct, the majority of the examples on the DNS forwarding guide do not explicitly state that 127.0.0.1 needs to be added as a nameserver (or be the only name server) in /etc/resolv.conf.

I’ll make a note of this and will try to get this updated over the next week.

Thanks for bringing this to my attention.

1 Like

Hi @shantanugadgil,

A sentence has been added to the prerequisites to state that nameserver 127.0.0.1 must be added to /etc/resolv.conf when using Consul DNS forwarding with BIND, dnsmasq, or Unbound.