IT Troubleshooting CLI & Log Analysis
When a server goes down or an app stops responding, guessing wastes time. Follow a repeatable read-only triage loop first: gather evidence from network, system resources, and logs before touching anything.
1 Network Connectivity Triage
Work from your machine outward: Local IP โ Gateway/Internet โ Route โ DNS โ HTTP App โ Listening Ports.
ip a
Linux (Windows: ipconfig /all)
UP and actually has an IP address.169.254.x.x = DHCP failed, not an internet outage.ping -c 4 1.1.1.1
Linux/macOS (Win: ping -n 4 1.1.1.1)
ping 1.1.1.1 works but ping google.com fails = DNS is broken.traceroute 8.8.8.8
Linux/macOS (Windows: tracert 8.8.8.8)
dig shekharit.com +short
Linux/macOS (Win: nslookup shekharit.com)
dig @8.8.8.8 domain.com.curl -v https://example.com
Cross-platform (Linux / macOS / Win11)
-I fetches headers only; -v reveals where the handshake stalls.ss -tulpn
Linux (Windows: netstat -ano)
0.0.0.0 or only 127.0.0.1?"2 System Resource Triage
When a server is slow or crashing, check the four resource pillars in order: CPU, RAM, Disk, and Port Conflicts.
htop
Fallback: top (always installed)
wa (I/O wait) means the CPU is idle waiting on a slow disk.free -h
Linux (-h = human-readable)
available column, not free (Linux uses free RAM for disk cache).Swap usage = server is thrashing and will feel frozen.df -h
Disk Free (all mounted filesystems)
/ or /var partition stops databases, logs, and SSH logins from working.df -i to check inodes.du -sh * | sort -h
Disk Usage (run inside target folder)
/var/log firstโrunaway logs are the #1 culprit.iostat -xz 1 5
Package: sysstat
%util and await (ms per I/O).%util near 100% = storage bottleneck, not a CPU problem.sudo lsof -i :80
List Open Files / Network Sockets
:80 for :443, :3000, or :5432 to check any app port.3 Log Analysis Quick Commands
Logs tell you why something crashed instead of just that it crashed. Use these four commands to cut straight to errors.
journalctl -p err -b
systemd Linux (Ubuntu, RHEL, Debian)
-p err filters out noisy info messages; -b limits output to this boot.journalctl -u nginx -f.tail -f /var/log/syslog
RHEL/Alma/Rocky: /var/log/messages
tail -n 100 /var/log/syslog to see the last 100 lines immediately.grep -i error /var/log/syslog
Case-insensitive pattern search
-i ignores letter case. Add -C 3 to print 3 lines of context before and after each match.grep -iE "error|fail|fatal" file.log.dmesg -T | tail -n 30
Kernel Ring Buffer
dmesg -T | grep -i "killed process" proves the OOM killer struck.Quick-Copy Triage One-Liners
journalctl -u nginx --since "15 minutes ago" --no-pager
grep -iE "error|crit|oom" /var/log/syslog | tail -n 25
4 Outage Symptom โ Cause โ First Command
Match the symptom reported by users to the most likely root cause and the exact first command to run.
| Symptom | Likely Cause | First Command to Run |
|---|---|---|
| Website down | Web service crashed, bad config reload, or upstream proxy returning 502/503. | curl -I http://localhost & journalctl -u nginx -n 30 |
| No Internet | Missing default gateway, DHCP failure, or broken DNS resolver. | ping -c 4 1.1.1.1 (then dig google.com) |
| Disk 100% full | Runaway log file, unrotated container logs, or large temp/backup file. | df -h then du -sh /var/log/* | sort -h |
| Address already in use | Another daemon or stale worker process is already bound to that port. | sudo lsof -i :80 (or ss -tulpn | grep :80) |
| Connection refused | Target service is stopped, listening only on 127.0.0.1, or wrong port. |
ss -tulpn & systemctl status <service> |
5 The Danger Zone (What NOT To Do)
A blind reboot wipes volatile evidence: active network sockets, in-memory process states, and dmesg/tmpfs clues disappearโand the problem often comes right back.
journalctl -p err -b and df -h before any reboot.kill -9 on databases (PostgreSQL, MySQL, Redis)
kill -9 (SIGKILL) terminates a process instantly without flushing buffers or closing write-ahead logs, risking table corruption and slow crash recovery.
systemctl stop postgresql or kill -15 <PID> (SIGTERM) first so it shuts down cleanly.rm while the app is still writing
If a service holds an open file descriptor to app.log, rm app.log removes the filename, but the disk space stays locked at 100% until you restart the service.
: > /var/log/app.log (or truncate -s 0 /var/log/app.log) to free disk space immediately.