Home » Cyber Security » 10 Best Troubleshooting Commands to Use in Linux

10 Best Troubleshooting Commands to Use in Linux

troubleshooting commands in linux

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.

1. ifconfig

In 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 eth0

To assign an IP address to an interface:

sudo ifconfig eth0 192.168.120.5 netmask 255.255.255.0

The 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-tools

On Fedora, CentOS, and other RPM-based distros:

yum install net-tools

On Arch Linux:

sudo pacman -S net-tools

2. ping

The 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. hostname

The 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.

hostname

4. host

The 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 IPv6

For 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. netstat

netstat 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.

troubleshooting commands, netstat

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 -at

To display all active UDP connections, use the following command:

netstat -au

To display all active connections with their program names, use the following command:

netstat -ap

To 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. curl

curl is a command-line tool for transferring data over the internet using various protocols such as DICTFILEFTPFTPSGOPHERHTTPHTTPSIMAPIMAPSLDAPLDAPSMQTTPOP3POP3SRTMPRTMPSRTSPSCPSFTPSMBSMBSSMTPSMTPSTELNET 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.txt

To follow HTTP redirects and display detailed information about the request and response, use the following command:

curl -vL http://example.com

To send data in the request body using the HTTP POST method, use the following command:

curl -d "name=John&age=30" http://example.com/form

To add a custom HTTP header to the request, use the following command:

curl -H "Authorization: Bearer TOKEN" http://example.com/api

To specify the HTTP method to be used for the request, use the following command:

curl -X DELETE http://example.com/resource/123

These 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. arp

The 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:

arp

8. traceroute

The 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.8

This 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. dig

The 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:

  1. Querying the A record for a domain name:
dig example.com A
  1. Querying the MX record for a domain name:
dig example.com MX
  1. Querying a specific DNS server for a domain name:
dig example.com @8.8.8.8
  1. Querying a domain name and displaying only the IP addresses:
dig example.com +short

10. fdisk

The 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:

  1. To list all the available disks: fdisk -l
  2. To 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.
  3. 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.
  4. To display the partition table of a disk: sudo fdisk -l /dev/sda

Note: 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 2023

The Best Penetration Testing Tools for Linux

3 Way to Copy and Paste Text in Linux Terminal

How to Install Blackarch Linux From Scratch – Comprehensive Tutorial

Leave a Reply