Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

First troubleshooting steps on Linux

By updated

Improve this page

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 systemctl and 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:

  1. Check the service: is it started? has it crashed?
  2. Read the logs: what do the journals say?
  3. Test the network: is the machine reachable? is the port listening?
  4. 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.

Terminal window
systemctl status nginx

Three possible results:

StateMeaningAction
active (running)The process is runningThe problem is elsewhere (network, configuration…)
inactive (dead)The service is stoppedStart it: sudo systemctl start nginx
failedThe service crashedRead 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.

Terminal window
systemctl --failed

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

Terminal window
journalctl -u nginx -n 30

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

Terminal window
journalctl -p err -b

This 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:

Terminal window
journalctl -u nginx -f

Then in another terminal:

Terminal window
sudo systemctl restart nginx

You 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 logsMeaning
Address already in useThe port is already taken by another process
Permission deniedThe service lacks the necessary permissions
No such file or directoryA configuration file or a binary is missing
Failed to parseSyntax error in the configuration
Connection refusedNo 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.

Terminal window
ping -c 4 8.8.8.8

If 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?

Terminal window
ping -c 4 google.com

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

Terminal window
ss -tlnp | grep :80

If 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?

Terminal window
curl -I http://192.168.1.10

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

Terminal window
sudo ufw status
sudo ufw allow 80/tcp

With 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

Terminal window
df -h
Output (excerpt)
Filesystem 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.

Terminal window
free -h
Output
total used free shared buff/cache available
Mem: 3.8Gi 2.1Gi 200Mi 50Mi 1.5Gi 1.4Gi
Swap: 2.0Gi 500Mi 1.5Gi
  • available shows the memory really available to applications.
  • If available is 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.

Terminal window
top

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

StepCommandWhat you check
1systemctl status serviceIs the service active?
1systemctl --failedAre there failed services?
2journalctl -u service -n 30What do the service's logs say?
2journalctl -p err -bAre there system errors?
3ping -c 4 8.8.8.8Does network connectivity work?
3ss -tlnp | grep :portIs the service's port open?
4df -hIs the disk full?
4free -hIs 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.

SymptomCheckSolution
The website does not respondsystemctl status nginx + ss -tlnp | grep :80Read the service logs (step 2), fix the cause, then start the service or open the port in the firewall
Cannot connect over SSHsystemctl status sshd (ssh on Debian and Ubuntu) + ss -tlnp | grep :22Start the SSH service and check the firewall
The server is very slowtop + free -h + df -hIdentify the greedy process, free disk space
A service restarts in a loopjournalctl -u service -fRead the error message and fix the configuration
"No space left on device" errordf -hDelete files or old logs: sudo journalctl --vacuum-time=3d
The network works by IP but not by namecat /etc/resolv.confAdd a valid DNS server (e.g. nameserver 8.8.8.8)

Key points

  • Always follow the order: service → logs → network → resources.
  • systemctl status and journalctl -u are 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

6 questions
6 min
70% to pass

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