We may also get the time duration for transmitting and receiving answers from a network using the Linux ping program. Ping sends a sequence of Internet Control Message Protocol (ICMP) packets to the host and then waits for an ICMP response message from the host. This gives us information about the network’s operation.
Commonly performed tasks by Ping are:
- Checking status of network
- Check internet connection
- Check for network Issues
In this Article, the functions/usage of Ping command will be discussed.
Checking Ping Utility Existence In your System
Ping command is present in many Linux system by default but to verify its existence, check its version by below mentioned command:
How to use the Ping Command
The Syntax to follow for the Ping command is mentioned below:
$ ping [options] [hostname/IP]
To check the connectivity of any host, you can use the ping command. Here I am pinging the youtube server by below mentioned command and check the result below:
Above output describe the following information:
|Icmp_seq||It tells Sequence number of Packet. For instance, first packet has icmp_seq=1|
|ttl||Stands for “time to live”. It tells the count of “network hops” a packet takes before the discarding of the router. Its range is 1-255|
|time||The time it took for a package to get to its destination and return to its origin. Milliseconds are used to express time.|
Press Ctrl+C to stop the process, and after the process ends the count of packets received or transmitted, the count of packets lost and also time are all reported by this command as shown below:
There will be no network connectivity between your device and the host server if you do not get a ping response.
How to use ping command on Ubuntu
Some commonly used ping commands are following:
Changing Time Interval between Packets using Ping Command on Ubuntu
By default, the ping command delivers packets after one second, although this period can be changed.
By using “-i” flag after ping command we can change the time by below mentioned syntax:
$ ping -i [changed time] host address
To increase time: If you want to increase the time interval between packets then specify “changed time” greater than 1 after -i.
For instance, I want to change the time of ping of “youtube” and set to 3, then I will run below mentioned command on terminal:
To decrease time: If you want to decrease the time interval between packets then specify “ping time” less than 1 after -i.
For instance, I want to decrease ping time of the “youtube” and set to 0.3, then I will run below mentioned command on terminal:
$ ping -i 0.3 youtube.com
Limiting the Number of Packets
The ping command sends packets until it is stopped manually by pressing Ctrl+c, although the number of packets sent can be restricted using the “-c” option. Below mentioned is its syntax:
$ ping -c [Number-of-packets] hostname
For instance, I restrict “youtube.com” time to execute 3 Packets by below mentioned command:
Limiting Packet by specifying Time for Packets to execute
Another way to limit the number of Packets is by setting time by using “-w” flag as shown in below mentioned command:
Checking Local Network Status Using Ping Command
If you are facing some problems accessing a website. So, by using Ping command you can diagnose your local network connectivity: There are various ways to ping localhost:
First way : Easiest way is using ping command with 0:
Second way : Using local host, here localhost referred to our computer:
Third way : Ping using IP address
Run the below mentioned command using your server IP address, you need to enters your IP:
Flooding A Network Using Ping Command on Ubuntu
To test your network under heavy load, you can use the Ping flood command, below mentioned is its syntax:
$ sudo ping -f [hostname/IP]
For instance, you want to test the performance of “youtube.com”, run the below mentioned command:
$ sudo ping -f youtube.com
In the above output dots represent the sent Packet and backspace represents response.
To get an Audible Ping while Host is Accessible Using Ping Command
When “-a” flag is used, the system produces a sound when response from host is received, below mentioned is its syntax:
For instance, to check the response from “youtube.com” run the below mentioned command:
Get Summary of Statistics Using Ping Command
If you don’t want to see the information for each Packet then use “-q” option to simply show the summary like shown in below mentioned command:
$ ping -c 5 -q youtube.com
Here we also used the “-c” flag to limit the ping command to send specified packages.
Check Time Before Each Line Execution Using Ping Command
Add the -D option to the ping command if you wish to record the time of day when you run it, it shows time in Unix, below mentioned is its syntax.
Pinging “youtube.com” to check time of when each packet executes by below mentioned command:
Commonly Used Ping Options
Mentioned below are some widely use Ping options and their use:
|-b||Allows you to ping a broadcast IP address|
|-d||Used for Socket Debugging|
|-I||Sets the maximum number of packets to send before waiting for a response. You will need superuser access to set a value higher than 3.|
|-r||Allows the routing table to be bypassed and data to be sent straight to the host.|
|-s||Set the size of Packet|
|-T||Set time to live(ttl)|
|-v||Additional ICMP packets and echo replies are displayed.|
Or you can run the below mentioned “help” command to view all options used with Ping command:
Ping is a very useful command which can be run on any terminal to check the network status or configure network performance. A number of functions related to network inspection are performed by ping command and are discussed in this article. This article will help you to learn the ping command without any difficulty and use it efficiently. Go through this Article in detail and get familiar with the Ping command and learn its uses.