I have installed DNSMASQ but it was not starting as 53 port was busy.

I found out that ubuntu already had dnsmasq package and it's working.

Now the problem is...I just want to be able to resolve my hosts in /etc/hosts through it

i.e: nslookup somehostonlan localhost to be resolved to certain IP taken from /etc/hosts file.

but this is not happening.

Why? BTW, as the caching DNS server it's working fine. I just want it to resolve hosts from /etc/hosts file that's all

4 Answers 4


To speed up internet, ubuntu 12.04 has added a plugin to NetworkManager to start dnsmasq, a local dns server that caches dns entries. The problem is the plugin has hardcoded the --no-hosts string.

So one solution is to comment out the line that load the plugin in the NetworkManager config file and restart NetworkManager :

sudo mv /etc/NetworkManager/NetworkManager.conf /etc/NetworkManager/NetworkManager.conf.bak
sudo bash -c 'cat /etc/NetworkManager/NetworkManager.conf.bak | sed -e "s/^\(dns=dnsmasq\)$/#\1/" > /etc/NetworkManager/NetworkManager.conf'
sudo restart network-manager

Another solution is to wrap dnsmasq to filter out the undesired arguments:

sudo mv /usr/sbin/dnsmasq /usr/sbin/dnsmasq.bin
sudo bash -c 'cat > /usr/sbin/dnsmasq' << EOF

exec $dnsmasq `echo $@ | sed -e s/--no-hosts//`

sudo chmod 755 /usr/sbin/dnsmasq

Please mark the bug as affecting you.

Another solution without patching system files

cat /etc/NetworkManager/dnsmasq.d/hosts.conf 


This bug still affected me even now ( Ubuntu 14.04 ).

Finally I found a solution that, simply add this line 'addn-hosts=/etc/hosts' to dnsmasq configuration file of Newworkmanager package.

echo 'addn-hosts=/etc/hosts' > /etc/NetworkManager/dnsmasq.d/etc-hosts
service network-manager restart

The idea is, we are adding /etc/hosts as a additional host file .

Even if I could find a solution, hard-coded option '--no-hosts' in the binary file /usr/sbin/NetworkManager disappoints me.


As of August 2015, the other answers are outdated.

Simple answer

  1. Create /etc/NetworkManager/dnsmasq.d/hosts.conf.
  2. Put lines like address=/whatever/ in it. See the docs (look for --address). Wildcards are possible: address/.whatever./
  3. Kill dnsmasq (bug).
  4. Restart it: $ service network-manager restart.

dnsmasq should automatically use the /etc/hosts file. This can be disabled by the -h command line option or no-hosts configuration option. I would not expect either to be set in the default configuration.

Try forcing dnsmasq to reload its hosts file. (Changes to the configuration file require a restart). Either of these commands should work.

service dnsmasq reload

kill -HUP $(pidof dnsmasq)

If you are working with a system that has no-hosts specified you should be able to use the addn-hosts option to override it. Normally, this would be used to read an additional file in /etc/hosts format. This can be used to specify additional host data that you want DNS to provide, but don't want in your /etc/hosts file. This can be used to allow the package manager and related tools to manage /etc/hosts while additional hosts data is provided in an alternate file.

  • /etc/dnsmasq.conf has all options commented out. Reloading not helping
    – bakytn
    Commented Apr 1, 2012 at 14:34
  • I don't know what I did. it seems to be working now
    – bakytn
    Commented Apr 1, 2012 at 14:51
  • 4
    Why would you answer this when you don't actually know the answer? The fact that you "would not expect either to be set in the default configuration" does not make it the case as it in fact is set and hard-coded into dnsmasq in NetworkManger. Commented Oct 25, 2012 at 22:29
  • dnsmasq must be restarted in order to load changes in configuration files
    – txwikinger
    Commented Aug 23, 2014 at 15:24
  • @txwikinger Many options files are reread when dnsmasq receive a HUP signal. This includes both the /etc/hosts and /etc/ethers files. Restart times are fast enough, that it will be rare for clients to not get a response.
    – BillThor
    Commented Aug 24, 2014 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .