3

I changed the /etc/hosts and added an ip address to point localhost to a different computer like:

192.x.x.1 localhost

But it is not working and when I ping to localhost it pings ::1 which is the default route

Adding an alternative name however works, its just the localhost that cannot be overwritten.

How to solve this problem?

Starx
  • 2,271
  • 5
  • 30
  • 37

1 Answers1

2

You cannot change the localhost's IP address.

Note the comment preceding the lines in hosts file:

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost

So, you don't even need to enter localhost in your hosts file in order get it work, it's built into the TCP stack since it's a loopback address.

In TCP/IP a loopback device is a virtual network interface implemented in software only and not connected to any hardware, but which is fully integrated into the computer system's internal network infrastructure. Any traffic that a computer program sends to the loopback interface is immediately received on the same interface.

Here are some useful comments from another answer on SuperUser:

Your localhost is used to refer to your computer from its "internal" IP, not from any "external" IPs of your computer. So, the ping packets don't pass through any physical network interface; only through a virtual loop back interface which directly sends the packets from port to port without any physical hops.

TFM
  • 4,253
  • 2
  • 31
  • 37