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?

2
  • Localhost is probably built-in, though I couldn't promise that. If you use a different (unreserved or at least non-well-known) name, does THAT work?
    – Mark Allen
    Feb 6, 2013 at 1:12
  • @MarkAllen Yes they do
    – Starx
    Feb 6, 2013 at 1:14

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .