Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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
#!/bin/sh
dnsmasq=/usr/sbin/dnsmasq.bin

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

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 

addn-hosts=/etc/hosts
share|improve this answer

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.

share|improve this answer
    
/etc/dnsmasq.conf has all options commented out. Reloading not helping –  bakytn Apr 1 '12 at 14:34
    
I don't know what I did. it seems to be working now –  bakytn Apr 1 '12 at 14:51
2  
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. –  Justin Buser Oct 25 '12 at 22:29
    
dnsmasq must be restarted in order to load changes in configuration files –  txwikinger Aug 23 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 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.