- The Linux Ping Command
- Using the Ping command
- Some Basic Ping functions
- Pinging the host for availability
- Increase/Decrease interval between ping packets
- Change ping packet size
- Set ping to send a desired number of packets
- Flooding the network
- Set ping timeout
- Audible ping
- Karim Buzdar
- PING Command in Linux with examples
- Ping Command in Linux [How to Ping in Linux]
- What Is Ping Command? [How to Use Linux Ping]
- More Linux Ping Command Options
- Conclusion
The Linux Ping Command
Ping or Packet Internet Groper is a network management utility that can check the connection status between a source and destination computer/device over an IP network. It also helps you estimate the time it takes to send and receive a response from the network.
We all have our favorite websites that we visit frequently; if one of them doesn’t load, we really want to know why. Is it because we don’t have an Internet connection, or is it problems with our Internet service provider that are preventing us from accessing the website? Another reason could be the unavailability of the website itself. Whatever the reason, the Linux Ping command can give you all the answers.
Ping uses the Internet Control Message Protocol (ICMP) to send and receive echo messages to and from the host or target computers to keep us informed of network performance. An ICMP request message is sent to the target computer; if the target IP address is available, it sends an ICMP message response to the host computer. This informs us about the connectivity status of the network, such as the round-trip time – the time it takes to send and receive an information packet.
Using the Ping command
In the Linux terminal type the following command:
This is the output you will get:
Let us describe(in alphabetic order) the commonly used options that you can see above:
Option | Description |
a | Use this option for a beep sound when the peer is reachable |
b | Use this option to allow pinging a broadcast address |
B | Use this option if you do not want to allow the ping to change the source address of the probe |
c (count) | Use this option to set the number of times to send the ping request |
d | Use this option to set the SO-DEBUG option on the socket being used |
f | Use this option to flood the network by sending hundred or more packets per second |
i (interval) | Use this option to specify an interval between successive packet transmissions. The default value of interval is 1 second |
I (interface address) | Use this option to set source address to the specified interface address. This option is required when pinging IPv6 link local address. Its argument can be an IP address or name of the device. |
l (preload) | Use this option to set the number of packets to send without waiting for a reply. For selecting a value more than 3, you need to be a super user. |
n | Use this option to display network addresses as numbers rather than as hostnames |
q | Use this option to display a quiet output. It means that only the summary is displayed at startup and finish time |
T (ttl) | Use this option to set the Time To Live |
v | Use this option for verbose output |
V | Use this option to display the version and exit |
w (deadline) | Use this option to specify a timeout, in seconds, before ping exits, regardless of how many packets have been sent or received. |
W (timeout) | Use this option to set the time(seconds) to wait for a response |
Some Basic Ping functions
Here are some basic ping functions that you will be used to check the performance of your network:
Pinging the host for availability
You can check if a host is alive or not through the following ping command:
Press Ctrl+C for breaking the command
Increase/Decrease interval between ping packets
The default time interval between sending each packet is 1 second in Linux. You can increase the time interval by setting a value greater than 1 and decrease it by setting a value less than 1. Advertisement
Here is an example to increase the time interval between two pings:
Here is an example to decrease the time interval between two pings:
As you can see in the following image, you need to be a superuser in order to set this time interval lesser than 0.2 seconds:
Therefore, the command should be executed with sudo. It should look like the following,
Enter the password when you are prompted and the command should work.
Change ping packet size
The default ping packet size is 56 bytes. You can change it through the following command:
Here we are setting the packet size to 100; you can see the value set to 100 in the first line of output:
Set ping to send a desired number of packets
You can set ping to send a desired number of packets as follows:
In the following example, we are setting the number of packets as 5; after that, the results will end:
Flooding the network
Ping command allows super users to send 100 or more packets per second through the following command:
Ping prints a “.” when sending a ping and “/” when receiving one.
Set ping timeout
You can set a time limit after which ping will exit; no matter how many ping packets are sent or received:
Here we are using 3 seconds as timeout:
Audible ping
The ping command can be set to play a beep to check whether the host is available as follows:
Practicing around with this tutorial will enable you to run ping commands to check your network performance in an optimal way. You can also use advanced switches to customize your requests and responses in ping.
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn
Источник
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 :
PING Version:
To get ping version installed on your system.
Using PING:
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.
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
-s option.
Changing the time interval:
By default ping wait for 1 sec to send next packet we can change this time by using -i option.
Now, the ping interval will change to 2 seconds.
To get only summary:
To only get the summary about the network use -q option
To Timout PING:
To stop pingig after sometime use -w option.
This will stop pinging after 3 seconds
Flooding with PING:
To send packets as soon as possible. This is used to test network performance.
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)
Time to wait for response:
Sets time to wait for a response.
To fill packet with data:
We can fill data in packet using -p option. Like -p ff will fill packet with ones.
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).
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 Command in Linux [How to Ping in Linux]
Ping command in Linux is the best solution to find that how your network connection is performing or also helpful while troubleshooting, testing, and diagnosing network connectivity issues. To help you to understand Linux ping command this article will guide you.
List of content you will read in this article:
Checking for the concept of Ping command in Linux? If yes, then this is the right place where you will get complete information and commands of Linux ping. Packet InterNet Groper is the full form for Ping. Software/Service determines whether or not a given IP address, host, or server is available from your network. The ping tool is often used to look for and diagnose network errors. Its mechanism is basic, but it saves time. It operates by sending a packet to the given IP address/client/server address and measuring the time it takes for that host to respond.
This is often referred to as latency. PING is the most popular method of troubleshooting any link. For example, it will respond or echo. Ping sends a packet containing the message «PING» to a server/host and receives a copy of the message from that host/server. Ping determines the «Round Trip Time» (or RTT) needed for a packet to hit a specific server or host.
One of the most commonly used methods for troubleshooting, monitoring, and diagnosing network access problems is the ping command. Linux Ping sends one or more ICMP (Internet Control Message Protocol) Echo Request packets to a designated network destination IP and waits for a response. When the shipment arrives at its destination, it receives an ICMP echo reply.
You can use the ping command to verify; if a remote destination IP is working or not. You should also search for packet loss and determine the round-trip delay when communication is established. Ping is included in the iputils (or iputils-ping) kit, pre-installed on almost all Linux distributions. In this guide, we will explain brief information on what is ping command is, how to use Linux ping and how does it works.
What Is Ping Command? [How to Use Linux Ping]
The ping command has the following syntax:
ping [OPTIONS] DESTINATION
Let’s ping google.com to understand how the ping command works:
The output of the ping will be something like this:
PING google.com (172.217.22.206) 56(84) bytes of data.
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.102): icmp_seq=1 ttl=53 time=40.2 ms
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.102): icmp_seq=2 ttl=53 time=41.8 ms
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.102): icmp_seq=3 ttl=53 time=47.4 ms
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.102): icmp_seq=4 ttl=53 time=41.4 ms
— google.com ping statistics —
We’ll go into the most popular ping command options in the below-given section.
Option 1: How to Select the number of packets you want to transfer.
Ping will continuously transfer the ICMP packets until an interrupt signal is received. Using the -c alternative followed by the number of packages to send before ping exits to specify the number of Echo Request packages to send before ping exits:
ping -c 1 DESTINATION
To ping xyz.com just once, for example, you will type:
ping -c 1 xyz.com
Option 2: How to choose a source interface.
The ping command’s default action is to deliver ICMP packages over the default path. If your computer has several interfaces, you can use the -I option to define the source interface:
ping -I INTERFACE_NAME DESTINATION
Using em2 as a source interface, run the following command to ping xyz.com:
ping -I eth0 monovm.com
Option 3: How to Specify the Internet Protocol
Depending on your machine’s DNS settings, the ping command can use either IPv4 or IPv6. If you’re using IPv6, use the -6 option or ping6:
ping -6 DESTINATION
Pass the -4 alternative to use IPv4, or use its alias ping4:
ping -4 DESTINATION
Option 4: How to Timeout Ping?
Use the -w alternative to interrupt pinging after a certain amount of time.
ping -w 5 www.xyz.com
After 5 seconds, the pinging will cease.
Option 5: How to PING Flooding
It is used to send packets as quickly as possible. This is used to evaluate the efficiency of a network.
ping -f www.xyz.com
Option 5: How to Filling Data Packet
Using the -p alternative, we can fill the packet with data. -p ff, for example, -p ff would fill the packet with ones.
ping -c 5 -p ff www.xyz.com
Option 6: How to Adjust the Time Frame in Ping
By default, ping waits 1 second before sending the next packet; however, the -i alternative can adjust this time.
ping -i 4 www.xyz.com
More Linux Ping Command Options
Ping Option | The output of the Command |
a | It will give a sound when a peer can be reached. |
b | It will allow you to ping broadcast IP addresses. |
B | Prevents the ping to change the source address of the probe. |
c (count) | It will limit you to send the number of ping requests. |
d | It will set the SO-DEBUG option on the used socket. |
f | This will Flood by sending hundreds of packets per second over a network. |
i (interval) | This will inform you that how many successful packets have been transmitted into the specified time interval. By default value = 1 Second |
I (interface address) | I will help you st set your source IP address to a specified interface IP address. It is required while pinging IPv6 link-local address. For this, use an IP address or name of the device. |
l (preload) | I will define the number of packets you can send without waiting for a response. You can specify the value higher than 3 and by giving yourself superuser permissions. |
n | This will display IP addresses as output rather than hostnames. |
q | This will show you quiet output that will ping line displayed and summary of the ping command at the end. |
T (TTL) | It will Set Time To Live. |
v | It will give verbose output. |
V | It will show the ping version and exit to a new command prompt line. |
w (deadline) | Before you exist a ping command, it will specify the time limit, regardless of how many packets have been sent or received. |
W (timeout) | It determines the time in seconds for which you need to wait for a response. |
Conclusion
Ping uses ICMP to send an ICMP echo message to the designated host, and then an ICMP returns a message if that host is open. Ping is usually calculated in milliseconds, and it comes pre-installed on any modern operating system. Ping is a network command-line interface for checking a host’s IP-level reliability on a server.
This article helped you to understand the concept of ping command in Linux, how to. ping in Linux and how to use the Linux ping command. If you have any more commands associated with Ping commands, please suggest them via the comment box listed below.
Источник