Updated April 18, 2023
Introduction to Linux Network Command
In the Linux operating system, the network command is used to configure the network parameters, network troubleshooting, integration of various applications, port and network interface management, etc. In Linux, the network is a very important part to handle. For Linux application development and administration, network knowledge is mandatory.
[Different Network Command] [NIC] [Option] [Hostname/IP Address]
- Different Network Command: We can use different network level keyword/command in it like netstat, ifconfig, traceroute, dig, route, etc.
- NIC: We can provide the different network interface cards as an input to the network command.
- Option: We can provide the different flags as options that are compatible with the Network command.
- Hostname/IP Address: sometimes we need to provide the hostname and IP address information for configuration and troubleshooting.
How does Linux Network Command Work?
Basically, the network command is used to set up or configure network-related things in the Linux Ecosystem. It is also being useful for network or application level troubleshooting.
There are different types of network commands available in the Linux environment. Every command having different working mechanisms and troubleshooting steps. But generally, the network command accepts the option and NIC/Hostname or IP Address. Accordingly, the network command will give the output or result.
Examples to Implement Linux Network Command
Following are the examples are given below:
Example #1 – Ifstat Command
The “ifstat” command is providing the IN and OUT packet-related information of all the network interfaces associated with the Linux environment.
Explanation: As per the above command, we are able to get the packet related information of network interface. Currently, there are two interfaces is present i.e. lo (it is for loopback) and enp0s3 (it is for internet card). Whenever any packet will flow form below interfaces. The “ifstat” command will show the results accordingly.
Example #2 – Ifup and ifdown command
The Linux, the network packet will follow via interfaces. If we need to down or up the network interfaces, then we can ifup and ifdown command.
ifdown enp0s3 ifup enp0s3
Explanation: According to the above command, we are able to up and down the network interfaces in the Linux environment. In the current Linux environment, we are having the two interfaces i.e. lo and enp0s3. The network connectivity was established by enp0s3 interface. We can down the interface (refer screenshot 1 (a)) and up the interface (refer screenshot 1 (b)).
Example #3 – Ping Command
Ping command is the very command in any operating system. It is useful to check whether the machine is reachable or not.
Explanation: As per the above command, we are checking whether our machine is reachable to google.com or not. If the machine is reachable, then we are getting the relay from destination service/host/IP and we ensure the connectivity is established in between the source and destination machine.
Example #4 – Traceroute Command
The traceroute command is used for network troubleshooting. It will give detailed information on the number of hops that comes in between the source and destination. It will also provide the packet traveling path.
Explanation: As per the above command, we are able to trace out the number of hopes and the packet travel path from the source and the destination server or network. As per the traceroute command, we can troubleshoot when our server is reachable to the destination server or not. If not where is the issue?
Example #5 – Netstat Command
Netstat is one more type of network-related command and we will get different types of network-related information from it. With the help of the “-r” option, we will get the routing table information.
Explanation: As per the below output screenshot, we are able to get the routing table information of the server. It will define how the network is established in the Linux server.
Example #6 – Ethtool command
The ethtool tool is used to get the detail information of the network interface.
Explanation: In a Linux server, there are different network interfaces available in it (depends on the configuration). As per the above command, we are getting detailed information of the network interface. It will really full to design the duplex or full-duplex network topology.
Example #7 – Hostname Command
While configuration any network topology, the hostname is very important. On the Linux environment, we can identify the hostname associated with it.
Note: If we need to assign the hostname to the Linux server. We need to update the entry in “/etc/hosts” file.
Explanation: As per the above command, we are getting the hostname information of the Linux server. The hostname is very important when we are accessing any external application.
Example #8 – nmtui command
In Linux, we can graphically configure the network interfaces, active or inactive the interfaces set the hostname.
Note: The graphical interface command is varied for the Linux operating system. The below command will only work in CentOS7 or RHEL 7.
Explanation: While configuring the network interface in the Linux environment. We need to pass different commands for different tasks like assign the IP address, hostname, active the interface, etc.
But we in Linux, we can avoid it and use the graphical interface to configure the IP address, hostname, active the interface, etc.
Example #9 – Nslookup Command
The nslookup command is based on the DNS or A Record. It will provide the IP address associated with the hostname or vice versa.
Explanation: As per the above command, we are able to find the IP address of the name server from which the URL is associated (i.e. google.com).
We have seen the uncut concept of “Linux Network Command” with the proper example, explanation, and command with different outputs. The Network command is very important for troubleshooting and configuration of network-related things. While integrating with a different application, we need to take care of the network establishment things.
We hope that this EDUCBA information on “Linux Network Command” was beneficial to you. You can view EDUCBA’s recommended articles for more information.