Open In App
Related Articles

Network configuration and trouble shooting commands in Linux

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Computers are often connected to each other on a network. They send requests to each other in the form of packets that travel from the host to the destination. Linux provides various commands from network configuration and troubleshooting. 

Here is the list of important commands: 

Using Ping (Packet Internet Groper) Command for Network configuration and troubleshooting


The ping command is used to ensure that a computer can communicate with a specified device over the network. The pings command sends Internet Control Message Protocol (ICMP) Echo Request messages in the form of packets to the destination computer and waits in order to get the response back. Once the packets are received by the destined computer, it starts sending the packets back. This command keeps executing until it is interrupted. 

ping command provides details such as 

  • the number of packets transmitted.
  • the number of packets received.
  • time is taken by the packet to return.

ping command is generally used for the following purposes:

  • measuring the time taken by the packets to return to determine the speed of the connection.
  • to make sure that the network connection between the host and the destined computer can be established.
ping google.com

ping google.com

ping an IP

ping an IP

Using nslookup Command for Network configuration and troubleshooting


nslookup command queries the DNS in order to fetch the IP address or the domain name from DNS records. 

nslookup facebook.com

nslookup facebook.com

Using traceroute Command for Network configuration and troubleshooting


This command is used to get the route of a packet. In other words, the traceroute command is used to determine the path along which a packet travels. It also returns the number of hops taken by the packet to reach the destination. This command prints to the console a list of hosts through which the packet travels in order to the destination. 

traceroute www.google.com

Using host Command for Network configuration and troubleshooting


host command is used to find a domain name associated with the IP address or find an IP address associated with the domain name. The returned IP address is either IPv4 or IPv6. 

host google.com

host google.com

host 31.13.78.35

host 31.13.78.35

Using netstat Command for Network configuration and troubleshooting


netstat (Network Statistics) is the command that is used to display routing tables, connection information, the status of ports, etc. This command works with Linux Network Subsystem. This command basically displays the content of /proc/net file defined in the Linux file system. 

netstat

netstat

netstat -r

netstat -r

Using Arp Command for Network configuration and troubleshooting


ARP (Address Resolution Protocol) command is used to display and modify ARP cache, which contains the mapping of IP address to MAC address. The system’s TCP/IP stack uses ARP in order to determine the MAC address associated with an IP address. 

arp

arp

arp -e

arp -e

Using ifconfig Command for Network configuration and troubleshooting


ifconfig(Interface Configuration) is a utility in an operating system that is used to set or display the IP address and netmask of a network interface. It also provides commands to enable or disable an interface. Many UNIX-like operating systems initialize their network interfaces using ifconfig at boot time. ifconfig is also used to view the MTU(Maximum transmission unit). 

ifconfig

ifconfig

Using Dig Command for Network configuration and troubleshooting

It is called domain information groper; it is a tool used to find query information related to domain name and troubleshoot DNS issue in Linux. This tool can provide various types of DNS records, such as CNAME, MX records and records etc. 
 For example: If we want to query a record for “google.com”
 syntax:

dig A google.com
dig A google.com

dig A google.com

This will show the IP address associated with the domain name.

Using Route Command for Network configuration and troubleshooting

This tool helps us display and manipulate the routing table in Linux. Information contained by this is about how network packets should be routed through a network.
Syntax:

route
route

route

This command shows destination, mask, flags, metric, gateway, reference count, and interface. We can also add or delete routes from a network with IP address.
For example: If we have “IP address: 192.168.90.0” and “Subnet mask = 24” and “gateway (gw) = 10.0.0.1”
syntax:

route add -net 192.168.90.0/24 gw 10.0.0.1

Using Ethtool Command for Network configuration and troubleshooting

This tool is used to view and modify the settings of a network interface card (NIC) in Linux. It has replaced the old tool named mii-tool. This command can be used to view the current speed and duplex setting of the NIC. To view the settings for the NIC named “enp0s3” use the following command.
Syntax:

enthool enp0s3

You can find your NIC name by using “ifconfig” command.

Ethtool

Ethtool

Using Hostname Command for Network configuration and troubleshooting

This command is used to display the current hostname of the system.

Hostname

Hostname

We can also change our host name by using commands.

syntax:

hostnamectl set-hostname mypc

This will set the hostname to “mypc” and display it after reboot also.

Conclusion

Computer networks are essential for communication and data transfer between devices and in Linux we get various commands to configure and troubleshoot network-related issues. Commands that we have mentioned in the article are ping, nslookup, traceroute, host, netstat, ARP, Dig, Route, Ethtool, Hostname and ifconfig. With these commands one can fix network problems by diagnosing them.



Last Updated : 05 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads