What I want to know is if I were execute something like ping localhost
would the packets be redirected by the operating system and go directly to the destination port or would the packets go out on the network to the nearest router or switch which then bounces them back to your computer?
views:
260answers:
7No packets will hit the network. Unplug your network cable and try it!
No, it's called loopback for a reason. IIRC, packets to 127.0.0.1 aren't allowed "outside" the computer.
The packets will stay on your machine.
The name 'localhost' is an alias from 127.0.0.1 in the hosts file, if you edit the hosts file (UNIX: /etc/hosts Windows: C:\windows\system32\drivers\etc\hosts) and change localhost for any other word then you'll access your local host using that other word.
The address 127.0.0.1 is a loopback address, it is defined in RFC3330
Any packets sent to an IP address attached to a local interface do not go out of your host. 127.0.0.1 is not special in this regard. Both ping 127.0.0.1
and ping 192.168.1.44
will transmit and receive ICMP packets over the "loopback network device". You can confirm this by unplugging your Ethernet cable and observing the TX and RX counters.
$ /sbin/ifconfig
eth0 Link encap:Ethernet
inet addr:192.168.1.44 Bcast:192.168.3.255 Mask:255.255.252.0
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
RX packets:992670 errors:0 dropped:0 overruns:0 frame:0
TX packets:992670 errors:0 dropped:0 overruns:0 carrier:0
That depends on name resolution.
Try that ping after # echo "69.59.196.211 localhost" > /etc/hosts
.