LinuxQuestions.org

LinuxQuestions.org (http://www.linuxquestions.org/questions/index.php)
-   Linux - Networking (http://www.linuxquestions.org/questions/forumdisplay.php?f=3)
-   -   dnsmasq: how to prevent upstream queries for hosts in /etc/hosts? (http://www.linuxquestions.org/questions/showthread.php?t=775858)

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:

    192.168.1.47    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:
    Code:

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

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

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

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

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 192.168.1.47.55058 > 218.248.240.23.53: 9959+ A? CW8.(none). (28)
23:51:57.274656 IP 192.168.1.47.39046 > 218.248.240.23.53: 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.

Best

Charles

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.:
1.2.3.4 hostname hostname.localdomain

- added this to my dnsmasq config:
expand-hosts
domain=localdomain
local=/localdomain/

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 127.0.0.1 (dnsmasq runs here) and 2 other IPs given by the ISP provider.


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