41

Is there any particular port number that the ping command works on by default?

Also on a Linux system, is there a way to figure out by yourself which port numbers it runs on and configure a different port number for it?

6
  • there's a free windows utility called paping which can test a TCP port instead of a normal ICMP packet. In that case you specify the port number. It is similar to using telnet or putty to connect to a specific port with a short timeout.
    – LPChip
    Jul 26, 2021 at 13:20
  • @LPChip I assume you mean PsPing (typo?)
    – user541686
    Jul 26, 2021 at 23:19
  • 4
    No need to download anything. Powershell has a Test-NetConnection cmdlet that’ll test a specific port. docs.microsoft.com/en-us/powershell/module/nettcpip/…
    – Greg W
    Jul 27, 2021 at 3:12
  • @user541686 no, paping: code.google.com/archive/p/paping/downloads. PsPing looks interesting though. :) More capable it seems. Have to try that out.
    – LPChip
    Jul 27, 2021 at 6:45
  • I don't want to answer about Windows, if the question is about Linux, but it looks like from NetLimiter that Windows will listen on port 139 for ping requests with System process 4. They show up there every time and that process number is constant, even though ping uses ICMP as noted below. I'm not entirely sure what the reason for that is, so I can't really give a properly formed answer, because I'm not entirely sure that use of that port is operating system independent.
    – user56983
    Jul 27, 2021 at 21:51

4 Answers 4

65

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)
9
  • 4
    Concur - there are other things named "ping" like tcpping and arping that work on different protocols, but they're not the common ping.
    – Criggie
    Jul 27, 2021 at 4:31
  • 2
    But isn't ping a service running on a system responding to the ping request. And won't any service on the internet will have a port number?
    – joseph
    Jul 27, 2021 at 13:40
  • 5
    @joseph TCP and UDP protocol services will have ports. ICMP doesn't have that concept. If you used ICMP protocol to send a message, you don't specify a port, just that protocol.
    – Josh Zhang
    Jul 27, 2021 at 13:52
  • 13
    @joseph: nope! Port numbers are a thing for tcp and udp, but icmp is a separate protocol at the same level; it's distinguished as protocol 1 in the protocol field of the IP packet (tcp and udp are 6 and 17 respectively). As to whether it's a "service", well, anything can be modelled as a service, but it's certainly not implemented as a daemon listening on a tcp or udp port. In most cases I believe it's answered within the OS kernel, except for OSs in which TCP is modularized outside the kernel.
    – CCTO
    Jul 27, 2021 at 13:52
  • 4
    @CCTO, Re, "...within the OS kernel, except for OSs in which TCP is modularized..." There's a simpler way to say that: ICMP is implemented within the TCP/IP stack. Depending on the OS, The TCP/IP stack could be part of the kernel, or it could be a driver or a loadable kernel module, or it could be a user-mode process, etc. Jul 27, 2021 at 21:06
43

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.

6
  • On the other hand, ICMP works on top of IP, so on the same level as TCP and UDP. Name it to the transport or network layer as you will.
    – ilkkachu
    Jul 28, 2021 at 16:20
  • 6
    IP and ICMP are not independent protocols: you couldn't use ICMP on top of a different layer-3 protocol, as it is part of IP, but it uses IP in much the same way that TCP (a layer-4/transport protocol) would.
    – chepner
    Jul 28, 2021 at 16:46
  • @chepner Theoretically there's nothing preventing you to use ICMP over another L3 protocol, similar to how TCP and UDP runs perfectly well on both IPv4 and IPv6 (ICMPv6 is another story). There's just no reason or support to do it.
    – iBug
    Jul 29, 2021 at 7:21
  • @iBug Except that ICMP is an L2 protocol, as is IPv4 and IPv6. They all live on the same layer. TCP and UDP both work on the layer above (L3) and so don't care about what happens at L1 (Ethernet/WiFi/etc) or L2 (IPv4/IPv6/etc). The Internet Suite of protocols only have four layers.
    – phyrfox
    Jul 29, 2021 at 15:18
  • @phyrfox It doesn't make sense to me that ICMP is on the same level as IPv4 or IPv6. ICMP is indicated in the IP header "protocol type" number 1 (as TCP=6 and UDP=17, while ICMPv6=58). ICMP also allows extra payload than just the message itself for various message types. Also, conventional naming systems designates "Layer 3" for IP and "Layer 4" for ICMP/TCP/UDP. Your answer could have had less confusion by adhering to common sense and conventions.
    – iBug
    Jul 29, 2021 at 18:05
7

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:

3
  • 1
    It sounds like you mixed up OSI and TCP/IP and got somewhere in the middle. There's 7 layers in OSI, and 4 layers in TCP/IP. Your L1/L2 layers are just L1 in TCP/IP, ICMP/IPv4/IPv6 are L2, UDP/TCP is L3, and HTTPS/SSH/etc are L4.
    – phyrfox
    Jul 29, 2021 at 15:16
  • @phyrfox Where do you get that from? I could agree with you that TCP/IP is a 4-layered model, but I'm more convinced that "data link" is L2, IPv4/IPv6 is "network layer" (L3), ICMP is "transport layer" and thus L4, and everything application above being L5. I would very appreciate if you could back up your claim.
    – iBug
    Jul 29, 2021 at 17:58
  • I learned this in college, but you can read about it on docs like this one. The names vary, but almost everyone agrees there's four layers, Network, Internet, Transport, and Application. Anything to do with PHY layer exists on Network, intra-network routing is handled at the Internet layer, including ICMP, Transport handles "sessions", such as UDP/TCP/etc, and the aptly named Application layer handles the rest.
    – phyrfox
    Jul 29, 2021 at 18:12
2

What port does 'ping' work on?

None.

Ping actually is NOT a service in the traditional sense. There is no ping daemon server.

Ping (formally, ICMP Echo) is provided by the IP driver in the kernel, perhaps even by hardware itself in some architectures with hardware offloading. Also as others have mentioned, it uses ICMP. The world isn't split between either udp or tcp.

Other Layer4 protocols exist with varying degrees of commonality, like ICMP, IGMP, PPTP, part of IPSec.

There is a spinoff of ping called tcping which accomplishes the same thing as ping more or less, using a tcp port of your choosing. In its case, there still isn't a "ping server". The "server" is whatever server software you happen to point it at.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .