From where do I get a reply if I ping broadcast address 255.255.255.255 from a router
When I do a ping to the broadcast address, I get reply from self-loopback 127.0.0.1. Is this scenario correct or should I get reply from the longest-prefix IP?
ping 255.255.255.255
PING 255.255.255.255 (255.255.255.255): 40 data bytes
68 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=2 ms
68 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=1 ms
68 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=1 ms
68 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=2 ms
68 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=1 ms
--- 255.255.255.255 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss round-trip min/avg/max/stddev = 1/1/2/<1
Solution 1:
255.255.255.255 is a broadcast address, you are sending a ping to every device on your local network and you will get a reply from every device. The ping command is only showing the first reply it gets, in your case your own PC (127.0.0.1 is loopback) was the quickest. If you use a packet sniffer (like Wireshark) you will be able to see all replies.
Some devices will reply to a normal ping but will not reply to a ping sent to a broadcast address. This is to prevent an exploit called a Smurf attack.
255.255.255.255 will also broadcast to every device on the internet. For obvious reason this is blocked, the message will not leave your local network.