+4 votes
277 views
Ping Linux command and examples

in Linux / Unix by (552k points)
reopened | 277 views

1 Answer

+5 votes
Best answer

1. How to use PING Linux command
2. Examples PING Linux command

In any type of organization, regardless of its infrastructure, and for many users, it is natural that at some point in the day to day it is necessary to use utilities that have been designed to validate, optimize and monitor various aspects of the system ..

One of these areas is associated with the network which is essential to not only access the internet, but it is also essential, in the case of corporate environments, for the roles, processes and services of the servers to function properly. . Within the utilities that allow us a centralized control over the state of the network we have the ping command, so TechnoWikis will make an analysis of what this command is and how it works, for this tutorial we will use Ubuntu 18.04.

What is the ping command?
The ping command has been developed as a network utility which is available for most operating systems whose mission is basically to validate if a host is accessible in an Internet Protocol (IP) network, that is, with ping it will be possible Verify that a device is capable of communicating through the network, local or external, with another device or network device.

In order for this process to be carried out correctly, the ping command sends a series of messages, called ECHO_REQUEST, from the Internet Control Message Protocol (ICMP) to the destination host and proceeds to wait for an ICMP echo response. , called ECHO_RESPONSE..

Based on the number of responses that are returned, and how long it takes to return, we will have information provided by the ping command to execute the administration and control tasks of the network. If the destination equipment is active, it is possible to measure the amount of time it takes for the packets to reach the destination host and return to our equipment, this is called TTL (Time to Live) and it is vital to check the status of the devices network between the local and remote equipment, likewise, the loss of some packet, is expressed as a percentage.

Uses ping command
The most common uses of the ping command are:
  • Validate and analyze the state of the network and several destination hosts.
  • Track and isolate hardware and software problems associated with the network.
  • Execute tests, measurement and network administration.

1. How to use PING Linux command


The ping command is executed by sending a datagram per second and this result is printed as an output line for each response received. In these results, we can see the round trip times and the statistics of packet loss, and a brief summary is also shown at the end of the command execution . The ping command will end when the program expires or when a SIGINT signal is received, by default, the ping command will continue sending echo requests to the destination computer until an interruption of the action is received (Ctrl-C).
Ping command syntax
There are several parameters to use with the ping command, the general syntax is as follows:
 ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS] [-r count] [-s count] [-w timeout] [- R] [-S srcaddr] [-p] [-4] [-6] target [/?] 

The variables to use are:

-t
This option is responsible for pinging the target until its arrest is forced using the Ctrl-C keys.

-to
This option resolves, if possible, the host name of an IP address destination.

-n count
With this option it is possible to set the number of ICMP echo requests to send, the options range from 1 to 4294967295. The ping command will send 4 by default if the -n parameter is not used.

-l size
This option allows you to set the size, in bytes, of the echo request packet in a range of 32 to 65,527. The ping command will send a 32-byte echo request if you do not use the -l option within the order.

-F
This option is responsible for preventing ICMP echo requests from being fragmented by routers between the source and destination equipment. The -f option is used more frequently to troubleshoot the maximum route transmission unit (PMTU) in local networks.

-i TTL
This option sets the value of Time to Live (TTL), its maximum value is 255.

-v TOS
With this option it will be possible to set a value of Type of Service - Type of service (TOS).

-r count
By using this option, we can specify the number of jumps between the source device and the destination device or device to which we will register and display. The maximum value for this action is 9.

-s count
This option allows us to inform the time, in Internet Timestamp format, in which each echo request is received and the echo response is sent. The maximum value to count is 4, so that only the first four jumps can be marked with time.

-w timeout
When specifying a wait time value, the amount of time, in milliseconds, that the ping waits for each response from the target team is adjusted, in case of not using this -w option, the time value of default wait of 4000, which is 4 seconds.

-R
This option allows you to run a round trip trace.

-srcaddr
With this option it will be possible to specify the source address.

-p
This option can be used at a Hyper-V network virtualization provider address.

-4
This parameter forces the ping command to use only IPv4 addresses, but it will only be useful if the destination is a host name and not an IP address.

-6
This parameter forces the ping command to use IPv6 addresses only.

Target
This value indicates the destination to be ping, either an IP address or a hostname.

/?
Display the ping command help

-f, -v, -r, -s, -jy -k
The -f, -v, -r, -s, -j and -k options work with IPv4 addresses only while the -R and -S options only work with IPv6.

2. Examples PING Linux command


Now let's see some practical examples for using ping in Linux
Basic Ping Execution
It is possible to run a simple ping test in order to verify that the destination host is reachable or not, remember that it is possible to use an IP address instead of a domain name as shown.
 ping www.solvetic.com 
As we have mentioned, this is a process that will be permanent and we can stop it with the Ctrl + C keys, when stopping the process, results will be displayed with details such as:
  • Number of packages sent
  • Number of packages received
  • Lost packages (in percentage format)
  • Total response time in milliseconds
image
Indicate the number of requests
It will also be possible to specify the number of ECHO_REQUEST requests that will be sent with the ping execution, this is achieved with the -c parameter and the number of requests to be sent:
 ping -c 7 www.solvetic.com 
In this case, only 7 requests will be sent to the destination team: image
Define interval in seconds
With the -i parameter it will be possible to set the interval in seconds between the sending of each packet, the default value is one second, we will execute the following for an interval of 4 seconds:
 ping -i 4 -c 6 www.solvetic.com 
So we will send 6 requests with a range of 4 seconds between each of them. image
Validate network response
To determine the response of the network in high load conditions, which is essential to check the capacity of the network, it is possible to run a flood ping which is responsible for sending requests much faster, this is achieved with the -fy parameter must be executed as root user.

The options to use are one of the following:

 sudo ping -f www.solvetic.com sudo ping -f -i 3 www.solvetic.com (indicating the interval between each request) 
image
Enable ping to broadcast
If we want to enable ping to broadcast, we can use the -b parameter.
 ping -b 192.168.0.255 
image
Limit the number of TTL
It is possible to limit the number of network jumps (TTL - Time-to-live) carried out by the ping command, this is achieved with the -t value, it will be possible to set any value between 1 and 255.

We must clarify that each router that receives the packet subtracts at least 1 from the count and if the count is even greater than 0, the router forwards the packet to the next hop, otherwise it will be discarded and an ICMP response is sent to our team ..

 ping -t 15 www.solvetic.com 
image
Define ping preload
If you specify a preload at the time of execution, the ping command sends many packets that do not expect a response, this must be run as root to select a preload of more than 3.
 sudo ping -l 6 www.solvetic.com 
image
Set packet size
The default packet size in ping is sufficient to determine the status of the network, but this value can be edited if necessary. It will be possible to specify the size of the payload, in number of bytes using the -s option, which will result in a total packet size of value provided plus 8 additional bytes for the ICMP header, for this we execute:
 ping -s 800 www.solvetic.com 
We have entered a size of 800 and we can see that ping sets 808: image
Define response time
If it is necessary to set the response time of a request, in seconds, we will use the -W option to do so:
 ping -W 9 www.solvetic.com 
image

If the case is to set a timeout in seconds, before the ping command is executed regardless of how many packets have been sent or received, we will use the -w parameter:

 ping -w 8 www.solvetic.com 
image
Enable debug packet details
We can use the -d option to enable the detail of the IP debugging package.
 ping -d www.solvetic.com 
image
See detailed information
It will be possible to enable detailed output using the -v indicator:
 ping -v www.solvetic.com 
image
Define IPv4 or IPv6 addresses
We can specify that the ping command only detect IPv4 or IPv6 addresses (if they exist), for this we execute the most appropriate option.
 ping -4 www.solvetic.com ping -6 www.solvetic.com 
image

In this way, the ping command is one of the most practical and comprehensive utilities to carry out the process of network control and management tasks.


by (3.5m points)
edited

Related questions

+5 votes
1 answer
asked Feb 22, 2020 in Linux / Unix by backtothefuture (552k points) | 349 views
+3 votes
1 answer
asked Dec 6, 2019 in Linux / Unix by backtothefuture (552k points) | 270 views
+5 votes
1 answer
asked Oct 4, 2019 in Linux / Unix by backtothefuture (552k points) | 247 views
+4 votes
1 answer
asked Sep 22, 2020 in Linux / Unix by backtothefuture (552k points) | 329 views
+5 votes
1 answer
asked Feb 21, 2020 in Linux / Unix by backtothefuture (552k points) | 298 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users