Você não pode alterar o endereço IP de localhost
.
Observe o comentário que precede as linhas em hosts
file:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
Então, você nem precisa inserir localhost
no seu arquivo hosts
para que funcione, ele está embutido na pilha TCP já que é um endereço de loopback .
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.
Aqui estão alguns comentários úteis de outra resposta no 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.