You cannot change the
localhost's IP address.
Note the comment preceding the lines in
# 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:
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.