How to Send a Ping to a Network Host in Linux



Linux


In this article, we show how to send a special packet (ping) to a network host in linux.

Doing this is one way of examining and monitoring a network.

By sending a ping to a network, we can examine the performance and operation of a network.

The most basic network command is ping.

The ping command sends a special network packet called an ICMP ECHO_REQUEST to a specified host. Most network devices receiving this packet will reply to it, allowing the network connection to be verified.

So sending a ping is a way for a system administrator to see if s/he is able to to reach a network.

So to send a ping to youtube, youtube.com, the code to do so is shown below.



The reason we specify -c3 is because if you don't specify this, the ping command will send almost countless pings. So to prevent this, we just specify a count of 3. This will ensure whether we're able to successfully communicate with this network.

After this is done, the shell will tell you how packets were transmitted and how many packets were received. It will also tell you if there was any packet loss and the time it took to send then pings.

This is shown below.

Sending a ping to a network host

You can see the pings we sent to the site, youtube.com.

And then you can see the statistics below.

We can see that 3 packets were transmitted and 3 packets were received. There was a 0% packet loss. And it took 2002ms (or 2.002 seconds) to send and receive responses for the pings.

We can also see the IP address for the website we are trying to connect with. In the case of youtube, the IP address is 172.217.10.14

An alternative way to the code above is to simply send the following code below.



This code excludes the -c3 (3 pings to send).

This code will send many more pings, but we can stop the sending of pings at any time by pressing Ctrl+C.

After pressing Ctrl+C, this interrupts the sending of more pings. And ping, at this point, will print out performance statistics.

A properly performign network will exhibit zero percent packet loss and will indicate the elements of the network (its interface cards, cabling, routing, and gateways).

Also realize that it is possible to configure most network devices (including Linux hosts) to ignore these special packets that are sent by the ping command. This is usually done for security purposes, to obscure a host from a potential attacker. Firewalls may also be configured to block ICMP traffic.




Related Resources

How to Randomly Select From or Shuffle a List in Python



HTML Comment Box is loading comments...