Open In App

Network configuration and troubleshooting commands in Linux

Last Updated : 01 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
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. 

Using Ping (Packet Internet Groper) Command

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

The 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

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

The 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

The 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

The 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

The 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

The Dig Command 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

The Route Command 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

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

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



Previous Article
Next Article

Similar Reads

Useful and time saving bash commands in Linux
There are many useful bash scripts that can make things easier. Many things can be done just using the terminal. Here is a list of some of such useful bash scripts through which we can do things that cannot be done manually. 1. Counting the number of files(or directory) in a given directory: Go to the directory in which you want to count the number
3 min read
halt, poweroff and reboot Commands in Linux
Below are typical uses of halt, poweroff and reboot. halt : Instructs hardware to stop CPU functions. poweroff : Instructs the system to power down. reboot : Restarts or reboots the system. The above mentioned commands can only be run by super user as these involve the actions to stop the system hardware. If the user is not logged in as super user
2 min read
How to run Linux Commands on Windows 10?
It is a dilemma when you want to switch from one operating system to another. This is a common case when you switch from Windows to Linux. Either you store your data and then uninstall Windows to install Linux and then transfer your data or you can have a dual boot system where you encounter an option as to which OS to choose in the beginning. Don'
2 min read
Basic Linux Commands for day to day life
This article will explore the basic Linux commands and how to use them. 1. ls: How would we know what a folder contains? With a graphical interface, you'd do this by opening a folder and inspecting its contents. From the command line, you use the command ls instead to list a folder's contents. By default, ls will use a very compact output format. M
7 min read
DDL Commands & Syntax
In this article, we will discuss the overview of DDL commands and will understand DDL commands like create, alter, truncate, drop. We will cover each command syntax with the help of an example for better understanding. Let's discuss it one by one. Overview :Data Definition Language(DDL) is a subset of SQL and a part of DBMS(Database Management Syst
3 min read
Linux Virtualization : Linux Containers (lxc)
Operating-system-level virtualization is a server virtualization method in which an operating system's kernel allows multiple isolated user-space instances, instead of just one. Such instances, which are sometimes called containers, software containers, virtualization engines (VEs), or jails (FreeBSD jail or chroot jail), may look and feel like a r
6 min read
Cuts and Network Flow
The backbone analysis of any network is broadly accomplished by using Graph Theory and its Algorithms. The performance constraints are Reliability, Delay/Throughput and the goal is to minimize cost. In the backbone designing of a network the concerned points and considerations are : What should be the backbone topology ?Assignment of Line Capacitie
4 min read
Program to determine class, Network and Host ID of an IPv4 address
Given a valid IPv4 address in the form of string and it follows Class Full addressing. The task is to determine the class of the given IPv4 address as well as separate the Network and Host ID parts from it. Examples: Input : 1.4.5.5 Output : Given IP address belongs to Class A Network ID is 1 Host ID is 4.5.5 Input : 130.45.151.154 Output : Given I
8 min read
Introduction to ANN | Set 4 (Network Architectures)
Prerequisites: Introduction to ANN | Set-1, Set-2, Set-3 An Artificial Neural Network (ANN) is an information processing paradigm that is inspired by the brain. ANNs, like people, learn by examples. An ANN is configured for a specific application, such as pattern recognition or data classification, through a learning process. Learning largely invol
5 min read
Vihaan Network Interview ( On Campus for full + Intern )
Vihaan Network came to our campus for the role of software engineers and allowed B.tech (CS, IT, ECE) M.tech (CSED All) and MCA. There are two rounds 1. Written 2. Interview Round 1: Written Test had 5 section 1. C/C++(15 questions) 2. JAVA (15 questions) 3. Data Communication & Networking Concepts(15 questions) 4. Operating System(15 questions
2 min read
Article Tags :
Practice Tags :