How network manager is resolving localhost without /etc/hosts

Tom H tomh0665 at gmail.com
Fri Dec 25 19:22:37 UTC 2015


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




More information about the ubuntu-users mailing list