How network manager is resolving localhost without /etc/hosts

Tom H tomh0665 at gmail.com
Sun Dec 27 09:51:44 UTC 2015


On Fri, Dec 25, 2015 at 11:33 PM, Bruce Ferrell <bferrell at baywinds.org> wrote:
> On 12/25/2015 11:22 AM, Tom H wrote:
>> On Mon, Dec 21, 2015 at 12:30 AM, Liam Proven <lproven at gmail.com> wrote:
>>> On 20 December 2015 at 21:57, Shashwat Kumar <shashwatkmr.001 at gmail.com> wrote:
>>>>
>>>> I tried to make a new mapping in /etc/hosts which didn't work. After
>>>> searching I found that network-manager does not use /etc/hosts but dnsmasq
>>>> is used as local dns resolver.
>>>>
>>>> To confirm this design, I commented every line in /etc/hosts and flush
>>>> dnsmasq cache using
>>>>
>>>> sudo /etc/init.d/nscd restart
>>>>
>>>> and restarted network-manager
>>>>
>>>> sudo service network-manager restart
>>>>
>>>> But to my surprise ping localhost was still resolving to 127.0.0.1. As per
>>>> my knowledge localhost mapping is only maintained in /etc/hosts. So how
>>>> localhost was still being resolved? Is there any information that I am
>>>> missing?
>>
>> I don't have access to Ubuntu+NM at the moment but, IIRC, it won't
>> resolve localhost to 127.0.0.1 if you set "dns=none" in
>> "/etc/NetworkManager/NetworkManager.conf" and if "/etc/hosts" doesn't
>> have a "127.0.0.1 localhost" line (even though this isn't really what
>> "man NetworkManager.conf" says about "dns=none").
>>
>>> Localhost is *always* 127.0.0.1 on any computer with IPv4. You can't
>>> change this to anything else in any way at all, as far as I know; it's
>>> part of the definition of IPv4.
>>
>> It's always 127.0.0.1 because it's what's set in "/etc/hosts". If it
>> isn't set there:
>>
>> # cat /etc/hosts
>> 127.0.1.1 rr.city rr
>>
>> # ping localhost
>> ping: unknown host localhost
>>
>> # getent hosts localhost
>>
>> # getent ahosts localhost
>>
>> #
>>
>>> You do *not* set localhost to your network IP address! That will break
>>> TCP/IP very badly, I think.
>>
>> Most definitely +1
>
> Name resolution at it lowest level is a function of a thing called the
> resolver library... A part of glibc... Very low level systems library.
> The resolver library is is configured by a file, /etc/nsswitch.conf
> (name switch configuration). This row means:
>
> hosts: files mdns_minimal [NOTFOUND=return] dns
>
> Check for the known file, /etc/hosts. If it's not there, look at the
> minimal mdns resolver library (on linux known as avahi usually, OS X
> bonjour). If you don't find it there, go ask DNS.
>
> NetworkManager relies on this mechanism and ordering

This isn't an issue regarding the order of resolution of dns queries.

"localhost." isn't going to be resolved by anything other than
"files". It turns out that in the NM case, "localhost." is resolved
without a hosts file unless NM's dns setting is "none".




More information about the ubuntu-users mailing list