Announcement

Collapse
No announcement yet.

Allow dnsmasq to use /etc/hosts

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Allow dnsmasq to use /etc/hosts

    Greetings!

    I would like to use my /etc/hosts file to force name resolution to certain hosts. But when I look at how dnsmasq is set up I see that it has a parameter set to ignore the /etc/hosts file via the "--no-hosts" switch:

    Code:
    /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/sendsigs.omit.d/network-manager.dnsmasq.pid --listen-address=127.0.0.1 --conf-file=/var/run/nm-dns-dnsmasq.conf --cache-size=0 --proxy-dnssec
    Where is this parameter set so I can disable it? I think this would allow me to use the /etc/hosts file for name resolutions.

    Any thoughts?

    #2
    Is this a server? dnsmasq isn't running on my desktop installation and afaik it shouldn't.

    All I can suggest is running a grep -r for it in your /etc directory to find the script that invokes it ...

    Or a find /etc -name '*dnsmasq*' to look for config files.
    I'd rather be locked out than locked in.

    Comment


      #3
      My machine is a workstation running on a laptop. I think dnsmasq is on by default.

      The grep -r is talong a long time. :-)

      Comment


        #4
        Look here yet?

        --conf-file=/var/run/nm-dns-dnsmasq.conf

        Please Read Me

        Comment


          #5
          Is your laptop providing dns or dhcp services to other machines?

          If you don't need to do that, and only need to control name resolution for processes on your own machine, I'm not sure dnsmasq is what you want. But if it is, do you have
          Code:
          nameserver 127.0.0.1
          in /etc/resolv.conf?
          I'd rather be locked out than locked in.

          Comment


            #6
            Originally posted by Thiudans View Post
            The grep -r is talong a long time. :-)
            Code:
            $ time grep -r dnsmasq /etc
            /etc/insserv.conf:$named                +named +dnsmasq +lwresd +bind9 +unbound $network
            grep -r dnsmasq /etc  0.12s user 0.35s system 3% cpu 13.031 total
            I'd rather be locked out than locked in.

            Comment


              #7
              Unfortunately, the --no-hosts option is hard-coded to NetworkManager's dnsmasq plugin (which I personally think is borderline idiotic).

              1. You can disable the nm dnsmasq plugin by commenting out the dns=dnsmasq line in /etc/NetworkManager/Networkmanager.conf file (and restarting NetworkManager afterwards)

              2. If you would like to continue using dnsmasq without the no-hosts option, you can wrap dnsmasq binary into a shell script that calls it with the options you choose...or install and use the regular 'dnsmasq' which you can configure to your liking (the latter requires you to also disable the networkmanager plugin as per step one)

              Some links:
              https://bugs.launchpad.net/ubuntu/+s...er/+bug/993298
              http://askubuntu.com/questions/11789...etc-hosts-file
              Last edited by kubicle; Aug 23, 2012, 01:51 PM.

              Comment


                #8
                Yes, it has a list of DNS servers from my DHCP servers.

                Comment


                  #9
                  kubicle,

                  "Unfortunately, the --no-hosts option is hard-coded to NetworkManager's dnsmasq plugin (which I personally think is borderline idiotic)."

                  Why? I agree this is idiotic.

                  I think I will take option 2.

                  Finally, are all those options for dnsmasq hard coded for the plugin? If not, there is an easier workarount with the --addn-hosts switch.

                  Comment


                    #10
                    Originally posted by Thiudans View Post
                    Why? I agree this is idiotic.
                    Well there is a reasoning behind the no-hosts option (though it doesn't seem to be working as expected...judging by your experiences, I don't use the plugin myself)...see the commit (https://mail.gnome.org/archives/netw.../msg00179.html) for the reasoning. Still...using hard-coded options makes no sense to me in general.

                    Originally posted by Thiudans View Post
                    Finally, are all those options for dnsmasq hard coded for the plugin? If not, there is an easier workarount with the --addn-hosts switch.
                    I didn't check the full source, so I'm not sure...but I'd expect they are.

                    Comment


                      #11
                      Ha!

                      nsswitch.conf, located at /etc/nsswitch.conf had no entry for dns--I added it and now I can resolve names with /etc/hosts !

                      Thanks kubicle--I found it from the link you provided.
                      Last edited by Thiudans; Aug 23, 2012, 05:55 PM. Reason: corrected path

                      Comment


                        #12
                        Originally posted by Thiudans View Post
                        nsswitch.conf, located at /etc/nsswitch.conf had no entry for dns--I added it and now I can resolve names with /etc/hosts !
                        Is your 12.04 a fresh installation, or an upgraded one?
                        I think the default nsswitch.conf in precise should have:
                        Code:
                        hosts:          files dns
                        (which should mean that [files] /etc/hosts is checked before dns resolving)

                        Comment


                          #13
                          On my 12.04, this is the content of /etc/nsswitch.conf
                          Code:
                          # /etc/nsswitch.conf#
                          # Example configuration of GNU Name Service Switch functionality.
                          # If you have the `glibc-doc-reference' and `info' packages installed, try:
                          # `info libc "Name Service Switch"' for information about this file.
                          
                          passwd:         compat
                          group:          compat
                          shadow:         compat
                          
                          hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
                          networks:       files
                          
                          protocols:      db files
                          services:       db files
                          ethers:         db files
                          rpc:            db files
                          
                          netgroup:       nis
                          Last edited by Snowhog; Aug 24, 2012, 08:15 PM.
                          Windows no longer obstructs my view.
                          Using Kubuntu Linux since March 23, 2007.
                          "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                          Comment


                            #14
                            Originally posted by Snowhog View Post
                            On my 12.04, this is the content of /etc/nsswitch.conf
                            Code:
                            hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
                            The mdns4 entries probably depend on whether you have avahi-daemon (+ libnss-mdns) installed or not (they are installed by default).

                            Comment


                              #15
                              Mine is a fresh install. I fiddlw lot, so something may have changed it. The way it works is that the resources for the DB are read in order from left to right. So in my case, there was no DNS entry. That means that unless the application calls DNS, there would be no name resolution. Here is mine:

                              Code:
                              # /etc/nsswitch.conf
                              #
                              # Example configuration of GNU Name Service Switch functionality.
                              # If you have the `glibc-doc-reference' and `info' packages installed, try:
                              # `info libc "Name Service Switch"' for information about this file.
                              
                              passwd:         compat
                              group:          compat
                              shadow:         compat
                              
                              hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
                              networks:       files
                              
                              protocols:      db files
                              services:       db files
                              ethers:         db files
                              rpc:            db files
                              As you can see, files is first, so it will use the hosts file to resolve.

                              Comment

                              Working...
                              X