ping Command

Purpose

Sends an ECHO_REQUEST to a network host.

Syntax

ping [ -d ] [ -D ] [ start of change-Fend of change ] [ -n ] [ -q ] [ -r ] [ -v] [  -R ] [ -a addr_family ] [ -c Count ] [ -w timeout ] [ start of change-uend of change ] [ -f-i Wait ] [ -l Preload ] [ -p Pattern  ] [ -s PacketSize  ] [ -S hostname/IP addr ] [ -L ] [ -I a.b.c.d. ] [ -o interface ] [ -T ttl ] [ -E Interface_name | Source_Hostname | Source_IP_address ] Host [ PacketSize ] [ Count ]

Description

The ping command sends an Internet Control Message Protocol (ICMP) ECHO_REQUEST to receive an ICMP ECHO_RESPONSE from a host or a gateway. The ping command has the following functions:

  • Determines the status of the network and the status of the foreign hosts only.
  • Tracks and isolates the hardware and software issues.
  • Tests, measures, and manages the networks.

If the host is operational and on the network, the host responds to the echo. Each echo request contains an Internet Protocol (IP), ICMP header, ping process ID (PID), timeval structure, and the bytes that are required to complete the packet.

The ping command sends one datagram per second and prints one line of output for every response that is received from the network host. The ping command calculates the round-trip times, statistics of the packet loss, and displays a summary on completion. The ping command is complete when the program times out or upon the receipt of a SIGINT signal. The Host parameter is a valid hostname or an IP address.

The ping command, by default, continues to send echo requests to the display until an interrupt is received (Ctrl-C). You can change the Interrupt key by using the stty command.

Repeated echo requests might overload the system. Hence, repeated echo requests must be used primarily for problem isolation.

Flags

Table 1. Flags
Item Description
-c Count Specifies the number of echo requests as indicated by the Count variable that must be sent and received.
-w timeout Makes the ping wait for a maximum of timeout seconds for a reply after sending the last packet. The -w flag works only with the -c flag.
-d Starts the debugging at the socket-level.
-D Causes a hex dump to a standard output of ICMP ECHO_REPLY packets.
-E Interface_name | Source_Hostname | Source_IP_address Sends or receives the ping packets over a specific interface for the Internet protocol version 4 (IPv4) and Internet protocol version 6 (IPv6). If you specify an interface name, a source hostname, or a source IP address, which is not the interface addresses of the machine, an error returns and the ping packets are not sent. If you specify an interface name with the -E flag, by default, the number of echo requests (-c Count) is set to a value of 5.
Notes:
  • The -E flag makes sure to send or receive a ping packet over a specific interface.
  • The -E flag works only on the destination Media Access Control (MAC) address, and not on the saved routes. Therefore, the -E flag works in the IPv4 protocol only if the address resolution protocol (ARP) is resolved. The -E flag works in the IPv6 protocol only if the neighbor discovery protocol (NDP) resolves an IPv6 address into a MAC address.
  • You cannot run the -R flag with the -E flag because the -E flag does not work on the saved routes.
start of change-Fend of change Displays the latency of the ping command in floating point precision.
-f Specifies the flood-ping option. The -f flag floods or outputs packets as fast as they come back or 100 times per second, whichever is more. For every ECHO_REQUEST that is sent, a period (.) is printed, while for every ECHO_REPLY that is received, a backspace (/) is printed. This operation provides a rapid display of how many packets are being dropped. The -f flag is used only by the root user.
Note: Use the -f flag with caution. Flood pinging is only permitted by the root user. The -f flag is incompatible with the -i Wait flag.
-I a.b.c.d Specifies that the interface that is specified by the a.b.c.d variable must be used for the outgoing IPv4 multicasts.
-o interface Specifies that the interface variable must be used for the outgoing IPv6 multicasts. The interface is specified in the form of en0, tr0, and so on.
-i Wait Waits the number of seconds specified by the Wait variable between each packet transmission. The default is to wait for one second between each packet. The -i flag is incompatible with the -f flag. start of changeIf you specify the -u flag, an interval that is passed to the -i flag is considered in microseconds. The valid range of interval with the -u flag is greater than or equal to 50 and lesser than 1000000 microseconds. A value of 1000000 microseconds equals 1 second. Do not use the -i flag with the -D flag.end of change
-L Disables the local loopback for the multicast pings.
-l Preload Sends the number of packets that are specified by the Preload variable as fast as possible before falling into a normal mode of behavior. The normal mode of behavior is one per second.
-n Specifies only the numeric output. An attempt is not made to look up a symbolic name for the host addresses.
-p Pattern Specifies up to 16 pad bytes to complete the packet you send. The -p flag diagnosis data-dependent problems in a network. For example, -p ff fills the packet with all 1's.
-q Specifies the quiet output. Only the summary lines at the start and end time are displayed.
-r Skips routing tables and sends directly to a host on a connected network. If the Host is not on a directly connected network, the ping command generates an error message. The -r flag can be used to ping a local host through an interface that no longer has a route through it.
-R Specifies the RECORD_ROUTE option. The -R flag includes the RECORD_ROUTE option in the ECHO_REQUEST packet and displays the route buffer on the returned packets.
Note: The IP header is large enough for nine such routes. Many hosts and gateways ignore the -R flag.
-a addr_family Maps the destination address of the ICMP packets to IPv6 format if addr_family is equal to inet6.
-s PacketSize Specifies the number of data bytes that must be sent. The default data byte is 56, which converts into 64 ICMP data bytes when combined with the 8 bytes of the ICMP data header.
-S hostname/IP addr Uses the IP address as the source address in the outgoing ping packets. On hosts with more than one IP address, the -S flag can be used to send or receive the ping packets by using a specific source IP address. If the IP address is not one of the interface addresses of the machine, an error is returned and nothing is sent.
Note: You can use the -S flag to send or receive the ping packet by using a specific source IP address, but the -S flag does not guarantee to send or receive a ping packet over a specific interface. Instead, use -E flag that ensures to send or receive a ping packet over a specific interface.
-T ttl Specifies that the time to live for a multicast packet is ttl seconds.
start of change-uend of change Use the -u flag along with the -i flag. If you specify the -u flag, an interval that is passed to the -i flag is considered in microseconds. The valid range of interval with the -u flag is greater than or equal to 50 and lesser than 1000000 microseconds. A value of 1000000 microseconds equals 1 second. Do not use the -u flag with the -D flag.
-v Requests the verbose output, which lists the ICMP packets that are received in addition to the echo responses.

Parameters

Table 2. Parameters
Item Description
PacketSize Specifies the number of data bytes that must be sent. The default data byte is 56, which converts into 64 ICMP data bytes when you combine with the 8 bytes of the ICMP header data. This parameter is included for compatibility with the previous versions of the ping command.
Count Specifies the number of the echo requests that you must send and receive. This parameter is included for compatibility with previous versions of the ping command.

Security

Attention RBAC users
Attention RBAC users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in Security. For a list of privileges and the authorizations that are associated with this command, see the lssecattr command or the getcmdattr subcommand.

Examples

  1. To check the network connection of the host that is known as canopus and to specify the number of echo requests that must be send, enter the following command:
    ping  -c 5 canopus
    OR
    ping canopus  56  5
    An output similar to the following example is displayed:
    PING canopus.austin.century.com: (128.116.1.5): 56 data bytes
    64 bytes from 128.116.1.5: icmp_seq=0 ttl=255 time=2 ms
    64 bytes from 128.116.1.5: icmp_seq=1 ttl=255 time=2 ms
    64 bytes from 128.116.1.5: icmp_seq=2 ttl=255 time=3 ms
    64 bytes from 128.116.1.5: icmp_seq=3 ttl=255 time=2 ms
    64 bytes from 128.116.1.5: icmp_seq=4 ttl=255 time=2 ms
    
    ----canopus.austin.century.com PING Statistics----
    5 packets transmitted, 5 packets received, 0% packet loss
    round-trip min/avg/max = 2/2/3 ms
  2. To get the information about the host that is known as lear and to start the socket-level debugging, enter the following command:
    ping  -d  lear
    An output similar to the following example is displayed:
    PING lear.austin.century.com: (128.114.4.18) 56 data bytes
    64 bytes from 128.114.4.18: icmp_seq=0 ttl=255 time=6 ms
    64 bytes from 128.114.4.18: icmp_seq=1 ttl=255 time=17 ms
    64 bytes from 128.114.4.18: icmp_seq=2 ttl=255 time=6 ms
    64 bytes from 128.114.4.18: icmp_seq=3 ttl=255 time=6 ms
    64 bytes from 128.114.4.18: icmp_seq=4 ttl=255 time=6 ms
    ^C
    ----lear.austin.century.com PING Statistics ----
    5 packets transmitted, 5 packets received, 0% packet loss
    round-trip min/avg/max = 6/8/17 ms
    Note: The output is repeated until an interrupt (C®trl-C) is received.
  3. To obtain an information about the host that is known as opus and to specify the number of data bytes that must be sent, enter the following command:
    ping  -s 2000 opus
    OR
    ping opus  2000
    An output similar to the following example is displayed:
    PING opus.austin.century.com: (129.35.34.234): 2000 data bytes
    2008 bytes from 129.35.34.234: icmp_seq=0 ttl=255 time=20 ms
    2008 bytes from 129.35.34.234: icmp_seq=1 ttl=255 time=19 ms
    2008 bytes from 129.35.34.234: icmp_seq=2 ttl=255 time=20 ms
    2008 bytes from 129.35.34.234: icmp_seq=3 ttl=255 time=20 ms
    2008 bytes from 129.35.34.234: icmp_seq=4 ttl=255 time=20 ms
    2008 bytes from 129.35.34.234: icmp_seq=5 ttl=255 time=19 ms
    2008 bytes from 129.35.34.234: icmp_seq=6 ttl=255 time=19 ms
    ^C
    ----opus.austin.century.com PING Statistics----
    7 packets transmitted, 7 packets received, 0% packet loss
    round-trip min/avg/max = 19/19/20 ms
    Note: The output is repeated until an interrupt (Ctrl-C) is received.
  4. To start the flood-ping option to the host stlopnor, enter the following command:
    ping  -f stlopnor
    An output similar to the following example is displayed:
    Ping stlopnor.austin.century.com: (129.35.34.234): 56 data bytes
    .^C
    ----stlopnor.austin.century.com PING Statistics ----
    1098 packets transmitted, 1097 packets received, 0% packet loss
    round-trip min/avg/max = 4/4/11
    Note: The output is repeated until an interrupt (Ctrl-C) is received.
  5. To specify an interval of five seconds between the packets that are sent to the host opus, enter the following command:
    ping  -i5 opus
    An output similar to the following example is displayed:
    PING opus.austin.century.com: (129.35.34.234): 56 data bytes
    64 bytes from 129.35.34.234: icmp_seq=0 ttl=255 time=5 ms
    64 bytes from 129.35.34.234: icmp_seq=1 ttl=255 time=5 ms
    64 bytes from 129.35.34.234: icmp_seq=2 ttl=255 time=6 ms
    ^C
    ----opus.austin.century.com PING Statistics----
    3 packets transmitted, 3 packets received, 0% packet loss
    round-trip min/avg/max = 5/5/6 ms
    Note: The output is repeated until an interrupt (Ctrl-C) is received.
  6. To send the number of packets that are specified by the Preload variable before it falls into a normal mode of behavior to the host opus, enter the following command:
    ping  -l 10 opus
    An output similar to the following example is displayed:
    PING opus.austin.century.com: (129.35.34.234): 56 data bytes
    64 bytes from 129.35.34.234: icmp_seq=0 ttl=255 time=9 ms
    64 bytes from 129.35.34.234: icmp_seq=1 ttl=255 time=11 ms
    64 bytes from 129.35.34.234: icmp_seq=2 ttl=255 time=16 ms
    64 bytes from 129.35.34.234: icmp_seq=3 ttl=255 time=22 ms
    64 bytes from 129.35.34.234: icmp_seq=4 ttl=255 time=26 ms
    64 bytes from 129.35.34.234: icmp_seq=5 ttl=255 time=27 ms
    64 bytes from 129.35.34.234: icmp_seq=6 ttl=255 time=30 ms
    64 bytes from 129.35.34.234: icmp_seq=7 ttl=255 time=31 ms
    64 bytes from 129.35.34.234: icmp_seq=8 ttl=255 time=33 ms
    64 bytes from 129.35.34.234: icmp_seq=9 ttl=255 time=35 ms
    64 bytes from 129.35.34.234: icmp_seq=10 ttl=255 time=36 ms
    64 bytes from 129.35.34.234: icmp_seq=11 ttl=255 time=6 ms
    64 bytes from 129.35.34.234: icmp_seq=12 ttl=255 time=6 ms
    64 bytes from 129.35.34.234: icmp_seq=13 ttl=255 time=6 ms
    64 bytes from 129.35.34.234: icmp_seq=14 ttl=255 time=7 ms
    64 bytes from 129.35.34.234: icmp_seq=15 ttl=255 time=6 ms
    ^C
    ----opus.austin.century.com PING Statistics----
    16 packets transmitted, 16 packets received, 0% packet loss
    round-trip min/avg/max = 6/19/36 ms
    Note: The output is repeated until an interrupt (Ctrl-C) is received.
  7. To diagnose a data-dependent problem in a network, enter the following command:
    ping -p ff opus
    This command sends the packets with a pad-pattern of all 1's to the host opus. An output similar to the following example is displayed:
    PATTERN: 0xff
    PING opus.austin.century.com: (129.35.34.234): 56 data bytes
    64 bytes from 129.35.34.234: icmp_seq=0 ttl=255 time=5 ms
    64 bytes from 129.35.34.234: icmp_seq=1 ttl=255 time=5 ms
    64 bytes from 129.35.34.234: icmp_seq=2 ttl=255 time=5 ms
    64 bytes from 129.35.34.234: icmp_seq=3 ttl=255 time=6 ms
    64 bytes from 129.35.34.234: icmp_seq=4 ttl=255 time=5 ms
    ^C
    ----opus.austin.century.com PING Statistics----
    5 packets transmitted, 5 packets received, 0% packet loss
    round-trip min/avg/max = 5/5/6 ms
    Note: The output is repeated until an interrupt (Ctrl-C) is received.
  8. To specify a quiet output, enter the following command:
    ping  -q bach
    A summary information similar to the following sample is displayed:
    PING bach.austin.century.com: (129.35.34.234): 56 data bytes
    ^C
    ----bach.austin.century.com PING Statistics----
    5 packets transmitted, 5 packets received, 0% packet loss
    round-trip min/avg/max = 5/5/8 ms
    Note: The output is repeated until an interrupt (Ctrl-C) is received.
  9. To send or receive the ping packets over a specific interface, enter the following command:
    ping -E en1 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02
    An output similar to the following example is displayed:
    Using Source Address 2020:1234:5678:9122:2c6f:57ff:3e6b:58
    PING 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02: (2020:1234:5678:9122:2c6f:57ff:fe6b:8b02): 56 data bytes
    64 bytes from 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02: icmp_seq=0 ttl=64 time=1.462 ms
    64 bytes from 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02: icmp_seq=1 ttl=64 time=0.917 ms
    64 bytes from 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02: icmp_seq=2 ttl=64 time=1.187 ms
    64 bytes from 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02: icmp_seq=3 ttl=64 time=1.105 ms
    64 bytes from 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02: icmp_seq=4 ttl=64 time=1.114 ms
    
    --- 2020:1234:5678:9122:2c6f:57ff:fe6b:8b02 ping statistics ---
    5 packets transmitted, 5 packets received, 0% packet loss
    round-trip min/avg/max = 0/0/1 ms
  10. start of changeTo check the network connection of the host ping server that is known as commodev2 and specify that the latency must be in floating point precision, enter the following command:
    ping -F commodev2
    An output similar to the following example is displayed:
    # ping -F commodev2
    PING commodev2.pok.stglabs.ibm.com: (9.114.250.236): 56 data bytes
    64 bytes from 9.114.250.236: icmp_seq=0 ttl=255 time=0.315 ms
    64 bytes from 9.114.250.236: icmp_seq=1 ttl=255 time=0.100 ms
    64 bytes from 9.114.250.236: icmp_seq=2 ttl=255 time=0.088 ms
    64 bytes from 9.114.250.236: icmp_seq=3 ttl=255 time=0.090 ms
    --- commodev2.pok.stglabs.ibm.com ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.088/0.148/0.315 ms
    end of change
  11. start of changeTo specify an interval of 1000 microseconds between the packets that are sent to the host commodev6 (ping server), enter the following commands:
    • In the following example, the host ping server commodev6 goes down for a duration of 4 seconds and 2 seconds consecutively.

      # ping -ui 1000 commodev6
      PING commodev6.pok.stglabs.ibm.com: (9.114.248.17): 56 data bytes
      Packets from icmp_seq 1507 (time:14:20:09.283540) to 5464 (time:14:20:13.287128) missed
      Packets from icmp_seq 10415 (time:14:20:18.295048) to 12396 (time:14:20:20.299296) missed
      --- commodev6.pok.stglabs.ibm.com ping statistics ---
      19438 packets transmitted, 13497 packets received, 30% packet lost
      round-trip min/avg/max = 0.050/0.058/0.124 ms
    • In the following example, the longer distance between the ping client and the ping server causes the ping response to be delayed and out of order.

      # ping -ui 1000 aixbase.aus.stglabs.ibm.com
      PING aixbase.aus.stglabs.ibm.com: (9.3.199.113): 56 data bytes
      Packets from icmp_seq 179 (time:14:24:17.106403) to 181 (time:14:24:17.340580) missed
      icmp_seq=181 received out of order
      icmp_seq=179 received out of order
      icmp_seq=180 received out of order
      …
    • In the following example, responses are not received from the commodev6 ping server.

      # ping -ui 1000 commodev6
      PING commodev6.pok.stglabs.ibm.com: (9.114.248.17): 56 data bytes
      --- commodev6.pok.stglabs.ibm.com ping statistics ---
      3609 packets transmitted, 0 packets received, 100% packet loss
    • In the following example, the ping server is up all the time and responses to all the ping requests are received in the ping client.

      # ping -ui 1000 commodev6
      PING commodev6.pok.stglabs.ibm.com: (9.114.248.17): 56 data bytes
      
      --- commodev6.pok.stglabs.ibm.com ping statistics ---
      1989 packets transmitted, 1989 packets received, 0% packet loss
      round-trip min/avg/max = 0.050/0.056/0.322 ms
    end of change