📡 Command: ping (Network Connectivity Test)
The ping command is the most basic tool for testing whether a specific IP address or domain name is reachable over the network. It works by sending a small packet of data (an ICMP Echo Request) to a destination and waiting for a "pong" (Echo Reply) back.
1. The "Why"
In your setup—managing a backend, developing web tools —connectivity is everything.
- Check Internet Access: Verify if your Linux system is actually online.
- Test Server Latency: See how much "lag" (delay) there is between your PC and a server.
- Troubleshoot DNS: Check if a domain name (like
google.com) is resolving to the correct IP address. - Monitor Stability: See if your connection is dropping packets during a long session.
2. Basic Syntax
ping [OPTIONS] DESTINATION
- Note: On Windows,
pingstops after 4 tries. On Linux, it will continue forever until you manually stop it!
3. How to Read the Output
When you run ping google.com, you'll see lines like this:
64 bytes from ... icmp_seq=1 ttl=115 time=42.5 ms
| Component | Meaning |
|---|---|
| 64 bytes | The size of the test packet sent. |
| icmp_seq | The sequence number (helps track missing/dropped packets). |
| ttl | Time To Live. How many "hops" (routers) the packet can pass through before being discarded. |
| time | Latency. How long it took for the round trip in milliseconds (ms). Lower is better. |
4. Practical Examples
A. Testing Your Local Router
To see if your PC is even talking to your local Wi-Fi router (usually 192.168.1.1 or 192.168.0.1):
ping 192.168.1.1
B. Limiting the Number of Pings
If you don't want to hit Ctrl+C to stop, tell it to stop after 4 packets:
ping -c 4 google.com
C. Audible Ping
A classic trick: make the terminal "beep" every time a packet successfully returns. Useful if you are under the desk plugging in cables and want to know when it's fixed:
ping -a google.com
D. Fast "Flood" Ping (Requires Sudo)
To test the extreme limits of a connection (sends packets as fast as they return):
sudo ping -f 192.168.1.1
5. Pro-Tips
- Stopping the Command: Since
pingruns forever on Linux, always remember the shortcut:Ctrl + C. Once stopped, it will show you a "Statistics" summary (min/avg/max latency and packet loss). - Packet Loss: If you see
Request timed outor a high percentage of packet loss in the summary, your connection is unstable. - Arch Linux Context: If you're setting up a new service or your connection is failing, use
pingfirst. If you can ping the IP but not the domain name, your DNS settings in/etc/resolv.confare likely the problem.
6. Summary Reference
| Goal | Command |
|---|---|
| Basic test | ping [domain or IP] |
| Stop after 5 tries | ping -c 5 [domain] |
| Check only if host is alive | ping -w 5 [domain] (Wait 5 sec) |
| Change packet interval | ping -i 0.5 [domain] (Every 0.5 sec) |