4

I'd like to get .local addresses (such as test.local) to point to 127.0.0.1 but it isn't working. I'm on latest Ubuntu. In /etc/NetworkManager/NetworkManager.conf I commented out dns=dnsmasq then did sudo service network-manager restart.

I then installed dnsmasq and added a address=/local/127.0.0.1 to /etc/dnsmasq.d/mycustomfile then did sudo service dnsmasq restart. Apart from what I've mentioned I made no other changes.

But when I visit test.local it doesn't resolve to 127.0.0.1, doing a ping of that .local address also isn't successful. Maybe the contents of /etc/resolv.conf are relevant, it is just the default I didn't change it:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 222.11.22.36
nameserver 222.11.22.37

This is the output when I run dnsmasq not as a daemon:

$ sudo dnsmasq --no-daemon     
dnsmasq: started, version 2.68 cachesize 150
dnsmasq: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth
dnsmasq: reading /etc/resolv.conf
dnsmasq: using nameserver 222.11.22.37#53
dnsmasq: using nameserver 222.11.22.36#53
dnsmasq: read /etc/hosts - 9 addresses

When dnsmasq is running the /etc/resolv.conf automatically updates (and reverts back to the entry above when dnsmasq is stopped):

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1

And this:

$ sudo nslookup test.local 127.0.0.1
Server:         127.0.0.1
Address:        127.0.0.1#53

Name:   test.local
Address: 127.0.0.1

But still doing a ping to localhost doesn't work.

What do I need to do to get dnsmasq working to resolve .local addresses?

4 Answers 4

7

local seem to be some kind of reserved keyword, at least on Ubuntu:

  • address=/local/127.0.0.1 -- doesn't work.
  • address=/loc/127.0.0.1 -- works.
1
  • rand'Chris: Thank you for trying to improve an answer on Super User. But, while many people believe that it’s OK to correct errors in other people’s posts, and add small clarifications, your suggested edit is so substantial that (IMHO) it should be posted as a separate answer. It’s OK to repeat (some) information from a previous answer as long as you add something of value. (You should of course identify the answer that you are building on, by linking to it and citing the author’s name.) You might also want to refer to this other rejected edit. Sep 24, 2018 at 22:35
9

Looks like dnsmasq is starting correctly. You should test if dnsmasq is correctly working with nslookup test.local 127.0.0.1.

To make sure the system is using dnsmasq, you have to update the /etc/resolv.conf to use nameserver 127.0.0.1 as first option.

You can also use a custo upstream resolver configuration on dnsmasq with --resolv-file=/etc/resolv.conf.dnsmasq.

3
  • I have updated my question with some information based on your answer, I'd appreciate if you could take a look.
    – user779159
    Jul 21, 2014 at 16:17
  • Also the original /etc/dnsmasq.conf file is left as it was originally, with everything commented out. Are there things I need to uncomment from there? (It's a large file over 600 lines.) The only thing I uncommented was the last line conf-dir=/etc/dnsmasq.d because my custom config file is under that directory.
    – user779159
    Jul 21, 2014 at 16:21
  • Your dnsmasq is responding correctly. The conf-dir directive does load all files inside the directory, so you can have organize in different files, not necessary needed in your case. You can keep the original dnsmasq.conf as it is and put your configuration in a custom file in /etc/dnsmasq.d, as you've already done. You don't need sudo to run nslookup. Test again with nslookup test.local, it will use the DNS configuration from /etc/resolv.conf this time.
    – denisvm
    Jul 21, 2014 at 17:04
1

Probably the avahi-daemon is using the domain "local". See:

https://unix.stackexchange.com/questions/352237/avahi-daemon-and-local-domain-issues

1
  • Welcome to Super User! Thanks for your contribution. Providing the link for reference is useful, but you must also include the essential information in the post. Please edit your answer so it contains that information. You might also like to take the Tour and read the How to Answer page, to better familiarise yourself with this site.
    – robinCTS
    Jun 23, 2018 at 15:09
0

If what you want only involves pointing back at your own machine, and not trying to use dnsmasq to control other computers' dns resolving, then what you want is to actually just add some entries in /etc/hosts. I'd recommenced you undo all your changes to dnsmasq and it's settings and make sure that /etc/hosts has the following at the top:

127.0.0.1 localhost
127.0.1.1 mycomputername mycomputername.local anothername.local

After this, pinging mycomputername.local will point to yourself (actually, will point to dnsmasq server running on 127.0.1.1, THEN to localhost). You can even add entries for other computers on your network so that it appears to you, on this machine, that computers can be referenced as computer1.local computer2.local etc.

192.168.1.31 computer1.local
192.168.1.32 computer2.local

If you can't seem to undo your changes with dnsmasq, then you can add those additional entries after localhost, but do not delete or change the localhost entry itself. So like this:

127.0.0.1 localhost mycomputername mycomputername.local anothername.local

BTW: the proper way to modify resolv.conf on Ubuntu desktop is with the network manager in your taskbar. The proper way in Ubuntu server is add dns-nameserver entries under your network device in /etc/network/interfaces and either restart or do ifdown eth0 && ifup eth0. As the warning in /etc/resolv.conf states, don't modify it directly, it gets written dynamically based on /etc/network/interfaces settings.

1
  • 3
    /etc/hosts does not allow wildcards, you'd have to update it for every new .local domain, that's why people use dnsmasq even for local resolving. Aug 28, 2015 at 14:57

You must log in to answer this question.

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