ping Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The Ping command is a utility in Linux used to test the connectivity between two network devices. It works by sending an ICMP (Internet Control Message Protocol) echo request to the target device and waiting for a response. This article will explain how to use the Ping command in Linux, its syntax, options, and some examples of its usage.
Linux ping Command Syntax
The syntax for the ping command is as follows:
ping Command Options:
- -c or --count: This option is used to specify the number of packets to send. For example, -c 5 will send five packets to the destination.
- -i or --interval: This option is used to specify the interval in seconds between each packet. For example, -i 2 will wait for two seconds before sending the next packet.
- -t or --ttl: This option is used to specify the time-to-live value for the packets. This value specifies how many network hops the packets are allowed to make before being discarded. For example, -t 64 will set the time-to-live value to 64.
- -s or --size: This option is used to specify the size of the packets in bytes. For example, -s 100 will send packets of 100 bytes each.
Example Usages
-
Sending a single packet to a destination.:
Output:
Explanation: This command will send a single ICMP echo request packet to the Google website and wait for a response.
-
Sending multiple packets to a destination.:
Output:
Explanation: This command will send five ICMP echo request packets to the Google website and wait for a response. The output will show the statistics of the ping test, including the number of packets transmitted and received, and the round-trip time for each packet.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
-
The Ping command works by sending ICMP packets, which may be blocked by firewalls or routers.
-
The output of the Ping command shows the round-trip time for each packet, which can be used to diagnose network problems.
-
The time-to-live value specifies the maximum number of network hops that the packets can make before being discarded.
Advanced Use Cases of ping Command in Linux
-
Pinging a specific port.:
Output:
Explanation: This command will send an ICMP echo request packet to the Google website on port 80, which is the standard port for HTTP traffic. The output shows that the packet was not received, which indicates that the port is not open.
-
Limiting the number of hops.:
Output:
Explanation: This command will limit the number of network hops to two, which means that the ICMP echo request packet will be discarded if it reaches a third hop. The output shows that the packets were not received and were discarded because they exceeded the time-to-live value.
-
Setting the packet size.:
Output:
Explanation: This command will send ICMP echo request packets to the Google website, with a size of 500 bytes each. The output shows that the packets were received successfully, and the round-trip time for each packet.
Turn Learning into Career Growth
Conclusion
-
The Ping command is a useful utility in Linux for testing network connectivity.
-
It works by sending ICMP echo request packets to a target device and waiting for a response.
-
The output of the Ping command shows the round-trip time for each packet and other statistics.
-
The Ping command can be used to diagnose network problems, such as packet loss, high latency, and blocked ports.