I've done a default install of dnsmasq. When I run dig, it seems to be using dnsmasq (127.0.0.1), but the results don't include the hostnames included in /etc/hosts.
/etc/hosts:
192.168.1.13 sun
in a terminal:
$ dig sun
; <<>> DiG 9.6-ESV-R4 <<>> sun
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 32131
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;sun. IN A
;; AUTHORITY SECTION:
. 9699 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2011041100 1800 900 604800 86400
;; Query time: 1 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Apr 12 05:20:56 2011
;; MSG SIZE rcvd: 96
in a terminal:
$ dig @localhost sun
; <<>> DiG 9.6-ESV-R4 <<>> @localhost sun
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 43763
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;sun. IN A
;; AUTHORITY SECTION:
. 10800 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2011041800 1800 900 604800 86400
;; Query time: 40 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Apr 18 17:15:23 2011
;; MSG SIZE rcvd: 96
I've tried using local and expand-hosts/domain, but can't seem to get either of those working either. My primary goal is to be able to use one machine to host LAN DNS, I don't care if the names wind up being sun or sun.domain, whatever works.
Here is my /etc/resolv.conf
nameserver 127.0.0.1
domain members.linode.com
search members.linode.com
nameserver 72.14.188.5
nameserver 72.14.179.5
and /etc/dnsmasq.conf
domain-needed
bogus-priv
This is all on an ubuntu 10.04 machine if it makes a difference. I have been following this guide: http://www.mythicalbeast.co.uk/linux/dnsmasq_howto.html (though not verbatim since that also sets up DHCP)
I know this is from 2011, but since it still has no accepted answer:
Today, I had a similar problem. Curl worked to get the expected response from a haproxy lxc with the respective header, but somehow my local dnsmasq did not provide resolution for
container.test
(confirmed with nslookup).Google found me this post by Hugo Heden, who said that is might be an issue with
/etc/hosts
formatting.What solved the problem for me was:
no-hosts
in/etc/dnsmasq.conf
123.123.123.12 container.test
into a new file, e.g./etc/dnsmasq.hosts
addn-hosts=/etc/dnsmasq.hosts
to/etc/dnsmasq.conf
This snippet from the dnsmaq FAQ seems relevant:
So I suggest you post your
/etc/resolv.conf
, as well as the arguments you are feeding to dnsmasq when you start it.Something I found: Everything appears to be configured ok, but dns name from /etc/hosts is not resolving. After adding/editing /etc/hosts (or any config file), don't forget to restart dnsmasq process to re-read the file. Dnsmasq imports these files on startup, it's not a live lookup.
What does your /etc/resolv.conf look like? Look for domain or search elements.
Setup a .local domain for dnsmasq and then add that to your resolv.conf and it should work.
Try dig sun.local @localhost.
I've just found what happens behind the scenes: dnsmasq tries to expand
sun
tosun.
when it reads /etc/hosts file. If you try to resolvesun.
it returns the correct result, but if you query it forsun
it forwards the request to upstream DNS servers.To work around this behaviour:
local
to/etc/resolv.conf
, e.g.:sun.local
to/etc/hosts
or/etc/dnsmasq.hosts
, e.g.:When a client queries for
sun
the DNS resolver will autoexpand the query tosun.local
first and return the result from hosts file.dig, as well as host, and nslookup are specifically created to query dns servers. It will not look at /etc/hosts, and in fact will ignore /etc/nsswitch.conf
Anything using the gethostbyname call will however use /etc/nsswitch.conf
For example, ping should use /etc/hosts provided files is before dns in /etc/nsswitch.conf which it normally is.