GameFreak
GameFreak

Reputation: 2931

Does a connection to localhost go out onto the network?

What I want to know is, if I were to 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?

Upvotes: 24

Views: 15698

Answers (6)

sigjuice
sigjuice

Reputation: 29757

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

Upvotes: 15

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84189

That depends on name resolution. Try that ping after # echo "69.59.196.211 localhost" > /etc/hosts.

Upvotes: 0

victor hugo
victor hugo

Reputation: 35838

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

Upvotes: 2

Nathaniel Flath
Nathaniel Flath

Reputation: 16015

No, the packets will not go to the network.

Upvotes: 1

Macke
Macke

Reputation: 25690

No, it's called loopback for a reason. IIRC, packets to 127.0.0.1 aren't allowed "outside" the computer.

Upvotes: 1

RichieHindle
RichieHindle

Reputation: 281515

No packets will hit the network. Unplug your network cable and try it!

Upvotes: 28

Related Questions