10 Best Troubleshooting Commands to Use in Linux Prakash, 26, March 202326, March 2023 Troubleshooting commands in Linux are a set of commands that can help you identify and troubleshoot any issues with your system. These commands provide detailed information about the system’s hardware, software, and configuration.They can also be used to diagnose problems with applications or services running on the system. By using these commands, you can quickly identify the source of an issue and take corrective action to resolve it.Furthermore, these commands provide a more comprehensive view of the system than other methods such as GUI-based tools or log files. With this knowledge in hand, you will be able to better understand how your system works and make informed decisions when troubleshooting problems.TABLE OF CONTENTS1 1. ifconfig2 2. ping3 3. hostname4 4. host5 5. netstat6 6. curl7 7. arp8 8. traceroute9 9. dig10 10. fdisk10.1 About The Author10.1.1 Prakash10.2 Related1. ifconfigIn Linux/Unix operating systems, the command-line utility ifconfig is used to configure interfaces. With the aid of configuration scripts, network administrators may also utilise it to query and manage interface parameters.You can use it to enable or disable a network interface and provide the chosen interface a netmask and IP address. The maximum transmission unit size for active interfaces, along with all the accessible interfaces, IP addresses, and hardware addresses, are also visible.To activate or deactivate any interface, you may utilize the up/down parameters.sudo ifconfig up eth0 sudo ifconfig down eth0To assign an IP address to an interface:sudo ifconfig eth0 192.168.120.5 netmask 255.255.255.0The availability of this utility is not immediate in Linux distributions, and you may encounter an error message saying “ifconfig: command not found”. To fix this problem, you can install the net-tools package via your distribution’s package manager.On Ubuntu/Debian:sudo apt-get install net-toolsOn Fedora, CentOS, and other RPM-based distros:yum install net-toolsOn Arch Linux:sudo pacman -S net-tools2. pingThe ping networking utility is used to determine whether or not a remote server is reachable. It is primarily used for network connectivity testing and troubleshooting.It determines whether the host is reachable or if a service is running. Using the ping command, you can also check for network connectivity issues such as high latency and package drop.To check host availability, ping sends ICMP (Internet Control Message Protocol) echo request messages and waits for ICMP echo reply packets. The output includes the total number of messages sent and received, as well as the time it takes a packet to reach its destination.ping <IP or DNS>3. hostnameThe hostname command is used to display and change the hostname of a machine. In a network, the hostname serves as a unique identifier for a particular device.To view the hostname of your device, simply execute the “hostname” command. If you wish to set a permanent hostname, you can do so by modifying the “/etc/sysconfig/network”.It’s important to note that once you’ve set a proper hostname, you’ll need to reboot your device in order for the changes to take effect.hostname4. hostThe host command is a command-line utility used to perform DNS (Domain Name System) lookups. It can be used to obtain various information about a domain name, such as its IP address, mail servers, name servers, and more. The basic syntax of the host command is as follows:host [options] domain Here, domain is the domain name you want to look up, and options are the various command-line options that can be used to modify the behavior of the host command. Some commonly used options include:-a : Display all information about the domain (same as -v -t ANY)-t type : Specify the type of DNS record to look up (e.g. A, MX, NS, etc.)-v : Verbose output mode-4 : Force a lookup using IPv4-6 : Force a lookup using IPv6For example, to perform a simple DNS lookup for the domain example.com, you can run the following command:host example.com This will display the IP address associated with the domain, along with some additional information such as the type of record and the time-to-live (TTL) value.5. netstatnetstat is a command-line utility tool that displays active network connections, routing tables, and network statistics. It is available on most Unix-based operating systems including Linux.The basic syntax of the netstat command is:netstat [options]Here are some of the most common options used with netstat:-a or --all: Displays all active connections and their status, including listening sockets.-t or --tcp: Displays all active TCP connections.-u or --udp: Displays all active UDP connections.-n or --numeric: Displays network addresses as numerical values instead of resolving hostnames.-p or --program: Displays the name of the program that is using the network connection.-r or --route: Displays the kernel’s IP routing table.Here are some examples of how to use netstat:To display all active TCP connections, use the following command:netstat -atTo display all active UDP connections, use the following command:netstat -auTo display all active connections with their program names, use the following command:netstat -apTo display the routing table, use the following command:netstat -r To display all active connections and their status, use the following command:netstat -a These are just a few examples of the many ways netstat can be used to troubleshoot network issues in Linux.6. curlcurl is a command-line tool for transferring data over the internet using various protocols such as DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP.The basic syntax of the curl command is:curl [options] [URL]Here are some of the most common options used with curl:-O or --remote-name: Downloads the file from the URL and saves it with the same name as the remote file.-L or --location: Follows HTTP redirects.-v or --verbose: Displays detailed information about the request and response.-H or --header: Adds a custom HTTP header to the request.-d or --data: Sends data in the request body using the HTTP POST method.-X or --request: Specifies the HTTP method to be used for the request.Here are example of how to use curl:To download a file from a URL, use the following command:curl -O http://example.com/file.txtTo follow HTTP redirects and display detailed information about the request and response, use the following command:curl -vL http://example.comTo send data in the request body using the HTTP POST method, use the following command:curl -d "name=John&age=30" http://example.com/formTo add a custom HTTP header to the request, use the following command:curl -H "Authorization: Bearer TOKEN" http://example.com/apiTo specify the HTTP method to be used for the request, use the following command:curl -X DELETE http://example.com/resource/123These are just a few examples of the many ways curl can be used to interact with web services and APIs from the command line in Linux.7. arpThe system ARP table is a crucial component of network communication, and the arp command is a tool used to manipulate its cache. By adding or deleting addresses, as well as displaying them, the arp command helps to maintain the accuracy of the table.The protocol used for mapping IP addresses to MAC addresses is called the Address Resolution Protocol (ARP), and this is the underlying mechanism that the arp command utilizes. This tool is one of many available in the net-tools package, and is essential for managing network connectivity.To view the contents of the table, run the command without any parameters:arp8. tracerouteThe traceroute command is a network diagnostic tool used to track the path that an Internet Protocol (IP) packet takes from one host to another. It is available on most operating systems, including Windows, Linux, and macOS.When you run the traceroute command, it sends packets with increasing time-to-live (TTL) values, starting with 1, to the target host. Each router along the path decrements the TTL value of the packet by 1 and, if the TTL value reaches 0, it sends an ICMP “Time Exceeded” message back to the source host. The traceroute command displays the IP address of the router that sent the “Time Exceeded” message, as well as the round-trip time (RTT) for the packet.By sending multiple packets with increasing TTL values, traceroute can build a map of the path that packets take from the source host to the target host. This information can be used to troubleshoot network connectivity problems, identify routing issues, and optimize network performance.Here’s an example of using traceroute command on Linux to trace the route from the local machine to the Google DNS server:traceroute 8.8.8.8This command will send packets with increasing TTL values to the IP address 8.8.8.8, and display the intermediate routers that the packets pass through. The output will show the IP address and hostname of each router, as well as the RTT for each packet.9. digThe dig command is a tool used for querying DNS (Domain Name System) servers to obtain information about DNS records. DNS is a system used to translate human-readable domain names into IP addresses that computers can understand.The dig command can be used to perform various DNS queries, such as A, AAAA, CNAME, MX, NS, SOA, PTR, TXT, and SRV queries. The syntax for using the dig command is as follows:Here are a few examples of how to use the dig command:Querying the A record for a domain name:dig example.com AQuerying the MX record for a domain name:dig example.com MXQuerying a specific DNS server for a domain name:dig example.com @8.8.8.8Querying a domain name and displaying only the IP addresses:dig example.com +short 10. fdiskThe fdisk command is a utility program used to partition hard disk drives in Linux and other Unix-like operating systems. It allows you to create, delete, and modify partitions on your hard drive.Here are some common usages of the fdisk command:To list all the available disks: fdisk -lTo create a new partition:a. Start fdisk by specifying the disk device name: sudo fdisk /dev/sdab. Press n to create a new partition.c. Follow the prompts to specify the partition type, start and end cylinder, and partition size.d. Press w to write the changes to the disk and exit.To delete a partition:a. Start fdisk by specifying the disk device name: sudo fdisk /dev/sdab. Press d to delete a partition.c. Follow the prompts to select the partition to delete.d. Press w to write the changes to the disk and exit.To display the partition table of a disk: sudo fdisk -l /dev/sdaNote: Be careful when using the fdisk command, as any mistake in partitioning can lead to data loss. Always make a backup of your important data before making any changes to the partition table.Also Read:The 5 Best Linux Terminal Emulators In 2023The Best Penetration Testing Tools for Linux3 Way to Copy and Paste Text in Linux TerminalHow to Install Blackarch Linux From Scratch – Comprehensive TutorialAbout The Author Prakash See author's posts Related Cyber Security Linux troubleshooting commands in linux
Linux Top 10 Media Server Software for Linux Users 28, June 202228, June 2022A media server is a specialized file server or computer system for storing media (digital videos/movies, audio/music, and images). It enables you to access your media files over a network. In order to set up a media server, you need computer hardware (or perhaps a cloud server) as well as… Read More
Cyber Security The Best Cybersecurity Measures Safeguard Your Digital World 5, July 20235, July 2023In an increasingly more interconnected world, cybersecurity has become a critical challenge for individuals and organizations. As the technology advances, so do the associated risks and vulnerabilities. To ensure the security and privacy of your digital assets. It is essential to implement strong cyber security measures. In this comprehensive guide,… Read More
Cyber Security Most common types of Network Security vulnerabilities 8, January 20238, January 2023Network vulnerabilities are always changing and that means businesses are at risk of losing valuable information or income. Though there are new weaknesses appearing all the time, some of the methods used by hackers remain the same. They’ll use tried-and-true methods for infiltrating a seemingly secure network, employing various tricks,… Read More