When you cannot access a website, your first instinct might be to assume your entire internet connection is down. However, network issues are rarely that simple. The problem could be isolated to your computer’s Wi-Fi card, your local router, your ISP’s DNS servers, or the specific web server you are trying to reach.
To diagnose exactly where the connection is breaking down, network engineers rely on one of the oldest and most fundamental tools in computing: the ping command. This utility sends tiny packets of data (ICMP Echo Requests) to a specific IP address or domain name and listens for a response. By analyzing how long it takes the response to return, and whether any packets were lost along the way, you can pinpoint the exact nature of the network failure.
This guide explains how to use the ping command in the Ubuntu terminal for basic network troubleshooting.
The Basic Ping Command
To test if your computer can reach the outside internet, you should ping a highly reliable server that is known to almost never go down, such as Google’s primary DNS server (8.8.8.8).
Open your Ubuntu terminal and type:
ping 8.8.8.8
By default in Linux, the ping command will run continuously forever. You will see lines of text appearing one after another, looking something like this:
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=14.2 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=13.8 ms
To stop the test and return to your command prompt, you must press Ctrl + C on your keyboard.
How to Read the Results
When you press Ctrl + C, the terminal will print a summary of the test. Here is what the data means:
- time=14.2 ms: This is your latency (or “ping time”). It took 14.2 milliseconds for the packet to travel from your computer to Google’s server and back. A number under 50ms is excellent; anything over 150ms will cause noticeable lag in online games or video calls.
- packet loss: The summary will explicitly state if any packets were lost. If you sent 10 packets and received 10 back, you have 0% packet loss, indicating a perfectly stable connection. If you have 5% or 10% packet loss, your physical connection (like a bad Wi-Fi signal or a damaged Ethernet cable) is likely failing intermittently.
- Destination Net Unreachable: If you see this error instead of a time measurement, it means your computer does not even know how to route the traffic out of your house, usually indicating your local router is offline or your Wi-Fi is disconnected.
Troubleshooting with Ping (The Step-by-Step Method)
If you have no internet access, do not just ping Google immediately. Use this systematic approach to find the exact point of failure:
- Ping “localhost” (127.0.0.1): First, type
ping 127.0.0.1. This tests your own computer’s internal network stack. If this fails, your operating system’s networking software is broken, or your network card is physically dead. - Ping your Router: Next, ping your local router’s IP address (usually
192.168.1.1or192.168.0.1). If this fails, the problem is inside your house. You need to restart your router or check your Wi-Fi connection. - Ping a Public IP (8.8.8.8): If you can reach your router, ping Google’s IP address (
ping 8.8.8.8). If this works, it means your physical internet connection to the outside world is fully functional. - Ping a Domain Name (google.com): Finally, type
ping google.com. If step 3 worked but step 4 fails with an “unknown host” error, you have isolated the problem perfectly: your internet connection is fine, but your DNS (Domain Name System) server is down.
Limiting the Number of Pings
If you do not want to manually press Ctrl + C every time you run a test, you can use the -c (count) flag to tell the command to only send a specific number of packets and then automatically stop.
ping -c 4 google.com
This command will send exactly four packets, print the summary, and immediately return you to the command prompt, exactly mirroring how the command behaves by default on Windows machines.