Ping – What Happens When a Ping Enters a Network

ippingprotocol-theory

What happens with a ping when it enters a network? Does the router redirects it to one of the devices on the network, or it sends the reply itself?

Device a1 from network A, with public IP adress P1 sends a ping to a public IP on network B, with IP P2. The ping arrives in the B network throug the router R. Is the router R the one responding to the ping, or it redirects the ping to one of the devices on the B network, e.g. b1?

EDIT: to explain my bewilderment. A ping request has a destination, for ex. a public IP. But in many cases, that public IP belongs to a whole network. For example a personal network. Which device from that network deals with the ping response?

Best Answer

What happens with a ping when it enters a network? Does the router redirects it to one of the devices on the network, or it sends the reply itself?

A router routes packets towards the destination. An IP packet with ICMP payload (ICMP ping request) is treated no differently than any other packet.

With "enter a network" you might be referring to routing a packet from public IP space (the Internet) to a private IPv4 address. Since private addresses are meaningless in public space by definition, this isn't even possible. Packets with private destination addresses are usually dropped by Internet routers and cannot by used.

However, since connecting private IP space with public IP space usually involves NAT, you need to understand how that works. Connecting into a private LAN requires port forwarding aka reverse NAT aka destination NAT. Connecting out of a private LAN requires source NAT - the private IP address is replaced by a usable public IP from the router's pool.

So, if your server www.domain.tld is located inside your LAN and the HTTP/S ports are forwarded by the router, this forwarding works only for the defined protocols - TCP with port 80 or 443 in that case. Since www.domain.tld resolves to the public IP address of your router, pinging by name actually pings the router's public address.

Similar to port forwarding, some routers do allow forwarding ICMP to an internal host but that is normally only used for static NAT/exposed host setups where you have a dedicated public IP for a host and forward everything.

But in many cases, that public IP belongs to a whole network.

As explained above and by the other answers, you are confusing NAT routing with normal routing. Only when a (private) network is hidden behind a single public IP, that address is the only one you see from the outside. It's also very common to use a pool of public IP addresses which may be used purely randomly or by some correlations.

"Routing" does not imply NAT. Effectively, NAT is rarely used - only by the edge routers connecting public and private IP spaces, which does make it prominent. All other routers - on the Internet or within private LANs - don't require NAT and typically don't use it.

NAT is designed as a kludge to enable private IPv4 networks to use their own, not IANA-managed addressing in order to avoid the early exhaustion of public IPv4 addresses. With IPv6, this kludge doesn't even exist to this extent (NAT64 is a proposed standard only).

For example a personal network. Which device from that network deals with the ping response?

While home networks are off-topic here, these use a public IP address that the NAT router translates to (or from). So, you can only ever ping that router from the outside.

Note that all these translations are only required by and used with IPv4. IPv6 doesn't require any translation, so it's more logical and follows the proper end-to-end paradigm of TCP/IP.