PING Command in Linux with examples
PING (Packet Internet Groper) command is used to check the network connectivity between host and server/host. This command takes as input the IP address or the URL and sends a data packet to the specified address with the message “PING” and get a response from the server/host this time is recorded which is called latency. Fast ping low latency means faster connection. Ping uses ICMP(Internet Control Message Protocol) to send an ICMP echo message to the specified host if that host is available then it sends ICMP reply message. Ping is generally measured in millisecond every modern operating system has this ping pre-installed.
Now let see the PING command :
To get ping version installed on your system.
sudo ping -v
To stop pinging we should use ctrl+c otherwise it will keep on sending packets.
- min: minimum time to get a response
- avg: average time to get responses
- max: maximum time to get a response
Controlling the number of pings:
Earlier we did not define the number of packets to send to the server/host by using -c option we can do so.
ping -c 5 www.geeksforgeeks.org
Controlling the size of packets send:
Earlier a default sized packets were sent to a host but we can send light and heavy packet by using
ping -s 40 -c 5 www.geeksforgeeks.org
Changing the time interval:
By default ping wait for 1 sec to send next packet we can change this time by using -i option.
ping -i 2 www.geeksforgeeks.org
Now, the ping interval will change to 2 seconds.
To get only summary:
To only get the summary about the network use -q option
ping -c 5 -q www.geeksforgeeks.org
To Timeout PING:
To stop pinging after sometime use -w option.
ping -w 3 www.geeksforgeeks.org
This will stop pinging after 3 seconds
Flooding with PING:
To send packets as soon as possible. This is used to test network performance.
ping -f www.geeksforgeeks.org
To Add Timestamp
It is current time of event recorded by a machine over a network. It works by using TS option of IP packet.
We have three option with it
- tsonly (timestamp only)
- tsandaddr (timestamp and address)
- tsprespec (timestamp pre-specified for multiple hosts)
ping -T tsonly -c 2 127.0.0.1 ping -T tsandaddr -c 2 127.0.0.1
Time to wait for response:
Sets time to wait for a response.
ping -c 5 -W 3 www.geeksforgeeks.org
To fill packet with data:
We can fill data in packet using -p option. Like -p ff will fill packet with ones.
ping -c 5 -p ff www.geeksforgeeks.org
Path MTU discovery:
It is a simple protocol to find out the maximum MTU(Maximum Transmission Unit) a TCP path can take.
We use an option with -m do (prohibit fragmentation), want (do PMTU discovery, fragment locally when packet size is large), or dont (do not set DF flag).
ping -c 5 -M want www.geeksforgeeks.org
Specify TTL(Time To Live):
It is maximum hop a packet can travel before getting discarded.A value 0 will restricty packet to same host.
ping -c 5 -t 64 www.geeksforgeeks.org