10 Network Commands Available in Linux and How to Make Use of Them

We independently review everything we recommend. When you buy through our links, we may earn a commission.

Network Commands Linux and Use

Do you want to learn how to adjust the settings for your network and DNS in Linux? You will be assisted by these instructions.

Communication across a network is supported by Linux, just like it is by other sophisticated operating systems. On Linux, every configuration option is saved in a file that the user may access. In this approach, some files may be modified, and it is much simpler to adjust the parameters that are required. From the command panel, you have the ability to simply handle the commands that are used for configuring the network and DNS.

You will discover information in this article on the most commonly used basic network commands in Linux as well as instructions on how to update DNS settings.

1. For Establishing a Connection to the Network and Configuring IP: ifconfig

You are able to investigate and modify the IP configuration settings in addition to the network connections that are present in the system by using the ifconfig command.

ifconfig

You start out by looking over the information regarding eth0. The information that is displayed regarding your Ethernet card may be found in the eth0 section. If there were more Ethernet cards connected to the system, each one would be given a unique name, such as eth1 or eth2 depending on the number of connections.

lo is short for “localhost,” which refers to the computer itself.

You will also be able to view the information regarding wlan0 if you are working within a wireless network environment. The wireless network card is denoted by the notation wlan0.

You do not need to use the ifconfig command in this manner; rather, you may just list the necessary information one by one. For instance, if you wish to list only the information related to the Ethernet card, you may use the command ifconfig eth0. This will be sufficient.

ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe00::000:00xx:xx00:0x00 prefixlen 64 scopeid 0x20&lt;link&gt;
ether 08:00:00:00:0x:00 txqueuelen 1000 (Ethernet)
RX packets 11 bytes 3310 (3.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 25 bytes 3050 (2.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

You observed, for instance, that the local IP address of eth0 is 10.0.2.15 in the previous section. This IP address must be changed to 10.0.2.13 as follows:

sudo ifconfig eth0 10.0.2.13

You have the ability to alter the information that is displayed here by using the ifconfig command, as well as the information cards that are displayed in the output. You can hide the desired card from display by using the ifconfig card name down command. If you want to reveal the card once again, you can use the ifconfig card name up command.

sudo ifconfig lo down

As can be seen from the output, passing in a value for the down option resulted in the lo card becoming hidden.

sudo ifconfig lo up

2. An Instrument of Command: ping

Using the ping command, you may determine whether or not communication is established between your system and the destination. For instance, you have the ability to question Google about the connection speed between you and the search engine.

ping google.com

After completing the fifth query package, I terminated this operation by pressing the Control key and the letter C simultaneously. If you run a command such as ping -c 4, for example, just four query packets will be sent to google.com. After a certain threshold has been reached for the amount of query packets, the procedure will end.

ping -c 4 google.com
PING google.com (216.58.206.174) 56(84) bytes of data.
64 bytes from sof02s27-in-f14.1e100.net (216.58.206.174): icmp_seq=1 ttl=111 time=79.0 ms
64 bytes from sof02s27-in-f14.1e100.net (216.58.206.174): icmp_seq=2 ttl=111 time=73.5 ms
64 bytes from sof02s27-in-f14.1e100.net (216.58.206.174): icmp_seq=3 ttl=111 time=72.7 ms
64 bytes from sof02s27-in-f14.1e100.net (216.58.206.174): icmp_seq=4 ttl=111 time=75.1 ms
— google.com ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3014ms
rtt min/avg/max/mdev = 72.710/75.089/79.030/2.432 ms

3. For IP Routing Table: route

The route command gives you the ability to view the contents of the IP routing table that is stored on your system. In order to accomplish this, you may type the route -n command into the terminal.

route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.1 0.0.0.0 UG 100 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

When information travels from a local network to the internet network, a forwarding address is required. This address is known as the gateway address.

4. Traceroute, Forwarding Tracking for a Particular Target

Your command can show you which hosts the packet that was delivered to a certain location has traveled through by using the Traceroute utility. This time, let’s use the destination address as an illustration as an example.

traceroute www.makeuseof.com
traceroute to www.makeuseof.com (54.157.137.27), 30 hops max, 60 byte packets
1 10.0.2.1 (10.0.2.1) 0.430 ms 0.326 ms 0.414 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
9 * * *
10 * * *
11 * * *

As you can see, in order to be routed to the address you wish, a request must first be sent to the address 10.0.2.1, which is located at the beginning of the chain. You may view these different routing pathways by using the traceroute command, which will also help you understand any routing issues that may arise inside the network.

5. For Domain Information: whois

The results of the whois inquiry include information such as when the domain was formed, how long it will be active, and other relevant details. As an illustration of a whois query, let’s use google.com as our target.

whois google.com
Domain Name: GOOGLE.COM
Registry Domain ID: 2138514_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.markmonitor.com
Registrar URL: http://www.markmonitor.com
Updated Date: 2019-09-09T15:39:04Z
Creation Date: 1997-09-15T04:00:00Z
Registry Expiry Date: 2028-09-14T04:00:00Z
Registrar: MarkMonitor Inc.
Registrar IANA ID: 292
Registrar Abuse Contact Email: abusecomplaints@markmonitor.com
Registrar Abuse Contact Phone: +1.2083895740
Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
Domain Status: serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited
Domain Status: serverTransferProhibited https://icann.org/epp#serverTransferProhibited
Domain Status: serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited
Name Server: NS1.GOOGLE.COM
Name Server: NS2.GOOGLE.COM
Name Server: NS3.GOOGLE.COM
Name Server: NS4.GOOGLE.COM
DNSSEC: unsigned
URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/

You may also avoid needing to use the command screen by using the top websites that provide a free whois lookup service.

6. Finding Out Information Regarding the Target Address: the Host

Utilizing the host command, you are able to obtain information on the destination address. You may access the domain name from the IP address using the host command, and you can also access the IP address using the domain name.

7. To Look at DNS Records: dig

dig (domain information groper) is the command to use when viewing DNS Records.

dig google.com
; <<>> DiG 9.17.21-1-Debian <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 64917
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 177 IN A 216.58.206.174
;; Query time: 3 msec
;; SERVER: 192.168.1.1#53(192.168.1.1) (UDP)
;; WHEN: Thu Apr 14 19:25:15 EDT 2022
;; MSG SIZE rcvd: 44

Additionally, you may use the dig command to investigate NS records (Nameserver records). In order to accomplish this, you may use the -t NS the command.

dig google.com -t NS
; <<>> DiG 9.17.21-1-Debian <<>> google.com -t NS
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41881
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;google.com. IN NS
;; ANSWER SECTION:
google.com. 70621 IN NS ns3.google.com.
google.com. 70621 IN NS ns2.google.com.
google.com. 70621 IN NS ns4.google.com.
google.com. 70621 IN NS ns1.google.com.
;; Query time: 3 msec
;; SERVER: 192.168.1.1#53(192.168.1.1) (UDP)
;; WHEN: Thu Apr 14 19:34:38 EDT 2022
;; MSG SIZE rcvd: 100

8. For IP-MAC Address Matchings: arp

The arp command displays the tables that are used to keep track of IP-MAC Address mappings.

arp
Address HWtype HWaddress Flags Mask Iface
10.0.2.1 ether 52:54:00:12:35:00 C eth0
10.0.2.3 ether 08:00:27:66:24:25 C eth0

9. Use tcpdump for System-created connections.

The tcpdump program gives you the ability to inspect instantaneously both the connections that your system has made and the connections that have been made to your system.

# tcpdump
tcpdump: verbose output suppressed, use -v[v]… for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
19:44:59.746452 IP 10.0.2.15.48657 &gt; homerouter.cpe.domain: 14329+ A? www.makeuseof.com. (37)
19:44:59.746574 IP 10.0.2.15.48657 &gt; homerouter.cpe.domain: 39924+ AAAA? www.makeuseof.com. (37)
19:44:59.770573 IP 10.0.2.15.44391 &gt; homerouter.cpe.domain: 44735+ A? content-signature-2.cdn.mozilla.net. (53)
19:44:59.770685 IP 10.0.2.15.44391 &gt; homerouter.cpe.domain: 31664+ AAAA? content-signature-2.cdn.mozilla.net. (53)

In addition, you may use the tcpdump -n tool in order to follow the links in a manner that does not involve address resolution if you so want.

# tcpdump -n
tcpdump: verbose output suppressed, use -v[v]… for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
19:47:41.327149 IP 10.0.2.15.43892 &gt; 192.168.1.1.53: 44991+ A? content-signature-2.cdn.mozilla.net. (53)
19:47:41.327574 IP 10.0.2.15.43892 &gt; 192.168.1.1.53: 46778+ AAAA? content-signature-2.cdn.mozilla.net. (53)
19:47:41.425041 IP 192.168.1.1.53 > 10.0.2.15.43892: 44991 5/0/0 CNAME d2nxq2uap88usk.cloudfront.net., A 18.66.248.5, A 18.66.248.40, A 18.66.248.112, A 18.66.248.105 (157)
19:47:41.425042 IP 192.168.1.1.53 > 10.0.2.15.43892: 46778 9/0/0 CNAME d2nxq2uap88usk.cloudfront.net., AAAA 2600:9000:224a:e400:a:da5e:7900:93a1, AAAA 2600:9000:224a:1c00:a:da5e:7900:93a1, AAAA 2600:9000:224a:9400:a:da5e:7900:93a1, AAAA 2600:9000:224a:8200:a:da5e:7900:93a1, AAAA 2600:9000:224a:c00:a:da5e:7900:93a1, AAAA 2600:9000:224a:8e00:a:da5e:7900:93a1, AAAA 2600:9000:224a:9a00:a:da5e:7900:93a1, AAAA 2600:9000:224a:a400:a:da5e:7900:93a1 (317)
19:47:42.470901 IP 10.0.2.15.44369 &gt; 192.168.1.1.53: 28874+ A? safebrowsing.googleapis.com. (45)

10. DNS Configuration

Linux’s Domain Name System (DNS) configuration is very straightforward in comparison to those of other operating systems. In order to accomplish this, you will need to edit the etc/resolv.conf file, which is where the DNS information is saved.

# cat etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.1.1

You may make use of the echo command if you wish to add a new DNS to this location.

# echo nameserver 8.8.8.8 > etc/resolv.conf
# echo nameserver 8.8.4.4 >> etc/resolv.conf

When you revisit the etc/resolv.conf file after making these modifications, you will notice that the desired changes have been applied to the file.

# cat etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

Another file, named hosts, may be found within the /etc folder. This file serves as a domain nameserver for the system. When conducting domain name resolution in the system, this file is inspected as part of the process.

# cat etc/hosts
127.0.0.1 localhost
127.0.1.1 kali
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Linux Commands Make Network Administration Easier

Linux is one of the operating systems that has the greatest market share. Having a solid working knowledge of the Linux commands and how they should be executed will save a lot of time and energy. You may make use of the Linux network commands in order to configure your Linux network and investigate any potential issues that may arise inside the network.

Alex
We will be happy to hear your thoughts

Leave a reply

TopBestProductReview
Logo