Finding what's broken · Computer Networks
The site is down. Where do you start?
Course contentsWhy you need it
"It doesn't work" can fail at any layer: the name, the network path, the port, the service, the application. Guessing wastes hours. Checking one layer at a time, from the bottom up, finds most problems in minutes and is exactly what on-call engineers do.
The intuition
Ask in order, and stop at the first "no":
- Does the name resolve?
dig +short NAME - Is the machine reachable?
ping NAME - Does the service answer?
curl -I URL(refused → nothing listening) - Is the service running?
systemctl status SERVICE - Why did it stop?
journalctl -u SERVICE
Each step rules out a whole layer, so you never restart a server for a DNS typo.
Definition
Layered troubleshooting
Testing the network stack from the bottom (names, reachability) to the top (the application), so each test narrows where the fault is.
Address already in use
A service can't listen on a port another process already holds. Find and stop the other process, or change the port.
Examples
Walk down the checklist
Run it in the lessonName and machine are fine; the service isn't answering. Its log says why.
dig +short shop.example.com
ping shop.example.com
systemctl status web
journalctl -u web- L1The name resolves.
203.0.113.10 - L2The machine answers.
- L3Active: failed. Here's the broken layer.
- L4Port 443 is taken by another process.
Fix and confirm
Run it in the lessonStop the old test server that grabbed the port, start web, and check from the outside.
ps
sudo systemctl stop old-web
sudo systemctl start web
curl -I https://shop.example.com- L1old-web is running as PID 1300.
- L2Free the port.
- L4200 OK from the outside: fixed.
HTTP/1.1 200 OK
Common mistakes
Restarting first
A restart can hide the evidence (the log of why it failed) and won't fix a DNS or port problem. Look first.
Testing only from inside
curl on the server itself can work while users can't reach it (firewall, DNS). Always confirm from where the users are.
Quick quiz
1. `dig +short shop.example.com` prints nothing. What do you check next?
Show the answer
Answer: A
The first layer failed: nobody can reach the server by name until DNS is fixed.
2. What does this print?
systemctl status old-webShow the answer
Answer: A
It's running now but disabled, so it won't come back after a reboot.
Practice
3 exercises in three steps: predict what a program prints, change a program to meet a new requirement, then write one from scratch. Your code runs in the browser and is checked the moment you submit.
- PredictWhich layer?
Run this in your head (or press Run). Which layer is broken?
- ModifyFix it properly
This just restarts
web, which fails again becauseold-webstill holds port 443. Free the port first, so thatwebruns and the site answers. Also make sureold-webwon't come back: it is already disabled, so stopping it is enough. - WriteRun the checklist
Without changing anything, run the first four checks for
shop.example.comin order: resolve the name (dig +short), ping it, look at thewebservice's status, and read its log.
Practise this lesson
Open the interactive lesson to edit and run these examples and solve the exercises with instant feedback. Free to start, no sign-up.
Interactive lessons open in order. If you have not done the earlier ones yet, you start at the course map.
Terms in this lesson
| Term | Chinese | Definition |
|---|---|---|
| Troubleshooting | 故障排查 | Finding the cause of a problem by testing one possibility at a time. |
| Connection refused | 连接被拒绝 | The machine answered, but nothing listens on that port. |