howtouselinux

5 useful Linux network troubleshooting commands

Table of Contents

Here are five commands that you can use to check the network status in Linux.

ifconfig

ifconfig: This command displays information about the network interfaces on your system, including their IP addresses, netmasks, and network statistics.

Suppose that you are having trouble connecting to the internet on your Linux machine. You open a terminal and run the command ifconfig to view the status of your network interfaces. 

If the interface is not properly configured, you are unable to connect to the internet. To fix this problem, you might try the following steps:

  1. Check the physical connection to make sure that the ethernet cable is properly plugged in to both your computer and the router.
  2. Run the command ifconfig eth0 up to bring the eth0 interface up. This will enable the interface and allow it to receive and transmit data.
  3. Assign a valid IP address to the eth0 interface by running the command ifconfig eth0 [IP_ADDRESS] netmask [NETMASK]. Replace [IP_ADDRESS] with a valid IP address and [NETMASK] with the appropriate netmask for your network.
  4. Test your internet connection to see if it is working properly.

 

related: Troubleshoot network issues with ifconfig command in Linux

netstat

netstat: This command displays a variety of network-related information in Linux, including active network connections, routing tables, and network statistics.

If you are having trouble connecting to a network resource, such as a web server, you can use netstat to see if there are any active connections to that server.

To do this, you can use the -a flag to display all active connections, and the -n flag to display the connections using numerical addresses rather than hostnames. For example:

$ netstat -an | grep <server_ip_address>

This will display any active connections to the server, along with their status and protocol. If there are no active connections, or if the connections are in a state such as TIME_WAIT or CLOSED, it could indicate a problem with the connection.

This article explains more about how to check network status in Linux.

traceroute

traceroute: This command displays the route that packets take to reach a specified network host. It can be useful for troubleshooting network connectivity issues.

ping

ping: This command sends a small packet of data to a specified network host and measures the time it takes for the host to send a reply.

You can use this command to determine whether the host is reachable and to measure the round-trip time for packets sent to that host.

If you are having trouble accessing a network resource, such as a web server or a file share, you can use ping to test the connectivity between your system and the host.

To do this, you can use the ping command followed by the IP address or hostname of the target host. For example:

$ ping ip

This will send a series of ICMP echo request packets to the target host and display the results, including the round-trip time for each packet and the percentage of packets that were received.

If the host is reachable, you should see a series of replies from the host indicating that the packets were received.

If the host is not reachable, you will see a series of request timeouts indicating that the packets were not received.

If the host is not reachable, there could be a problem with the network connectivity between your system and the host.

You can use the traceroute command to see the route that packets are taking between your system and the host, which can help you identify the source of the connectivity issue.

nslookup

nslookup: This command allows you to query Domain Name System (DNS) servers to resolve domain names to IP addresses and vice versa.

You can use it to troubleshoot DNS-related issues or to find the IP address associated with a specific domain name.

Suppose that you are having trouble accessing a website on your computer. When you try to visit the website, you receive an error message saying that the domain cannot be found.

To troubleshoot this issue, you can use the nslookup command to query the DNS server and try to resolve the domain name.

To do this, open a terminal and run the command nslookup [DOMAIN_NAME], replacing [DOMAIN_NAME] with the name of the website you are trying to access.

If the domain can be resolved, nslookup will return the IP address of the website. If the domain cannot be resolved, nslookup will return an error message indicating that the domain does not exist.

Welcome to howtouselinux.com!

Our website is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative, and we welcome your feedback and suggestions for future content.

Learn More

Facebook
Twitter
LinkedIn