Linux 111: Troubleshooting and Debugging Techniques

Linux 111: Troubleshooting and Debugging Techniques

Welcome back! Even the most reliable Linux systems can run into issues — a service that won’t start, slow performance, or strange network behavior. This article introduces essential troubleshooting and debugging techniques to help you identify and resolve problems efficiently.


Start with the Basics

Begin by checking overall system health. These simple commands can give you a quick overview:

  • uptime — See how long the system has been running and load averages
  • df -h — Check available disk space
  • free -h — View memory usage
  • top or htop — Monitor running processes

Check System Logs

Logs are crucial for understanding what’s going wrong. Key tools and files include:

  • journalctl — View system logs (Systemd-based systems)
  • dmesg — Check kernel messages, useful for hardware issues
  • /var/log/ — Traditional log files like syslog, auth.log, and messages
sudo journalctl -xe
tail -f /var/log/syslog

Diagnosing Services

If a service isn’t running properly, these commands can help you troubleshoot:

sudo systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable nginx

Check related logs for deeper insight.


Debugging Network Issues

  • ping — Test connectivity
  • ip a — Display network interfaces and addresses
  • ss -tuln — View open and listening ports
  • traceroute — Trace route to a host
ping 8.8.8.8
ip a
ss -tuln

Resource and Process Debugging

Identify resource-intensive processes and manage them effectively:

top
ps aux --sort=-%mem | head
kill -9 <PID>

Use strace to trace system calls of a specific process:

strace -p <PID>

File Permission Issues

Permissions are a common source of problems. Use these commands to investigate and fix them:

ls -l
chmod +x script.sh
chown user:user file.txt

Debugging Shell Scripts

Use the -x option to run a script in debug mode:

bash -x myscript.sh

Redirect output and error messages for analysis:

./myscript.sh > output.log 2>&1

Useful Debugging Tools

  • lsof — List open files
  • tcpdump — Capture network traffic
  • gdb — GNU Debugger (for C/C++ programs)
  • perf — Performance analysis tools

Common Issues and Quick Fixes

  • System won’t boot: Use a live CD, check GRUB and /etc/fstab.
  • Package manager locked: Remove lock files in /var/lib/dpkg/lock.
  • Permission denied errors: Double-check permissions, SELinux/AppArmor contexts.

Best Practices

  • Document your troubleshooting steps
  • Make one change at a time and test
  • Keep backups of configuration files before editing

Wrapping Up

Mastering troubleshooting is about being methodical and using the right tools. Whether you’re debugging a broken script, a failing service, or a slow server, Linux provides powerful commands to guide you.

Next up: Linux 112: Linux Backup Strategies and Disaster Recovery

Post a Comment (0)
Previous Post Next Post

ads