Troubleshooting in Linux System

From monitoring processes with top to checking firewall rules with iptables, mastering these commands can significantly streamline troubleshooting tasks.

Linux is known for its robustness and reliability, but even the most well-maintained systems occasionally encounter performance and network issues. Mastering essential troubleshooting commands is invaluable for diagnosing and fixing these problems efficiently.

In this post, i will explain 10 fundamental Linux commands that can help you identify and resolve issues related to system performance, network connectivity, and process management.

Each of these commands provides essential insights into different aspects of Linux system performance and functionality. From monitoring processes with top to checking firewall rules with iptables, mastering these commands can significantly streamline troubleshooting tasks. Familiarize yourself with these tools to gain more control over your Linux environment and resolve issues efficiently.

1. top: Monitor System Performance

The top command provides a real-time view of system resource usage, showing active processes and their CPU and memory consumption.

 top

  1. Type top and press Enter.

  2. Look at the columns to identify processes that are consuming high CPU or memory.

  3. Press P to sort by CPU usage, or M to sort by memory usage.

  • Tip: Press q to exit.

2. dmesg: Check Kernel Messages

The dmesg command displays system messages from the kernel, which can be useful for diagnosing hardware and startup issues.

dmesg | tail

  1. Type dmesg to see all kernel messages or use dmesg | tail to view the latest entries.

  2. To filter messages, use dmesg | grep [keyword].

  • Example: dmesg | grep error will show recent errors.

3. ping: Test Network Connectivity

The ping command checks if your system can reach another system over the network by sending data packets.

ping [destination IP/hostname]

  1. Type ping google.com to check if you have internet connectivity.

  2. Review the response time to assess latency.

  3. Use Ctrl+C to stop the ping test.

  • Note: If packets are dropped, it may indicate network issues.

4. traceroute: Analyze Network Path

traceroute helps you trace the path taken by data packets to reach a destination, allowing you to identify network bottlenecks.

 traceroute [destination]

  1. Run traceroute google.com to see each hop the packet takes.

  2. Review the output for any delays or timeouts.

  • Tip: Look for high latency at specific hops, which may indicate a problem.

5. netstat / ss: Network Statistics and Connections

These commands display active network connections and listening ports, which is useful for troubleshooting network-related issues.

 netstat -tuln or ss -tuln

  1. Run netstat -tuln or ss -tuln to view TCP and UDP connections.

  2. The -tuln options display active network connections and listening ports.

  • Example: ss -tuln | grep LISTEN shows only listening ports.

6. df: Disk Usage Analysis

The df command provides an overview of available disk space across mounted filesystems.

df -h

  1. Type df -h to display disk usage in a human-readable format.

  2. Identify filesystems nearing full capacity (e.g., over 80% usage).

  • Tip: Check the / (root) partition to ensure there’s enough space for system operations.

7. du: Directory Usage Insight

Use du to check how much disk space specific directories are using, which helps in locating large files or folders that may need cleanup.

du -sh [directory]

  1. Type du -sh /path/to/directory to see the size of that directory.

  2. Use du -sh * | sort -h in a directory to list and sort all files by size.

  • Example: du -sh /var/log displays the size of the system log directory.

8. ps: Process Status and Management

The ps command shows active processes and their resource consumption, allowing you to identify and manage processes.

 ps aux

  1. Run ps aux to list all processes with details on user, CPU usage, and memory.

  2. Use ps aux | grep [process_name] to find a specific process.

  • Tip: To kill an unresponsive process, use kill [PID], where PID is the process ID.

9. tail: Log File Analysis

The tail command displays the end of a file, making it ideal for monitoring real-time log entries.

 tail -f /var/log/syslog

  1. Use tail -f /var/log/syslog to view the latest system logs as they’re updated.

  2. Press Ctrl+C to stop monitoring.

  • Common Files:

  • /var/log/syslog – General system events.

  • /var/log/auth.log – Authentication and authorization logs.

10. iptables: Firewall Rule Checks

iptables displays or configures firewall rules, allowing you to see which rules may be affecting network connectivity.

 sudo iptables -L

  1. Run sudo iptables -L to list all active firewall rules.

  2. Look for rules that may be blocking or restricting access to specific ports or IPs.

  • Tip: If you make changes to rules, remember to save them (sudo iptables-save).

Familiarize yourself with these tools to gain more control over your Linux environment and resolve issues efficiently.

Reply

or to participate.