Useful Network Configuration & Troubleshooting Commands in Cent OS.

By | April 5, 2022

1-nmtui & nmcli commands.

The Nmcli and Nmtui commands are used to configure network settings and also to manage network devices for creating, editing, and deleting the network connections in Cent OS.

[root@localhost ~]# nmtui
//The above command will open a GUI for you to edit the network connections.
[root@localhost ~]# nmcli
eno2: connected to eno2

2-ARP Table

If you want to see the current ARP table of the system then you can run the below command given below.
Note:- ARP is a part of the net-tools package so you have to install it first.

[root@localhost /]# yum install net-tools

Once it will install the net-tool package then you can see the ARP table.

[root@localhost /]# arp -a
gateway (192.168.14.117) at b6:59:f3:be:24:6a [ether] on eno2
[root@localhost /]# arp -e
Address HWtype HWaddress Flags Mask Iface
gateway ether b6:59:f3:be:24:6a C eno2
[root@localhost /]#

3-Adding Gateway in Cent OS.

[root@localhost /]#route add default gw 192.168.14.117

4-Adding and Deleting Routes.

[root@localhost /]# route add -net 192.168.1.0/24 gw 192.168.14.117

[root@localhost /]# route del -net 192.168.1.0/24 gw 192.168.14.117

5-Viewing The Routing Table.

[root@localhost /]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 eno2
192.168.14.117  0.0.0.0         255.255.255.252 U     100    0        0 eno2
[root@localhost /]#

6-Nslookup Command.

nslookup command is also used to find out DNS information.The examples are given below for showing A Record (IP Address) of google.com.At first you have to install the bind utill package and then you can see the DNS resolution information.

[root@localhost /]#dnf install bind-utils -y

[root@localhost /]#nslookup www.google.com

7-DIG Command

Dig (domain information groper) query DNS-related information like “A” Record, CNAME, MX Record, etc. This command is mainly used to troubleshoot DNS-related queries.

[root@localhost /]# dig google.com

; <<>> DiG 9.11.13-RedHat-9.11.13-5.el8_2 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11200
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com. IN A

;; ANSWER SECTION:
google.com. 296 IN A 216.58.197.78

;; Query time: 3 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Sun Apr 04 14:27:11 EDT 2022
;; MSG SIZE rcvd: 55

8-Traceroute

traceroute is a network troubleshooting utility that shows the number of hops taken to reach a destination and also determines packets traveling path.At first, you have to install the traceroute package.

[root@localhost /]# yum install traceroute -y

Below Traceroute to facebook.com.

[root@localhost ~]# traceroute www.facebook.com
traceroute to www.facebook.com (157.240.239.35), 30 hops max, 60 byte packets
 1  gateway (192.168.1.1)  0.185 ms  0.117 ms  0.146 ms
 2  10.0.0.1 (10.0.0.1)  0.268 ms  0.229 ms  0.188 ms
 3  13.0.0.1 (13.0.0.1)  69.342 ms  100.607 ms  100.480 ms
 4  74.119.78.201 (74.119.78.201)  69.098 ms  69.008 ms po104.psw01.del1.tfbnw.net (31.13.25.169)  68.987 ms
 5  157.240.39.97 (157.240.39.97)  69.365 ms 157.240.39.109 (157.240.39.109)  69.319 ms 173.252.67.229 (173.252.67.229)  68.980 ms
 6  edge-star-mini-shv-02-del1.facebook.com (157.240.239.35)  68.928 ms  69.087 ms  68.982 ms
[root@localhost ~]# 

9-Ping

Ping is the utility to test the reachability between source and destination.

c is used for packet count, I select 10 because I want to send 10 ping packet to google.com

[root@localhost ~]# ping facebook.com
PING facebook.com (157.240.239.35) 56(84) bytes of data.
64 bytes from edge-star-mini-shv-02-del1.facebook.com (157.240.239.35): icmp_seq=1 ttl=59 time=69.4 ms
64 bytes from edge-star-mini-shv-02-del1.facebook.com (157.240.239.35): icmp_seq=2 ttl=59 time=69.0 ms
64 bytes from edge-star-mini-shv-02-del1.facebook.com (157.240.239.35): icmp_seq=3 ttl=59 time=68.8 ms
64 bytes from edge-star-mini-shv-02-del1.facebook.com (157.240.239.35): icmp_seq=4 ttl=59 time=68.9 ms
^C
--- facebook.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 68.864/69.055/69.406/0.338 ms
[root@localhost ~]# 





[root@localhost ~]# ping -c 10 google.com
PING google.com (142.250.195.110) 56(84) bytes of data.
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=1 ttl=121 time=38.9 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=2 ttl=121 time=38.6 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=3 ttl=121 time=38.6 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=4 ttl=121 time=38.5 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=5 ttl=121 time=38.6 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=6 ttl=121 time=38.5 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=7 ttl=121 time=38.5 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=8 ttl=121 time=38.5 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=9 ttl=121 time=38.5 ms
64 bytes from maa03s39-in-f14.1e100.net (142.250.195.110): icmp_seq=10 ttl=121 time=38.5 ms

--- google.com ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9015ms
rtt min/avg/max/mdev = 38.531/38.617/38.981/0.279 ms
[root@localhost ~]# 

10-Enable or Disable Specific Interface

//Enable the port

[root@localhost ~]# ifup eth0

//Disable the port

[root@localhost ~]# ifdown eth0

11-MTU Size Configuration

The default MTU size is 1500 on Ethernet,But you can change it if you want, But it’s not recommended to change.

[root@localhost /]#ifconfig eth1 mtu 1500

12-Viewing the IP address on the port.

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 6c:de:4b:12:b3:12 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.2/30 brd 192.168.1.3 scope global noprefixroute eno2
       valid_lft forever preferred_lft forever


[root@localhost ~]# ifconfig
eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.2  netmask 255.255.255.252  broadcast 192.168.1.3
        ether 6c:de:4b:12:b3:12  txqueuelen 1000  (Ethernet)
        RX packets 43020570  bytes 41675151184 (38.8 GiB)
        RX errors 0  dropped 0  overruns 40  frame 0
        TX packets 47428243  bytes 51462919413 (47.9 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xc5a60000-c5a7ffff  
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 28  bytes 2492 (2.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28  bytes 2492 (2.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# 

13-Configuring the Static IP address .

Create a file named /etc/sysconfig/network-scripts/ifcfg-eth2 as follows:

DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
PREFIX=24
IPADDR=192.168.1.2


Restart network service: systemctl restart network

14-How to configure the IP through DHCP.

Create a file named /etc/sysconfig/network-scripts/ifcfg-eth2 as follows:

DEVICE="eth2"
ONBOOT=yes
NETBOOT=yes
UUID="41171a6f-bce1-44de-8a6e-cf5e782f8bd6"
IPV6INIT=yes
BOOTPROTO=dhcp
HWADDR="00:08:a2:0a:ba:b8"
TYPE=Ethernet
NAME="eth2"


Restart network service: systemctl restart network

Leave a Reply

Your email address will not be published.