How come one can successfully ping 127.0.0.2 on Linux?
10
votes
3
answers
2469
views
On a FreeBSD system with a loopback network interface ...
% ifconfig lo0 lo0 link up loopback drv_running running multicast nd6 performnud auto_linklocal no_radr link rxcsum txcsum hwcsum rxcsum_ipv6 txcsum_ipv6 link address metric 0 mtu 16384 type 24 linkstate 0 physical 0 baudrate 0 inet4 address 127.0.0.1 prefixlen 8 bdaddr 127.0.0.1 inet6 address ::1 scope 0 prefixlen 128 bdaddr ::1 scope 0 inet6 address fe80::1 scope 3 prefixlen 64 inet6 address ::2 scope 0 prefixlen 128 inet4 address 127.53.0.1 prefixlen 8 bdaddr 127.53.0.1 inet4 address 127.53.1.1 prefixlen 8 bdaddr 127.53.1.1 %... pinging the IP address 127.0.0.2, which is not assigned to that (or to any other) network interface results in failure:
% ping -c 1 127.0.0.2 PING 127.0.0.2 (127.0.0.2): 56 data bytes ping: sendto: Network is unreachable --- 127.0.0.2 ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss %The same is true for OpenBSD:
% ping -c 1 127.0.0.2 PING 127.0.0.2 (127.0.0.2): 56 data bytes ping: sendto: Network is unreachable ping: wrote 127.0.0.2 64 chars, ret=-1 --- 127.0.0.2 ping statistics --- 1 packets transmitted, 0 packets received, 100.0% packet loss %But on Linux where there is similarly no 127.0.0.2 configured ...
% ifconfig lo lo link up loopback running link address 00:00:00:00:00:00 bdaddr 00:00:00:00:00:00 inet4 address 127.0.0.1 prefixlen 8 bdaddr 127.0.0.1 inet4 address 127.53.0.1 prefixlen 8 bdaddr 127.255.255.255 inet6 address ::2 scope 0 prefixlen 128 inet6 address fe80:: scope 1 prefixlen 10 inet6 address ::1 scope 0 prefixlen 128 %... the ping is surprisingly successful:
% ping -c 1 127.0.0.2 PING 127.0.0.2 (127.0.0.2) 56(84) bytes of data. 64 bytes from 127.0.0.2: icmp_seq=1 ttl=64 time=0.044 ms --- 127.0.0.2 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.044/0.044/0.044/0.000 ms %How come? # Related questions * "https://unix.stackexchange.com/q/508007/5132 " — the very roundabout question, asking for an explanation of "virtual interfaces", that this question asks straightforwardly * "https://unix.stackexchange.com/q/169410/5132 " — several questions in one, rather than one question per question, and _not in fact answered_ by the purported duplicate * "https://unix.stackexchange.com/q/347825/5132 " — a question about why on Linux the
lo
interface seems to _also_ control the pingability of IP addresses that are assigned to _other_ network interfaces (behaviour that is similarly not what one gets on the BSDs)
* "https://unix.stackexchange.com/q/140008/5132 " — a question about _non-loopback_ behaviour
# Other references
* Jonathan de Boyne Pollard (2019). [ifconfig
](http://jdebp.eu./Softwares/nosh/guide/commands/ifconfig.xml) . _nosh Guide_. Softwares.
Asked by JdeBP
(71560 rep)
Mar 23, 2019, 11:47 AM
Last activity: Feb 17, 2025, 11:44 PM
Last activity: Feb 17, 2025, 11:44 PM