Linux-Troubleshooting-Scenarios
Introduction:
It is important to understand the issue. There should be the right approach or a step-by-step process to be followed to troubleshoot the issues. Unix./Linux is used widely and you should be aware with the issues and correct approach to resolve it. Let’s discuss on the few of them :
Linux-Troubleshooting-Scenarios
Issue 1: Server is not reachable or unable to connect
Ping the server by Hostname and IP Address
Command: ping <hostname>
Command: ping <ip_address>
Hostname/IP Address is pingable
- No specific command needed, as the server is reachable.
Hostname is not pingable but IP Address is pingable
Command: cat /etc/hosts
Command: cat /etc/resolv.conf
Command: cat /etc/nsswitch.conf
Command: cat /etc/sysconfig/network-scripts/ifcfg-<interface> (if applicable)
Hostname/IP Address both are not pingable
Check other servers on the same network.
Check network configuration and connectivity.
Logged into server by Virtual Console, check the uptime
- Command: uptime
Check if the server has the IP and has UP status of Network interface
Command: ip a or ifconfig
Command: cat /etc/sysconfig/network-scripts/ifcfg-<interface> (if applicable)
Command: ping <gateway_ip>
Command: route -n
Command: sestatus
Command: iptables -L
Issue 2: Unable to connect to website or an application
Follow the same steps as Issue 1 for checking server reachability.
Command: telnet <hostname or IP> <port>
Issue 3: Unable to ssh as root or any other user
Follow the same steps as Issue 1 for checking server reachability.
Command: telnet <hostname or IP> 22
Command: systemctl status sshd
Command: journalctl -u sshd
Issue 4: Disk Space is full issue or add/extend disk space
System Performance degradation detection
Command: top
Command: df -h
Action
Command: du -sh <directory>
Command: badblocks -v /dev/sda
Command: iostat -x 1
New disk addition (Simple partition)
Command: lsblk
Command: fdisk /dev/sdX
Command: mkfs.ext4 /dev/sdX1
Command: mount /dev/sdX1 /mnt
Command: echo "/dev/sdX1 /mnt ext4 defaults 0 0" >> /etc/fstab
New disk addition (LVM Partition)
Command: lsblk
Command: fdisk /dev/sdX
Command: pvcreate /dev/sdX1
Command: vgcreate <vg_name> /dev/sdX1
Command: lvcreate -L <size> -n <lv_name> <vg_name>
Command: mkfs.ext4 /dev/<vg_name>/<lv_name>
Command: mount /dev/<vg_name>/<lv_name> /mnt
Command: echo "/dev/<vg_name>/<lv_name> /mnt ext4 defaults 0 0" >> /etc/fstab
Extend LVM partition
Command: lsblk
Command: fdisk /dev/sdX
Command: pvcreate /dev/sdX1
Command: vgextend <vg_name> /dev/sdX1
Command: lvextend -l +100%FREE /dev/<vg_name>/<lv_name>
Command: resize2fs /dev/<vg_name>/<lv_name>
Issue 5: Filesystem corrupted
Command: cat /var/log/messages
Command: dmesg
Command: fsck /dev/sdX1
Issue 6: fstab file missing or bad entry
Command: cat /var/log/messages
Command: blkid
Command: vi /etc/fstab
Issue 7: Can’t cd to the directory even if the user has sudo privileges
Check the directory's existence.
Verify the pathname, permissions, and ownership of the parent directory.
Ensure execute permission on the target directory.
Issue 8: Can’t Create Links
Verify the existence of the target directory/file.
Use the complete path for the target.
Check permissions and ownership of the parent directory and target file.
Ensure read permission on the target file.
Issue 9: Running Out of Memory
Command: free -h
Command: top, htop, or ps
Check for OOM messages in logs and sysctl.conf for memory settings.
Kill or restart processes.
Prioritize processes using nice.
Add or extend swap space.
Add more physical RAM.
Issue 10: Add/Extend the Swap Space
Command: dd if=/dev/zero of=/swapfile bs=1M count=<size_in_MiB>
Command: chmod 600 /swapfile
Command: mkswap /swapfile
Command: swapon /swapfile
Command: echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
Issue 11: Unable to Run Certain Commands
Troubleshoot based on the specific command or script.
Check permissions, sudo configuration, paths, installation, and library availability.
Issue 12: System Unexpectedly reboot and process restart
Troubleshoot based on system reboot/crash reasons.
Check logs, system status, and custom application logs.
Reach out to the vendor if necessary.
Issue 13: Unable to get IP Address
Check IP assignment method (DHCP or Static).
Verify network settings and NIC status.
Restart the network service.
Issue 14: Backup and Restore File Permissions in Linux
Command: getfacl -R <dir> > permissions.acl
Command: setfacl --restore=permissions.acl
Please replace <hostname>, <ip_address>, <directory>, <size>, <vg_name>, <lv_name>, and <interface> with the appropriate values for your specific configuration. These commands should help you troubleshoot and resolve the mentioned Linux issues.