When facing a Linux problem, the method is always the same: check the
service, read the logs, test the network, control the resources. These four
steps rule out the simplest causes before you look further. This guide gives
you the essential reflexes to diagnose a problem in a structured way. It
assumes you know how to open a terminal and run a command with sudo.
What you will learn
- Apply a 4-step diagnostic method
- Check the state of a service with
systemctland read its logs - Diagnose a basic network problem
- Spot a lack of disk space or memory
- Adopt the right reflexes when facing an incident
The 4-step method
When something does not work, always follow this order:
- Check the service: is it started? has it crashed?
- Read the logs: what do the journals say?
- Test the network: is the machine reachable? is the port listening?
- Control the resources: is there disk space and memory left?
Step 1, check the service
You start with the service because it is the cheapest hypothesis to rule out: one command, one answer. Two questions come in order: is the service you suspect running? And if you do not know which one to blame, are other services failing on the machine? Until this step is closed, testing the network or the resources means hunting for a failure that may not exist.
Is the service running?
systemctl status is the first command to type because it answers two
questions at once: the state of the unit, and the last journal lines
attached to it. In the output, the Active: line carries the decisive
information. Also look at the Main PID: line. If this process number changes
every time you rerun the command, the service is in a restart loop, which
points to a configuration error rather than to a service that is simply
stopped.
systemctl status nginxThree possible results:
| State | Meaning | Action |
|---|---|---|
active (running) | The process is running | The problem is elsewhere (network, configuration…) |
inactive (dead) | The service is stopped | Start it: sudo systemctl start nginx |
failed | The service crashed | Read the logs (step 2) |
active (running) only proves that the process is running, not that the
service answers its clients. That is why the next three steps exist: an active
service can still be unreachable or in error.
List all the failed services
When you do not know which service to blame, this command gives the full list
of units in the failed state on the machine, without querying them one by
one. It is especially useful after a reboot: a service that fails at boot
shows no message on screen, it just goes into failure silently.
systemctl --failedIf a service you expect appears here, it is your main lead. An empty list does
not clear systemd for all that: a service configured with Restart=always
that keeps crashing goes back through the activating state between two
attempts and may not appear here at the exact moment you run the command. If
the crashes follow each other very quickly, systemd may eventually give up and
put the service in failed.
Step 2, read the logs
The service failed: the journals say why, and they are the only source that does. Four angles follow each other here, from the most targeted to the broadest: the last lines of the service at fault, the recent errors of the whole machine when the culprit is not identified, live following while you restart, and finally reading the common messages, which tell you where to look for the fix.
The last lines of the service
-u nginx restricts the journal to this unit, -n 30 shows only the last 30
entries. Thirty lines are almost always enough, because the cause of a
start-up failure appears just before the Failed to start message. So read
from the bottom up: the last line says the service failed, the one you want is
two or three lines above.
journalctl -u nginx -n 30Recent errors across the whole system
This command is for when the problem goes beyond a single service, typically a
disk in error or a lack of memory that brings down several daemons at once.
-p err filters on the syslog priority, and -b limits it to the current
boot so that you do not dig up incidents from three weeks ago.
journalctl -p err -bThis shows only the errors and the more severe levels of the current boot.
-p filtering works by threshold and not by equality: -p err (priority 3)
also selects crit, alert and emerg, whose numbers are lower.
Follow the logs live
Open a dedicated terminal while you attempt a restart:
journalctl -u nginx -fThen in another terminal:
sudo systemctl restart nginxYou will see the error message appear live.
Examples of common messages
These five messages often come up in a service's start-up failures. Their
value is that they tell you where to look, not what to fix.
Address already in use points to ss -tlnp to identify the process already
holding the port. Permission denied points to the permissions of the file
involved, but also to SELinux or AppArmor on a distribution that
enables them: a file in 644 readable by everyone can still be refused if its
security context is wrong.
| Message in the logs | Meaning |
|---|---|
Address already in use | The port is already taken by another process |
Permission denied | The service lacks the necessary permissions |
No such file or directory | A configuration file or a binary is missing |
Failed to parse | Syntax error in the configuration |
Connection refused | No service is listening on this port, or a firewall explicitly refuses the connection |
Step 3, test the network
The service runs and its journals are clean, but the client gets nothing: the failure lies in between. The 4 checks below go from the lowest to the highest layer, connectivity, name resolution, listening port, then access from outside. Each one rules out a layer, and the first one that fails shows where to fix.
Does the machine have a connection?
You test an IP address and not a domain name, to separate two failures
that produce the same symptom: a routing fault and a DNS resolution fault.
-c 4 stops ping after four packets instead of letting it run forever.
ping -c 4 8.8.8.8If it works, basic connectivity is fine. No answer proves nothing on its own:
many corporate networks block ICMP outbound. In that case, test opening a
TCP connection instead with curl -sS -m 5 https://deb.debian.org before
concluding that the network is down.
Does DNS work?
ping -c 4 google.comIf ping 8.8.8.8 works but not ping google.com, the problem is DNS. Check
/etc/resolv.conf.
Is the service's port listening?
ss lists the open sockets: -t for TCP, -l for listening sockets only,
-n to keep port numbers instead of translating them into service names, and
-p to show the owning process. The latter only shows the program name if you
are root; otherwise the column stays empty for other users' processes.
ss -tlnp | grep :80If there is no result, the service is not listening on this port. Go back to
step 1. Also look at the listening address shown left of the port:
127.0.0.1:80 means the service only accepts local connections, while
0.0.0.0:80 or *:80 accepts those coming from the network. It is a classic
cause of "it works locally but not remotely", and it is fixed in the service's
configuration, not in the firewall.
From another machine, is the port reachable?
curl -I http://192.168.1.10If the service listens locally (ss confirms it) but cannot be reached from
outside, a firewall is probably blocking the traffic. The tool depends on
the distribution: ufw on Ubuntu, when it is enabled, and firewalld on RHEL.
Debian enables no firewall by default: the block then more likely comes from an
upstream firewall, the hosting provider's or the network's.
sudo ufw statussudo ufw allow 80/tcpsudo firewall-cmd --list-allsudo firewall-cmd --add-port=80/tcp --permanentsudo firewall-cmd --reloadWith firewalld, --permanent writes the rule to the configuration without
applying it to the running session: --reload is what makes it active. Without
that reload, the port stays closed even though the command displayed no error.
Step 4, control the resources
This is the step people skip and regret. A full disk or exhausted memory makes operations fail that have no apparent link with storage or RAM, and the error messages then talk about the service, never about the resource. The 3 checks that follow take less than a minute and close this hypothesis for good.
Disk space
df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 50G 47G 3.0G 94% /A file system at 100% prevents writing logs and temporary files, and can block services.
Memory
The column to ignore in this output is free. Linux systematically uses idle
memory as a disk cache, counted in buff/cache: a healthy machine
therefore almost always shows a very low free, and it is not a sign of
saturation. The column to read is available, which estimates what a new
application could get, reclaimable cache included.
free -h total used free shared buff/cache availableMem: 3.8Gi 2.1Gi 200Mi 50Mi 1.5Gi 1.4GiSwap: 2.0Gi 500Mi 1.5Gi- available shows the memory really available to applications.
- If
availableis close to zero and swap is heavily used, the machine lacks RAM.
The processes that consume the most
top refreshes its list every three seconds by default, which lets you tell a
durably greedy process from a passing spike. One detail traps the reading
of CPU percentages: on a multi-core machine, %CPU can exceed 100, a value of
400 meaning that a process uses the equivalent of four full cores.
topIn top, press M to sort by memory, or P to sort by CPU. Press
q to quit.
Summary: the troubleshooting checklist
These eight commands run in order, without skipping any, even when you think you know the cause. The point of this sequence is that it rules out hypotheses instead of confirming one: after step 4, if everything is green, you know the failure is neither a stopped service, nor a closed port, nor an exhausted resource, which refocuses the search on the application configuration or on a remote component. For a more specific failure, two guides extend this method: Linux diagnostic method and Troubleshoot a Linux service that will not start with systemd.
| Step | Command | What you check |
|---|---|---|
| 1 | systemctl status service | Is the service active? |
| 1 | systemctl --failed | Are there failed services? |
| 2 | journalctl -u service -n 30 | What do the service's logs say? |
| 2 | journalctl -p err -b | Are there system errors? |
| 3 | ping -c 4 8.8.8.8 | Does network connectivity work? |
| 3 | ss -tlnp | grep :port | Is the service's port open? |
| 4 | df -h | Is the disk full? |
| 4 | free -h | Is there enough memory? |
Troubleshooting
This table matches six common symptoms with the
corresponding checks. Read it from left to right: the symptom is what you are
told, the check is what you type, the solution only comes afterwards. Beware
of the No space left on device line: the journalctl --vacuum-time=3d
command permanently deletes the journals older than three days, which can
erase the trace of the very incident you are trying to understand. Read the
logs before purging.
| Symptom | Check | Solution |
|---|---|---|
| The website does not respond | systemctl status nginx + ss -tlnp | grep :80 | Read the service logs (step 2), fix the cause, then start the service or open the port in the firewall |
| Cannot connect over SSH | systemctl status sshd (ssh on Debian and Ubuntu) + ss -tlnp | grep :22 | Start the SSH service and check the firewall |
| The server is very slow | top + free -h + df -h | Identify the greedy process, free disk space |
| A service restarts in a loop | journalctl -u service -f | Read the error message and fix the configuration |
| "No space left on device" error | df -h | Delete files or old logs: sudo journalctl --vacuum-time=3d |
| The network works by IP but not by name | cat /etc/resolv.conf | Add a valid DNS server (e.g. nameserver 8.8.8.8) |
Key points
- Always follow the order: service → logs → network → resources.
systemctl statusandjournalctl -uare the basic diagnostic pair.- Test the network by IP first, then by domain name to isolate a DNS problem.
- A full disk is a frequent and sometimes invisible cause of failures.
- Change nothing before identifying the cause: diagnose first, fix afterwards.
Knowledge check
Check that the essentials of this guide stuck. The questions cover only what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Operate a Linux server: the complete path
A new full quiz with random questions
Work again only on the questions you missed