-   Linux - Networking (
-   -   dnsmasq: how to prevent upstream queries for hosts in /etc/hosts? (

catkin 12-15-2009 02:01 PM

dnsmasq: how to prevent upstream queries for hosts in /etc/hosts?
Hello :)

This question arises from my LQ thread "OOo: when no Internet: very slow to start and does not open file" in which Skaperen kindly helped me resolve the underlying problem as dnsmasq querying the upstream DNS servers to resolve the local machine, CW8, which is listed in /etc/hosts when OOo tries to resolve that name.

Research showed that this is default dnsmasq behaviour and that solution (as I understand it) is to:
  1. Add an entry in /etc/hosts for the local computer including a local domain name. This was done (the registered domain name is required for sendmail to send mail as originating from that domain)
    Code:    CW8 CW8.<registered domain name not shown> CW8.localdomain
  2. Configure dnsmasq:
    • To add a domain name to hostnames without domain names
    • With a domain name to add as above
    • To use only /etc/hosts for the local domain

    I changed /etc/dnsmasq.conf accordingly, adding:

    # Set this (and domain: see below) if you want to have a domain
    # automatically added to simple names in a hosts-file.

    # Set the domain for dnsmasq. this is optional, but if it is set, it
    # does the following things.
    # 3) Provides the domain part for "expand-hosts"

    # Add local-only domains here, queries in these domains are answered
    # from /etc/hosts or DHCP only.

After making these changes and restarting dnsmasq I tested by opening an OOo document and saw that the changes had not stopped

root:/etc# tcpdump -nnl -i eth0 -s 1536 dst port 53
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 1536 bytes
23:51:57.224344 IP > 9959+ A? CW8.(none). (28)
23:51:57.274656 IP > 43484+ A? CW8.(none). (28)

What to do?

EDIT: I just found a current LQ thread asking a very similar question, without a solution at the time of writing -- but solved by the OP within the hour.



catkin 12-16-2009 03:56 AM

Solved :)

My silly mistake in dnsmasq.conf, setting local=/localhost/ instead of local=/localdomain/ :redface: :doh:

michal017 02-18-2013 10:50 AM

Did you have to tamper with resolv.conf as well?

What I did is that I:
- added my local hostname to /etc/hosts with and without the .localdomain, e.g.: hostname hostname.localdomain

- added this to my dnsmasq config:

But I still see in dnsmasq log that the query to "hostname" is forwarded to all the nameservers in my resolv.conf.
My resolv.conf contains (dnsmasq runs here) and 2 other IPs given by the ISP provider.

All times are GMT -5. The time now is 04:12 AM.