Networking is the most crucial thing which Linux handles. Linux provides a wide variety of Networking commands for network configuration and diagnosis. In this article we will see the top 10 Linux networking commands for beginners with some easy to understand examples, so let’s get started.

1.Ifconfig

The ifconfig tool is used to configure different network interfaces(eg: WLAN, ethernet) parameters. It also gives current network interface configurations such as IP-address, broadcast address, netmask etc.

root@FossNow:~$ ifconfig
enp3s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
 ether 60:eb:69:1e:98:54 txqueuelen 1000 (Ethernet)
 RX packets 0 bytes 0 (0.0 B)
 RX errors 0 dropped 0 overruns 0 frame 0
 TX packets 0 bytes 0 (0.0 B)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
 inet 127.0.0.1 netmask 255.0.0.0
 inet6 ::1 prefixlen 128 scopeid 0x10<host>
 loop txqueuelen 1000 (Local Loopback)
 RX packets 5548 bytes 466935 (466.9 KB)
 RX errors 0 dropped 0 overruns 0 frame 0
 TX packets 5548 bytes 466935 (466.9 KB)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlo1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
 ether 70:f3:95:3a:cb:a5 txqueuelen 1000 (Ethernet)
 RX packets 0 bytes 0 (0.0 B)
 RX errors 0 dropped 0 overruns 0 frame 16
 TX packets 0 bytes 0 (0.0 B)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
 device interrupt 16

wlx944452f274e2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
 inet 192.168.0.9 netmask 255.255.255.0 broadcast 192.168.0.255
 inet6 fe80::2d2:534:8e05:9f74 prefixlen 64 scopeid 0x20<link>
 ether 94:44:52:f2:74:e2 txqueuelen 1000 (Ethernet)
 RX packets 34806 bytes 30091462 (30.0 MB)
 RX errors 0 dropped 10000 overruns 0 frame 0
 TX packets 30860 bytes 4636223 (4.6 MB)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

SImply typing ifconfig on the terminal will display all the network interfaces and their configuration, now what if you want to see a particular network interface only, for that you can simply pass an extra command line argument along with “ifconfig” specifying the interface name.

root@FossNow:~$ ifconfig wlo1
wlo1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 70:f3:95:3a:cb:a5 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 16
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16

We can also activate or deactivate a network interface by using up or down along with the network interface name.

root@FossNow:~$ ifconfig wlo1 up
root@FossNow:~$ ifconfig wlo1 down

2.Traceroute

The internet is a complex forest of different network hardware connected to each other. traceroute utility helps you track the route of your transmitted packet to reach the network host.

Traceroute syntax:-

traceroute [ -46dFITnreAUDV ] [ -f first_ttl ] [ -g gate,... ] [ -i device ]
[ -m max_ttl ] [ -N squeries ] [ -p port ] [ -t tos ] [ -l flow_label ]
[ -w MAX,HERE,NEAR ] [ -q nqueries ] [ -s src_addr ] [ -z sendwait ]
[ --fwmark=num ] host [ packetlen ]

You can get the description on each of the above argument using the following command.

root@FossNow:~$ traceroute --help

Traceroute only has one mandatory parameter either the hostname or the IP-address. Traceroute for google.com is shown below.

root@FossNow:~$ traceroute google.com
traceroute to google.com (216.58.196.78), 30 hops max, 60 byte packets
 1 gateway (192.168.0.1) 3.637 ms 5.846 ms 5.826 ms
 2 * * *
 3 * * *
 4 172.16.16.22 (172.16.16.22) 52.353 ms * *
 5 72.14.196.137 (72.14.196.137) 17.689 ms 20.419 ms 22.678 ms
 6 * * *
 7 * * *
 8 kul01s09-in-f78.1e100.net (216.58.196.78) 14.995 ms 14.977 ms 5.848 ms

3.Ping(Packet Internet Groper)

The ping tool is used to test connectivity between two network nodes.Ping takes a hostname or an IP-address as a mandatory parameter.

root@FossNow:~$ ping fossnow.com

Linux will keep on sending the packets until you interrupt the process, you can specify the number of packets by passing a parameter specifying the number of packets.

root@FossNow:~$ ping -c 5 fossnow.com

4.Netstat(Network Statistics)

Netstat tool is mainly used to monitor both incoming and outgoing connections from your machine. It is mainly used in network debugging telling you which ports are open and which program is listening to which port.

Netstat -r (to see routing tables)

root@FossNow:~$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 wlx944452f274e2
link-local 0.0.0.0 255.255.0.0 U 0 0 0 wlx944452f274e2
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 wlx944452f274e2

Netstat -at(to see active TCP connections)

root@FossNow:~$ netstat -at

5.DIG(Domain Information Groper)

DIG is used to query DNS related information such as CNAME, MX RECORD etc. This tool is mainly used to diagnose DNS related queries.

root@FossNow:~$ dig fossnow.com

You can cut short the “A” Record by using the +short parameter

root@FossNow:~$ dig fossnow.com +short

Querying MX RECORD.

root@FossNow:~$ dig fossnow.com MX

6.NSLOOKUP

Nslookup utility is similar to dig as it is also a DNS query tool which helps in finding the IP-address(A record) of a particular hostname and information related to DNS such as MX Record, Name Servers, Reverse Domain lookup etc.

Let’s see some of the NSLOOKUP examples for finding:

A Record

root@FossNow:~$ nslookup fossnow.com

MX Record

root@FossNow:~$ nslookup -query=mx fossnow.com

Namer Servers of a particular Domain Name

root@FossNow:~$ nslookup -query=ns fossnow.com

The only difference between nslookup and dig is that nslookup does not use the operating system’s local Domain Name System resolver library to perform its queries.

7.ROUTE

ROUTE command displays and helps in configuring IP routing tables, to see the default routing tables you can execute the following command on the terminal.

root@FossNow:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 600 0 0 wlx944452f274e2
link-local 0.0.0.0 255.255.0.0 U 1000 0 0 wlx944452f274e2
192.168.0.0 0.0.0.0 255.255.255.0 U 600 0 0 wlx944452f274e2

8.ARP(Address Resolution Protocol)

ARP deals with the resolution of IP-address between computers on a network, let’s see a brief introduction of ARP.

Working of ARP.

Suppose you have a computer and you want it to connect with your smartphone and both are connected to your local network, you can simply test the connection by pinging your smartphone as soon as you ping your smartphone you are kicking off the need for address resolution. ARP is like a handshake process between the two of the devices.

The ARP compare the address and subnet masks of the host and the target if these matches then the address has been resolved on to your local network.

Your computer contains an ARP cache which is accessed first and used to resolve the address, if the cache does not contain the information to resolve the address then a request is sent to every machine on your local network, if any machine contains the IP-address which is being searched then the information regarding that machine is stored in the ARP cache.

Example Based on ARP

Let us try the above example. Open your terminal and type the following command.

root@FossNow:~$ arp
Address HWtype HWaddress Flags Mask Iface
gateway ether 74:da:da:c6:64:00 C wly956452f274e2

the above commands shows the current ARP cache stored on your computer, now you need to find the local IP of your smartphone for that you need to install Termux(for Android) application on your smartphone after the application is installed open it and use the ifconfig command to find the local IP-address under the wlan0 interface the local IP will be similar to something link 192.168.XX.XX, where X is some number. Now on your computer ping the local IP of your smartphone.

root@FossNow:~$ ping -c 5 192.168.0.4

Note your Local IP-address can be different from the one shown above, type the “arp” command on your computer to see the updated ARP cache.

root@FossNow:~$ arp
Address HWtype HWaddress Flags Mask Iface
gateway ether 74:da:da:c6:64:00 C wlx944452f274e2
192.168.0.4 ether 84:10:0d:53:22:3d C wlx944452f274e2

As you can see that our Phones Local IP has been added to the ARP cache for address resolution, now whenever we will try to connect again with our phone the system will use the ARP cache for address resolution.

9.HOST

Host is a DNS lookup utility, which is normally used to convert names to IP-address and IP-address to names.

root@FossNow:~$ host www.google.com
www.google.com has address 216.58.199.164
www.google.com has IPv6 address 2404:6800:4009:80a::2004

10.HOSTNAME

Hostname tool is used to find the hostname of your machine, you can change your hostname by changing the content of the following file /etc/hostname.

root@FossNow:~$ hostname
fossnow.com

If You Love
this article, You Should Consider:

  • Like us on Facebook
  • Follow us on Instagram
  • Follow us on Twitter
  • Let us know your suggestions and queries in the comments below.
  • Subscribe to our Newsletter

Thank you for your Love and Support