What port does 'ping' work on?
Solution 1:
Ping uses the ICMP protocol which doesn't have ports like the TCP and UDP protocols.
If you need to see if Ping is disabled on a Linux system, you can check:
cat /proc/sys/net/ipv4/icmp_echo_ignore_all
- 0 means Ping is enabled. (The system will respond to pings)
- 1 means Ping is disabled (The system will not respond to pings)
Solution 2:
TCP/IP uses a four-layer network stack. The Link layer deals with the physical media and how to get bytes across, the Internet layer deals with IP addresses and how to route data from one node to another, the Transport layer deals with TCP and UDP sessions, and the Application layer is what user programs use to interact with the network normally.
Pings are implemented as part of ICMP, the Internet Control Message Protocol, which deals with things like errors, congestion, and the like. ICMP is implemented in the Internet layer, and is therefore blissfully ignorant of things like encryption, ports, sessions, and other things provided by the upstream layers, and is also unaware of how the bytes are physically getting from point A to point B (which is the main point of the Link layer).
All of this means that pings are inherently without a port. They don't operate on any port number, as those are implemented in a different level. When you request a ping, this operation effectively bypasses the Application and Transport Layers, and directly asks the Internet layer to diagnose a connection (namely, to see how long it takes to get a response). This is often directly implemented in a network driver, and doesn't require any special user application to request or respond to a ping.
You can turn pings responses on and off, but you can't configure something that literally has no concept in the layer you're asking about. For any given Operating System, you simply need to check your online manual for how to enable or disable ping responses. The other answer goes into detail about enabling/disabling it on Linux, while this answer was meant to address why there are no ports that can be configured for pings.
Solution 3:
Conventional "Ping" uses the ICMP protocol, which is separate from TCP and UDP that have the concept of "ports". I drew a diagram so it's easier to understand: