10 Linux Network Commands and How to Use Them

0

Linux, like other advanced operating systems, supports communication over the network. In Linux, all settings are stored in accessible files. In this way, some files can be edited and necessary settings can be made easily. You can easily manage the commands used for network and DNS settings from the command screen.

In this article, you will find information on the most used basic network commands in Linux and how to change DNS settings.

1. For network connection and IP configuration: ifconfig

The ifconfig command allows you to examine and modify the network connection and IP configuration settings available in the system.

ifconfig

First, you see the eth0 information. eth0 is the part that displays information about your ethernet card. If other ethernet cards were connected to the system, they would have names such as eth1 and eth2, respectively.

hey represents the computer itself, i.e. localhost.

If you are using a wireless network environment, you may also see the wlan0 information. wlan0 means the wireless network card.

Instead of using the ifconfig command in this way, you can list the information you want one by one. For example, if you want to list only Ethernet card information, ifconfig eth0 the command will suffice.

 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

For example, you saw above that eth0’s local IP address is 10.0.2.15. To change this IP address to 10.0.2.13:

sudo ifconfig eth0 10.0.2.13 

With ifconfig, you can modify the information here, as well as adjust any information maps you encounter in the output. ifconfig map_name down the command can remove the desired map from the display, you can display this map again with ifconfig map_name up the command.

sudo ifconfig lo down

As can be seen from the output, the down parameter made the lo map invisible now.

sudo ifconfig lo up

2. A kind of control mechanism: ping

The ping command checks if communication is established between the target and your system. For example, you can query the communication speed between you and Google.

ping google.com

By doing this, I terminated this process with the Ctrl + C combination after the 5th query package. If you use a command like a ping -c 4 google.com, you only send 4 request packets. The process will terminate once the number of request packets is exhausted.

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 the IP routing table: route

The route command allows you to view the contents of the IP routing table on your system. You can type the route -n command in the console for this.

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

The gateway address here is the forwarding address used when switching from the local network to the Internet network.

4. Transfer trace for a specific target: traceroute

With Traceroute, your command tells you which hosts the packet sent to a specific destination passed through. This time, consider the target address www.makeuseof.com 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 directed to the desired address, you must first make a request to the address 10.0.2.1. You can use the traceroute command to see these routing paths and to understand any routing issues that occur on the network.

5. For domain information: whois

The whois query contains information such as the date of establishment of the domain, its validity period, etc. Let’s use google.com as an example of a whois query.

whois google.com            
Domain Name: GOOGLE.COM
Registry Domain ID: 2138514_DOMAIN_COM-VRSN
Registrar WHOIS Server: whois.markmonitor.com
Registrar URL: http:
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:
Domain Status: clientTransferProhibited https:
Domain Status: clientUpdateProhibited https:
Domain Status: serverDeleteProhibited https:
Domain Status: serverTransferProhibited https:
Domain Status: serverUpdateProhibited https:
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:

Also, you can avoid having to use the command screen by using the best websites to look up whois information for free.

6. Get target address information: host

The host command allows you to get information about the destination address. With the host command, you can access the domain name from the IP address and the IP address from the domain name.

7. To consult the DNS records: dig

The dig (domain information groper) command is a common Linux network command used to look up 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

Also, you can examine NS (Nameserver) records with the dig command. You can use the -t NS the command for it.

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 matches: arp

The arp command displays the tables in which IP-MAC address mappings are kept.

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. For connections made by the system: tcpdump

The tcpdump command allows you to instantly view the connections made by your system and the connections established with your system.


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)

Also, if you want to follow links directly without address resolution, you can use the tcpdump -n ordered.


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 Settings

Compared to other operating systems, DNS settings in Linux are quite easy. To do this, you can make some changes to the etc/resolv.conf file in which DNS information is stored.


nameserver 192.168.1.1

If you want to add a new DNS here, you can use the echo ordered.


# echo nameserver 8.8.4.4 >> etc/resolv.conf

After making these additions, when browsing the etc/resolv.conf file again, you will see that the desired changes have been made.

 
nameserver 8.8.8.8
nameserver 8.8.4.4

Inside of /etc/ folder, there is another file called hosts which acts as a domain name server. This file is checked when resolving the domain name in the system.


127.0.0.1 localhost
127.0.1.1 kali
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Network management is easier with Linux commands

Linux is one of the most widely used operating systems. Knowing the correct commands used in Linux will be very beneficial in terms of time and effort. When configuring your Linux network and finding problems that may occur on the network, you can use Linux network commands.


Linux Network Troubleshooting Commands

The 9 Best Linux Network Troubleshooting Commands

Read more


About the Author

Share.

Comments are closed.