ping
ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST datagrams ('pings') have an IP and ICMP header, followed by a struct timeval and then an arbitrary number of 'pad' bytes used to fill out the packet.[1]
Documentation
Syntax
ping [PARAMETER ...] HOST
Parameters
- General
- The following parameters can be used with all version of ping:
- -c COUNT
- Stop after sending COUNT ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.
- -f
- Flood ping. For every ECHO_REQUEST sent a period . is printed, while for ever ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. If interval is not given, it sets interval to zero and outputs packets as fast as they come back or one hundred times per second, whichever is more. Only the super-user may use this option with zero interval.
- -i INTERVAL
- Wait INTERVAL seconds between sending each packet. The default is to wait for one second between each packet normally, or not to wait in flood mode. Only super-user may set interval to values less 0.2 seconds.
- -I ADDRESS
- Set source address to specified ADDRESS. Argument may be numeric IP address or name of device. When pinging IPv6 link-local address this option is required.
- -l PRELOAD
- If PRELOAD is specified, ping sends that many packets not waiting for reply. Only the super-user may select preload more than 3.
- -n
- Numeric output only. No attempt will be made to lookup symbolic names for host addresses.
- -q
- Quiet output. Nothing is displayed except the summary lines at startup time and when finished.
- -s NUMBER
- Specifies the NUMBER of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.
- GNU
- The following parameters can be used with the GNU version of ping:
- -A
- Adaptive ping. Interpacket interval adapts to round-trip time, so that effectively not more than one (or more, if preload is set) unanswered probes present in the network. Minimal interval is 200 msec for not super-user. On networks with low RTT this mode is essentially equivalent to flood mode.
- -b
- Allow pinging a broadcast address.
- -t TTL
- Set the IP TTL.
- -w TIME
- Specify a TIME, in seconds, before ping exits regardless of how many packets have been sent or received. In this case ping does not stop after count packet are sent, it waits either for deadline expire or until count probes are answered or for some error notification from network.
- -W TIME
- TIME to wait for a response, in seconds. The option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.
- BSD
- The following parameters can be used with the BSD version of ping:
- -t TIME
- Specify a TIME, in seconds, before ping exits regardless of how many packets have been received.
- -T TTL
- Set the IP Time To Live for multicasted packets. This flag only applies if the ping destination is a multicast address.
Examples
- Test if a machine is alive from a script (GNU version only)
if ping -c 1 -w 1 'xeon.raysoft.loc' >'/dev/null' 2>&1; then
echo 'Machine is alive!'
fi
- Test if a machine is alive from a script (BSD version only)
if ping -c 1 -t 1 'xeon.raysoft.loc' >'/dev/null' 2>&1; then
echo 'Machine is alive!'
fi
References
- ↑ man 8 'ping'