Linux
10+ Network Commands in Linux for Troubleshooting [2025]
Let’s Learn Network Commands in Linux with Practical Examples :
Computers use networks to communicate and share information with other resources. A computer network comprises two or more computers connected through different devices to complete the connectivity. It is the task of a System Administrator to set up and maintain the several functions within the network. We are going to look at 10 commonly used Network Commands in Linux for both network configuration and troubleshooting.
1. IFCONFIG (interface configurator)
Ifconfig is a Network Commands in Linux used to check network interface configurations. The common application of this command is to check the IP address assigned to the system. You can also use this command to enable or disable a network interface. This single command also gives in details the Hardware or MAC address and the MTU –maximum transmission unit.
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  | 
						#root@bree:~# ifconfig enp0s25   Link encap:Ethernet  HWaddr b4:99:ba:e8:34:f4             inet addr:192.168.0.14  Bcast:192.168.0.255  Mask:255.255.255.0           inet6 addr: fe80::841e:7eb0:9fea:6905/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:4666 errors:0 dropped:0 overruns:0 frame:0           TX packets:2337 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            RX bytes:6806722 (6.8 MB)  TX bytes:185805 (185.8 KB)           Interrupt:20 Memory:97400000-97420000  lo        Link encap:Local Loopback             inet addr:127.0.0.1  Mask:255.0.0.0           inet6 addr: ::1/128 Scope:Host           UP LOOPBACK RUNNING  MTU:65536  Metric:1           RX packets:73 errors:0 dropped:0 overruns:0 frame:0           TX packets:73 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1            RX bytes:9314 (9.3 KB)  TX bytes:9314 (9.3 KB)  | 
					
In the example above the IP address (inet addr) is: 192.168.0.14, the MAC address (HWaddr) is: 0b4:99:ba:e8:34:f4
The ifconfig takes several options, using the ifconfig option will give the status of the interface whether it is enabled or disabled. For example.
| 
					 1 2 3 4 5 6 7 8 9 10  | 
						# root@bree:~# ifconfig enp0s25 enp0s25   Link encap:Ethernet  HWaddr b4:99:ba:e8:34:f4             inet addr:192.168.0.14  Bcast:192.168.0.255  Mask:255.255.255.0           inet6 addr: fe80::841e:7eb0:9fea:6905/64 Scope:Link           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1           RX packets:4707 errors:0 dropped:0 overruns:0 frame:0           TX packets:2343 errors:0 dropped:0 overruns:0 carrier:0           collisions:0 txqueuelen:1000            RX bytes:6810415 (6.8 MB)  TX bytes:186587 (186.5 KB)           Interrupt:20 Memory:97400000-97420000   | 
					
Other uses of the ifconfig command are as follows:
Assigning IP Address and netmask
For example,
| 
					 1  | 
						# ifconfig eth0 192.168.0.19 netmask 255.255.255.0  | 
					
Enabling or disabling a network interface
Enabling a network interface:
| 
					 1  | 
						 # ifup eth0  | 
					
Disabling a network interface:
| 
					 1  | 
						# ifdown eth0  | 
					
Please note that eth0 can be replaced by the interface name assigned to your machine, in my case it is enp0s25
Setting the MTU size (the default value of MTU is 1,500)
| 
					 1  | 
						# ifconfig eth0 mtu XXXX  | 
					
Where xxx is the numerical value assigned
Finally, to set the network interface to receive all packet and check later you set it in promiscuous mode as follows:
| 
					 1  | 
						# ifconfig eth0 - promisc  | 
					
The above command requires superuser privileges.
2. PING (Packet Internet Groper Command) Command
The best way to analyze network connectivity between two communication interfaces. PING works in any network setup whether it is a LAN or WAN. The protocol used by PING is called the ICMP (Internet Control Message Protocol) to send between nodes.
| 
					 1 2 3 4 5  | 
						# ping 192.68.0.1 PING 192.68.0.1 (192.68.0.1) 56(84) bytes of data. 64 bytes from 192.68.0.1: icmp_seq=1 ttl=44 time=203 ms 64 bytes from 192.68.0.1: icmp_seq=2 ttl=44 time=201 ms 64 bytes from 192.68.0.1: icmp_seq=3 ttl=44 time=201 ms  | 
					
OR using a host name
| 
					 1 2 3 4 5  | 
						# ping www.zuku.com PING zuku.com (197.237.254.182) 56(84) bytes of data. 64 bytes from 197.237.254.182: icmp_seq=1 ttl=47 time=284 ms 64 bytes from 197.237.254.182: icmp_seq=2 ttl=47 time=287 ms 64 bytes from 197.237.254.182: icmp_seq=3 ttl=47 time=285 ms  | 
					
When executed in Linux, PING command will not stop until you issue the interrupt command using the –c option. Using a number N will issue an interrupt after N PINGs.
| 
					 1 2 3 4 5 6 7 8  | 
						# ping –c 3 www.zuku.com PING zuku.com (197.237.254.182) 56(84) bytes of data. 64 bytes from 197.237.254.182: icmp_seq=1 ttl=47 time=284 ms 64 bytes from 197.237.254.182: icmp_seq=2 ttl=47 time=287 ms 64 bytes from 197.237.254.182: icmp_seq=3 ttl=47 time=285 ms --- zuku.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 4295ms rtt min/avg/max/mdev = 285.062/285.324/285.406/0.599 ms  | 
					
3. TRACEROUTE
Traceroute is used to trace the network path by showing the number of hops taken to reach its destination. This example shows the path taken by the global DNS Server IP Address tracing its path and destination.
| 
					 1 2 3 4 5 6 7 8 9 10 11 12  | 
						# traceroute 4.2.2.2 traceroute to 4.2.2.2 (4.2.2.2), 30 hops max, 60 byte packets 1  192.168.50.1 (192.168.50.1)  0.217 ms  0.624 ms  0.133 ms 2  227.18.106.27.mysipl.com (27.106.18.227)  2.343 ms  1.910 ms  1.799 ms 3  221-231-119-111.mysipl.com (111.119.231.221)  4.334 ms  4.001 ms  5.619 ms 4  10.0.0.5 (10.0.0.5)  5.386 ms  6.490 ms  6.224 ms 5  gi0-0-0.dgw1.bom2.pacific.net.in (203.123.129.25)  7.798 ms  7.614 ms  7.378 ms 6  115.113.165.49.static-mumbai.vsnl.net.in (115.113.165.49)  10.852 ms  5.389 ms  4.322 ms 7  ix-0-100.tcore1.MLV-Mumbai.as6453.net (180.87.38.5)  5.836 ms  5.590 ms  5.503 ms 8  if-9-5.tcore1.WYN-Marseille.as6453.net (80.231.217.17)  216.909 ms  198.864 ms  201.737 ms 9  if-2-2.tcore2.WYN-Marseille.as6453.net (80.231.217.2)  203.305 ms  203.141 ms  202.888 ms 10  if-5-2.tcore1.WV6-Madrid.as6453.net (80.231.200.6)  200.552 ms  202.463 ms  202.222 ms  | 
					
4. NETSTAT (Network Statistics)
Display information on the connection and routing table. Displaying the routing table data add the –r option.
| 
					 1 2 3 4 5 6 7 8 9 10  | 
						#netstat Active Connections   Proto  Local Address          Foreign Address        State   TCP    127.0.0.1:49863        activate:49864         ESTABLISHED   TCP    127.0.0.1:49864        activate:49863         ESTABLISHED   TCP    127.0.0.1:49873        activate:49874         ESTABLISHED   TCP    192.168.0.14:54423     mba01s08-in-f2:https   ESTABLISHED   TCP    192.168.0.14:54648     mba01s08-in-f14:https  ESTABLISHED   TCP    192.168.0.14:54652     192.0.76.3:https       TIME_WAIT   TCP    192.168.0.14:54653     ec2-54-86-213-171:https  TIME_WAIT  | 
					
Using the –r Option
| 
					 1 2 3 4 5 6  | 
						# netstat -r Kernel IP routing table Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface 192.168.0.19    *               255.255.255.0   U         0 0          0 eth0 link-local      *               255.255.0.0     U         0 0          0 eth0 default         192.168.0.19    0.0.0.0         UG        0 0          0 eth0  | 
					
5. DIG (Domain Information Groper)
This command will query for DNS related data such as the A Record, MX record, CNMAE, etc.
| 
					 1 2 3 4  | 
						# dig www.woodvale.com; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> www.woodvale.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<  | 
					
6. NSLOOKUP
Is also another command used to query the DNS. This example queries the domain name server.
| 
					 1 2 3 4 5 6 7 8  | 
						# nslookup woodvale.com Server:         197.237.254.182 Address:        197.237.254.182#53  Non-authoritative answer: Name: woodvale.com Address: 162.159.243.243 Name: woodvale.com Address: 162.159.244.243  | 
					
7. ROUTE
This command is used to show the IP routing table. Using it will give you the default routing table.
| 
					 1 2 3 4 5  | 
						root@bree:~# route Kernel IP routing table Destination     Gateway         Genmask         Flags Metric Ref    Use Iface default         192.168.0.1     0.0.0.0         UG    100    0        0 enp0s25 192.168.0.0     *               255.255.255.0   U     100    0        0 enp0s25  | 
					
The command can also add, delete, and set the default gateway as follows:
Adding Routes
| 
					 1  | 
						# route add -net 10.10.10.0/24 gw 192.168.0.1  | 
					
Deleting Routes
| 
					 1  | 
						# route del -net 10.10.10.0/24 gw 192.168.0.1  | 
					
Setting the default gateway
| 
					 1  | 
						# route add default gw 192.168.0.1  | 
					
8. HOST
The host command is used to find the name of associated to a particular IP address or an IP associated to a specific IP. The HOST command searches in the IPv4 or IPv6 and the DNS records.
| 
					 1 2 3  | 
						root@bree:~# host bassanga.co.ke bassanga.co.ke has address 192.185.160.175 bassanga.co.ke mail is handled by 0 mail.bassanga.co.ke  | 
					
9. ARP (Address Resolution Protocol)
System administrators use this command to view or add the contents of a kernel to the ARP table. The default table is viewed by using it in the following format using the –e option
| 
					 1 2 3  | 
						#arp -e Address                  HWtype  HWaddress           Flags Mask            Iface 192.168.50.1             ether   00:50:56:c0:00:08   C                     eth0  | 
					
10. ETHTOOL
This command was known by the name mii-tool and later on changed to ethtool. The command is used to view Ethernet adapter settings. For example, to view adapter settings for eth0, run
| 
					 1  | 
						# ethtool eth0  | 
					
Settings for eth0:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  | 
						 ethtool eth0 Settings for eth0:         Supported ports: [ ]         Supported link modes:   Not reported         Supported pause frame use: No         Supports auto-negotiation: No         Supported FEC modes: Not reported         Advertised link modes:  Not reported         Advertised pause frame use: No         Advertised auto-negotiation: No         Advertised FEC modes: Not reported         Speed: Unknown!         Duplex: Unknown! (255)         Port: Other         PHYAD: 0         Transceiver: internal         Auto-negotiation: off         Link detected: yes  | 
					
To display device driver run
| 
					 1  | 
						ethtool  -i eth0  | 
					
Sample output
| 
					 1 2 3 4 5 6 7 8 9 10  | 
						driver: virtio_net version: 1.0.0 firmware-version: expansion-rom-version: bus-info: 0000:00:03.0 supports-statistics: no supports-test: no supports-eeprom-access: no supports-register-dump: no supports-priv-flags: no  | 
					
The above Network Commands in Linux should be able to help you troubleshoot your network issues by gathering network information and diagnose an impending problem. This article is meant for use on a day to day for Linux Network Administrator or anyone used to the Linux operating system.
																	
																															- 
																	
										
																			DevOps6 years agoSaltstack Tutorial for beginners [2025]
 - 
																	
										
																			DevOps6 years agoHow to build a Docker cron job Container easily [2025]
 - 
																	
										
																			Linux6 years agomail Command in Linux/Unix with 10+ Examples [2025]
 - 
																	
										
																			DevOps6 years agoDocker ADD vs COPY vs VOLUME – [2025]
 - 
																	
										
																			DevOps6 years agoHow to setup Pritunl VPN on AWS to Access Servers
 - 
																	
										
																			Linux6 years agoGrep Command In Unix/Linux with 25+ Examples [2025]
 - 
																	
										
																			Linux6 years agoFind command in Unix/Linux with 30+ Examples [2025]
 - 
																Linux5 years ago
How To setup Django with Postgres, Nginx, and Gunicorn on Ubuntu 20.04
 

1 Comment