10 useful commands when debugging network issues in Linux
It’s difficult to find a Linux computer which is not connected to a network. So whenever we are connected to a network we may come across various difficulties and issues. In order to debug these issues, there are several network commands which we can use. From this article, my goal is to show you guys a few commands which we can use to debug these network issues.
1) ping(Packet Internet Groper)
ping command is used to check if the networked device is reachable. When a ping command is issued, an echo-request packet is sent to the address specified. When the remote host receives the echo request, it responds with an echo reply packet. With the ping command, we can use the URL or the IP address. There are several flags which can be used with ping. For the demo, I will use -c flag with 5 to only send 5 requests.
2) telnet(Teletype Network)
telnet command is used to check whether a port is opened. Issuing the telnet command telnet [domainname or ip] [port] will allow you to test connectivity to a remote host on the given port.
3) netstat(Network Statistics)
netstat command delivers basic statistics on all network activities and informs users on which ports and addresses the corresponding connections (TCP, UDP) are running and which ports are open for tasks. There are several flags in netstat which we can use to easily find the relative information. First, we need to install net-tools package in order to use the netstat command. net-tools can be installed as follows.
$ sudo apt-get update
$ sudo apt-get install net-tools
For the demo, I will use -lt flag to list only the listening TCP connections.
4) ifconfig(Interface Configuration)
ifconfig command is used to report the IPv4 and IPv6 addresses, subnets, and default gateways for all network adapters on your system. You can also assign an IP address, enable and disable network interface with this command. In the demo, I have shown the report which I got from my pc. If you want to list only one required network adapter you may type ifconfig followed by the specific interface.
5) traceroute
traceroute command can show the path a packet of information takes from the command issued computer to one you specify. It will list all the routers it passes through until it reaches its destination. Before you use this command, you need to install the traceroute package. To install the package we can use the following commands.
$ sudo apt-get update
$ sudo apt-get install traceroute
Afterwards, you can use the command as shown in the demo.
As you can see here, you can see how the data packet reached www.facebook.com.
6) route
route command can be used to show/manipulate the IP routing table. You can also setup static routes to specific host or networks via an interface. In the demo, I have used route command. It shows the kernel routing entities. To add new entities to this route table you can use route add command.
7) arp(Address Resolution Protocol)
This is a very useful command when you need to find the IP to mac address mapping. In the demo, I have listed all my IP address-mac address table.
8) dig(Domain Information Groper)
dig command is used for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information. There are some query options we can use. With the dig command, we need to provide a URL. Then the command will give us all the information according to the options we pass. For the demo, I will use the dig command with a URL.
9) nslookup(Name Server Lookup)
nslookup is used to find out the corresponding IP address or domain name system(DNS) record by using the hostname. In the demo, I have done a DNS lookup and a reverse DNS lookup by using the IP address.
10) nmap(Network Map)
nmap command can be used to scan for open ports in hosts and services. After executing this command it will take some time to get information about the open ports in hosts and services. Once you enter the relevant command you can press the enter key on your keyboard to see the status of the scanning process. In the following demo, I have used nmap to the www.google.com URL to see it’s open ports.
Cheers and see you guys with another writeup like this 🍻