Hi everyone. When the internet suddenly stops working, the question is always the same: is it my computer, the router, or the internet connection itself? Instead of guessing, there is one simple command that helps you find out: ping. It works a bit like calling out to someone, “hey, are you there?”, and waiting to see whether they answer and how long it takes.
In this guide I test a connection step by step, from the router to the internet to a domain name. I also trigger the two errors you are most likely to run into, so you will know what they mean when you see them yourself.
Distro : Ubuntu 26.04.1 LTS (Desktop)
Gateway : 10.0.2.2How the ping Command Works
Every time you run ping, your computer sends a tiny packet to the target and waits for a reply. If a reply comes back, the two devices can reach each other. If nothing comes back, something along the way is broken.
One thing to know right away: on Linux, ping does not stop on its own the way it does on Windows after four replies. It keeps going until you stop it.
Run ping and stop it with Ctrl+C

ping google.comEach 64 bytes from line (number 1) is one reply from Google. time=17.9 ms is how long the round trip took, and lower is faster. Since ping keeps running, I pressed Ctrl+C (number 2). A summary appears, showing 0% packet loss (number 3), so no packets went missing.
Note: If ping seems to run forever and you are not sure how to stop it, just press Ctrl+C. It is not an error. That is simply how ping behaves on Linux.
Test Your Connection Step by Step
The most useful way to troubleshoot with ping is to work outward from the closest point. First the router, then the internet, then a domain name. That way you can pinpoint exactly where the connection breaks.
To make ping stop by itself, I added -c, short for count, followed by the number of packets to send. No more Ctrl+C needed.
Step 1: ping the router (gateway)

You can find your router or gateway address with ip r, which I explain in the guide on checking your IP address with the ip command. On my machine it is 10.0.2.2.
ping -c 4 10.0.2.2All four packets got a reply (number 1), each under 1 ms because the router is right next door. The summary shows 4 transmitted, 4 received, 0% packet loss (number 2). The link between the computer and the router is fine.
Step 2: ping the internet by IP

Next, check whether the computer can get out to the internet. I used 8.8.8.8, a Google DNS server that is almost always up.
ping -c 4 8.8.8.8Replies came back in about 17 to 23 ms (number 1), slower than the router because the server is much farther away. The rtt line (number 2) shows the fastest, average, and slowest times. An average of 19 ms is very good. If this step works, your internet connection is actually fine.
My experience: Why ping an IP before a domain name? If pinging the IP works but pinging a name fails, the internet is not the problem. DNS is. This one trick saves a lot of time when troubleshooting.
Reading the Errors You Will Run Into
ping is not only useful when it succeeds. Its error messages are often the clearest clue about what is wrong.
These are the two errors I see most. I triggered both on purpose so you can see exactly what they look like.
Name or service not known

ping -c 2 mamangdigital-lab.invalidYou get Name or service not known (number 1). The computer could not turn that name into an IP address. Either the domain is misspelled or DNS is not working. If pinging 8.8.8.8 works but every domain name gives this error, DNS is almost certainly the culprit.
Destination Host Unreachable

Now I pinged 10.0.2.99, an address no device on my network is using.
ping -c 3 10.0.2.99Every packet comes back as Destination Host Unreachable (number 1). There is no device at that address, or it is switched off. The summary shows 0 received and 100% packet loss (number 2), so not a single packet got an answer.
Common Problems and How to Fix Them
You can usually diagnose the problem straight from your ping results. The trick is to compare the router, an internet IP, and a domain name.
If all three work but a website still will not open, the problem is probably the browser or the website itself.
ping to the router fails
The problem is local. Check the cable or WiFi, then make sure the computer has an IP address with ip a.
The router works, 8.8.8.8 fails
You are connected to the router, but the router cannot reach the internet. Restart the router or contact your internet provider.
8.8.8.8 works, domain names fail
The internet is up, but DNS is broken. Try switching your DNS to 1.1.1.1 or 8.8.8.8.
A server never replies to ping
Not every server answers ping. Many block it on purpose for security, so no reply does not always mean the server is down.
That is how to use ping on Linux to test a network connection. Remember the order, router, then an internet IP, then a domain name, and you will know exactly where things break. Once the connection works, you can also download files from the terminal with wget and curl. If you get ping results that do not make sense, share them in the comments.












