/etc/hosts not working

6,314

Solution 1

From man hosts:

This manual page describes the format of the /etc/hosts file. This file is a simple text file that associates IP addresses with hostnames, one line per IP address. For each host a single lineshould be present with the following information:

IP_address canonical_hostname [aliases...]

Thus,

chassisOne     10.0.0.1

is wrong.

It should be

10.0.0.1 chassisOne

Solution 2

You're writing it in the wrong order, the ip is supposed to go before the domain.

Try using this instead:

10.0.0.1 facebook.com
10.0.0.2 google.com

Then when you navigate to facebook.com or google.com on your browser, it'll display the following error:

Firefox Error Screen

Good luck.

Share:
6,314

Related videos on Youtube

Dale Smith
Author by

Dale Smith

By Day: I work in the telecommunications field aggregating and tapping 2G/3G/4G traffic for analysis. I've worked in Europe, North and South America. By night: I like to learn new things, drink my excellent home brewed beer, and watch something like Fring, Firefly, Castle, or Elementary. I like SciFi and WWII history for reading. Funsies: Seeing beautiful places.

Updated on September 18, 2022

Comments

  • Dale Smith
    Dale Smith over 1 year

    I populated /etc/hosts with device names and IP addresses. For example:

    chassisOne     10.0.0.1
    chassisTwo     10.0.0.2
    .
    .
    .
    etcetera.
    

    I am able to ping the IP address of both chassisOne and chassisTwo. Pinging the hostname returns:

    ping: unknown host chassisOne
    

    My nsswitch.conf file is:

    host:   files mdns4_minimal [NOTFOUND=return] dns
    

    What am I missing?

  • Dale Smith
    Dale Smith almost 5 years
    Oh Lord ... ...I made a noob mistake! Thank you.
  • vidarlo
    vidarlo almost 5 years
    Please mark answer as accepted, so it doesn't pop up again in a year:)
  • Dale Smith
    Dale Smith almost 5 years
    Working on it. Looking for the "Accepted" button. :)
  • Terrance
    Terrance almost 5 years
    @DaleSmith It is the little check mark next to this answer here below the up and down vote arrows.
  • ShadowRunner
    ShadowRunner almost 5 years
    @Dale-smith: the button (check-mark shaped) probably appeared now, next to this answer's score.
  • vidarlo
    vidarlo almost 5 years
    Note that there's no wildcard matching. Thus, facebook.com will not match `www.facebook.com
  • LogicalBranch
    LogicalBranch almost 5 years
    @vidarlo I know, that screenshot was from an old example.