Everyone Can Learn Program
中文 Start learning
Core · NetworksLesson 5 of 6Free to read

Finding what's broken · Computer Networks

The site is down. Where do you start?

Course contents

Why 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":

  1. Does the name resolve? dig +short NAME
  2. Is the machine reachable? ping NAME
  3. Does the service answer? curl -I URL (refused → nothing listening)
  4. Is the service running? systemctl status SERVICE
  5. 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 lesson

Name 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
Step by step
  1. L1The name resolves.203.0.113.10
  2. L2The machine answers.
  3. L3Active: failed. Here's the broken layer.
  4. L4Port 443 is taken by another process.

Fix and confirm

Run it in the lesson

Stop 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
Step by step
  1. L1old-web is running as PID 1300.
  2. L2Free the port.
  3. 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?

  1. AThe DNS record for the name
  2. BThe web server's log
  3. CThe database
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-web
  1. A
    ● old-web.service - Old test server
         Loaded: loaded (/etc/systemd/system/old-web.service; disabled)
         Active: active (running)
  2. B
    ● old-web.service - Old test server
         Loaded: loaded (/etc/systemd/system/old-web.service; enabled)
         Active: active (running)
  3. C
    ● old-web.service - Old test server
         Loaded: loaded (/etc/systemd/system/old-web.service; disabled)
         Active: inactive (dead)
Show 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.

  1. PredictWhich layer?

    Run this in your head (or press Run). Which layer is broken?

  2. ModifyFix it properly

    This just restarts web, which fails again because old-web still holds port 443. Free the port first, so that web runs and the site answers. Also make sure old-web won't come back: it is already disabled, so stopping it is enough.

  3. WriteRun the checklist

    Without changing anything, run the first four checks for shop.example.com in order: resolve the name (dig +short), ping it, look at the web service'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

TermChineseDefinition
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.