Jannah Theme License is not validated, Go to the theme options page to validate the license, You need a single license for each domain name.
DevOpsLinux

Ping Command Examples for Linux Users

The ping command can be used in its basic form by nearly all Linux users, so they know how to use it. Nonetheless, there are many other ping options and variations available. With the following guide, you are going to learn five of the most useful Linux ping commands.

UNIX and Linux distributions can use the commands in this article. The example and output samples below were generated using Ubuntu 18.04.2 LTS as the test system.

Requirements

  • System based on Linux or UNIX
  • A terminal is available for use
  • Running the commands requires a user with the necessary permissions

What is ping?

Network diagnostics can be performed with Ping from the Windows command prompt. Network diagnostics allows you to verify whether another computer is connected to a local or public network using a command line program.

With ping, either the IP address or the host name of the target computer is entered at the command line prompt of the same name. In case of computers on different local networks, specify the domain.

During World War II, ping was used to locate submarines by emitting pulses of sound – a process that locates objects using sonar technology. Within the submarine, the sound pulses were perceived as a light knocking, also known as a “ping.”

How ping works in Linux?

Linux ping is an easy-to-use but powerful tool that determines if a network is available and whether a host can be reached. Test the status of a server with this command. You can also use it to troubleshoot connection issues.

You can use the ping command to:

  • Connect your computer to the internet and test it.
  • Make sure the remote machine is online.
  • Check whether there are any network problems, such as dropped packages and high latency.

“Pinging” is the act of sending ICMP echo requests to a remote host and waiting for a reply. You receive an echo reply if your connection has been established.

It is displayed when a packet reaches its destination and returns in the ping command output.

Responses continue to be printed until interrupted. Ping statistics appear after each session.

How to Use the ping Command?

In basic terms, ping involves putting the hostname, the name of the website, or the exact IP address in front of the ping command.

Use [option] [hostname] or [IP address] to ping

To determine if a remote host is online, in this case, google.com, type the following command in your terminal:

Send a ping to google.com

To stop the process, press Ctrl + C on your keyboard.

  1. From: The destination’s IP address. Your IP address will be different if you are in another part of the world.
  2. Each ICMP packet has a sequence number of 1. Each subsequent echo request increases the sequence number by one.
  3. ttl=52: Value between 1 and 255 for the time to live. An IP packet can take a maximum number of network hops before a router discards it.
  4. In milliseconds, a packet takes 7.68 milliseconds to reach its destination and return. This is expressed in milliseconds.

ping Commands in Linux with Examples

Check your local network by pinging “localhost”

Ping localhost is to confirm you have a network connection if you are having difficulty reaching a website or remote machine. Check your network interface by using one of the following methods:

  1. Using ping 0 is the fastest way to ping localhost. A response is provided to you by the terminal once it has resolved the IP address.
  2. Localhost can be pinged using the name. Our command “ping this computer” refers to the name of your computer.
  3. Pinging 127.0.0.1 is a popular method for pinging localhost.

How to Limit the Number of Pings?

As a default setting for the ping command, the request is sent continuously until the command is terminated. One of two methods can be used to limit the number of pings.

Ping packet limit

Using -c and a number will make the ping command automatically stop after a certain number of packets have been sent. The number of ping requests can be set, as shown in this example:

Ping google.com with -c 2

Despite its name, ping does not send packets after two requests, as shown in the image above.

Set the time limit for pinging

To stop receiving ping output after a certain amount of time, add -w and an interval in seconds to the ping command.

Examples of Ping Commands

1. Ping the target host www.google.com to see if it can be reached. An IP address can also be used instead of a domain name.

The ping was successful and no packets were lost as a result of the above command. When performing a ping test, remember the time. Depending on the type of application running on the server, the value of ping testing varies greatly.

In general, a lower ping time indicates that more data is being sent without delay to a particular server, and the opposite applies if you have a web application producing many queries to a database (or databases).

2. The -c flag can be used to specify how many ECHO_REQUEST’s are to be sent before ping terminates (in this case, the ping test will terminate after sending five packets).

3. You can set the interval between sending packets using the -i flag. The default is one second between sending packets.

$ ping -i 3 -c 5 www.google.com

4. You can use the -f switch to perform a flood ping to check your network’s response under high-load conditions. To gain root privileges, you need to use the sudo command. This option is only available to root.

5. Using the -b command line parameter, you can ping a broadcast.

$ ping -b 192.168.43.255

6. By using the -t flag, you can limit the number of network hops that probes traverse (TTL – Time-to-live). Default values can range from 1 to 255; different operating systems set them differently.

The router subtracts 1 from the count when it receives a packet and if it is greater than 0, it forwards the packet to the next hop. If the count is less than 0, the router discards the packet and replies with an ICMP packet to your computer.

The TTL was exceeded in this example, as shown in the screenshot, causing the ping test to fail.

7. You can adjust the packet size for your specific testing requirements; however, a ping test generally uses the default packet size. If you specify a payload size of bytes with the -s option, the packet will have the specified size plus 8 bytes for the ICMP header.

8. Ping sends this many packets without waiting for a response if preload is specified. Using sudo will grant root privileges; otherwise, select more than three preloads as root.

9. With the -W option, you can also specify a time in seconds for waiting for a response.

10. You can set a timeout in seconds with the -w flag if you want ping to terminate regardless of how many packets it sends or receives.

11. You can enable debugging IP packet details using the -d option.

12. By using the -v flag, verbose output can be enabled,

Generally, pings are high-pitched, sharp tones that sound musical. If you tap a spoon against a crystal glass, you might hear a similar sound. The meaning of this is entirely different in IT.

This article explains the basics of Ping, explains how it works, and shows how it can be used to monitor networks.

Also Read: Learn to use SCP Command in Linux (with Examples)

Why Would I Use Ping?

Even if you didn’t realize it, you’ve used the ping command when performing a speed test on your computer or network. Testing the return time of a message bouncing off a remote server.

A ping can be used to troubleshoot connectivity, devices, or networks, among other things.

Troubleshooting Connectivity

Connectivity problems are resolved by pinging. You typically use this technique to check if two machines are connected. If you want to determine whether a printer or copier is offline or if you are able to connect to a router, you can use ping to test the connection. A ping command is one of the first steps you should take if you’re having trouble with an application hosted on a server over a network. Then you can narrow down the problem. You may have a problem with the server or application if your ping comes back with fast response times. 

With the ping command, you can verify that a website is operational and that the connection is functioning.

Troubleshooting Networking Issues

Pinging almost any networked device makes checking network connections incredibly valuable. The ping protocol can be used to test the throughput and speed of routers and servers. If you want to locate each attached device in a particular range of addresses, you can ping across the range. Similarly, you can test the name and address of each computer. An IP address can be pinged, but the computer name isn’t. 

It is likely that you are facing a routing, congestion, or networking issue if a ping returns a successful connection but has long response times.

For monitoring network reliability, a ping command can be run manually or automatically as a scheduled task. A failed ping indicates a problem.

Ping Error Messages

When the host does not respond to the ping command, either nothing will be returned or a timeout notification will be displayed. Due to the 4 requests, you are likely to see four time-outs.

Ping Command Switches and Modifiers

In order to troubleshoot this command, you can specify parameters or modifiers (also called switches). Below is a list of the commands and their correct syntax for Windows, although there will be minor differences for Unix.

  • /t 
  • /a –
  • /n count –
  • /l size –
  • /f – 
  • /i TTL – 
  • /v TOS – 
  • /r count – 
  • /s count – 
  • /j host-list – 
  • /k host-list –
  • /w timeout – 
  • /r range – 
  • /s 
  • /c 
  • /p – 
  • /4 – 
  • /6 –

Also Read: Steps to Unzip / Extract tar.gz Files in Linux Using Command Line

Conclusion

You now know how to use the Linux ping command. The examples in this tutorial should provide insight into how “ping” is used in the real world.

Checking the network connectivity both locally and remotely is possible with ping.

If you want a complete list of ping options, run man ping inside your terminal.

Arpit Saini

He is the Director of Cloud Operations at Serverwala and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *