Skip to content

/etc/hosts Does Not Work on Linux or Windows?

/etc/hosts or C:WindowsSystem32driversetchosts is a file for resolving the domain name in a local manner. If you set it incorrectly, you will see no effects on resolving domain name. For example, we add a mapping record to the file like this:

[root@test ~]# vi /etc/hosts
[root@test ~]# ping -c 4 server01
ping: unknown host server01

The above record is incorrect in format. The correct format is IP-HostName mapping. So, we should switch the places of the two fields into this:

[root@test ~]# vi /etc/hosts
... server01
[root@test ~]# ping -c 4 server01
PING server01 ( 56(84) bytes of data.
64 bytes from server01 ( icmp_seq=1 ttl=64 time=0.027 ms
64 bytes from server01 ( icmp_seq=2 ttl=64 time=0.077 ms
64 bytes from server01 ( icmp_seq=3 ttl=64 time=0.037 ms
64 bytes from server01 ( icmp_seq=4 ttl=64 time=0.036 ms

--- server01 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.027/0.044/0.077/0.019 ms

On generic Windows platform (e.g. Windows XP, Windows 7, Windows 8, or Windows 10), it's the same thing. You should add records to etchosts in IP-HostName mapping format.

Kindly remind you the format once again, either on Windows or Linux:

  • ✓ Correct      IP to HostName.
  • ✗ Incorrect   HostName to IP.

Leave a Reply

Your email address will not be published. Required fields are marked *