2

Entries in my /etc/hosts file are being ignored:

$ cat /etc/hosts
127.0.0.1   localhost
127.0.0.1   google.com

$ ping google.com
PING google.com (216.58.213.142) 56(84) bytes of data.
64 bytes from par21s03-in-f142.1e100.net (216.58.213.142): icmp_seq=1 ttl=50 time=10.3 ms

I've been through ALL the solutions suggested in the 12.04 thread but no dice.

  • Installing nscd just so I can restart it
  • Editing /etc/nsswitch.conf : it currently looks like:

    $ cat /etc/nsswitch.conf
    # /etc/nsswitch.conf
    #
    
    passwd:         compat
    group:          compat
    shadow:         compat
    gshadow:        files
    
    hosts:          dns files
    networks:       files
    
    protocols:      db files
    services:       db files
    ethers:         db files
    rpc:            db files
    
    netgroup:       nis
    

    Note: The hosts line was files dns before I started troubleshooting, I changed it to dns files as per a suggestion from the 12.04 thread. Neither ordering produced any change in the behavior of my system, where /etc/hosts is concerned.

  • Editing /etc/default/dnsmasq (No such file)

  • Disabling dnsmasq in /etc/NetworkManager/NetworkManager.conf (no such file either)
  • Creating a /etc/NetworkManager/dnsmasq.d/hosts.conf file and adding address resolution lines to it, killing dnsmasq (no such process) and doing service network-manager restart (no such service)
  • Setting up a Squid proxy server (err, this won't work for my situation, and is a hack that's outside the scope of the question!)
  • sudo chmod 644 hosts (permissions were already 644 beforehand)

I would have asked this as a comment in that thread, but I don't have enough reputation (50 needed).

By request, here's the output of systemctl list-units '[Nn]etwork*' --all:

$ systemctl list-units '[Nn]etwork*' --all
  UNIT                   LOAD      ACTIVE   SUB    DESCRIPTION
  networking.service     loaded    active   exited Raise network interfaces
● NetworkManager.service not-found inactive dead   NetworkManager.service
  network-online.target  loaded    active   active Network is Online
  network-pre.target     loaded    active   active Network (Pre)
  network.target         loaded    active   active Network

Any ideas?

2 Answers2

1

hosts: dns files

should be:

hosts: files dns

This allows the system NS to query a file first. Namely, /etc/hosts.
The order in nsswitch.conf is important - also a reboot or network restart.

B. Shea
  • 1,252
0

After trying all of the above, including steeldriver's suggestion in the comments I finally solved it...

...by rebooting the machine.

Now /etc/hosts works as it should.

I don't know WHICH solution did the trick, but applying all of them, and then rebooting... evidently did.