การตรวจสอบหมายเลข IP ของ Router ที่ใช้งาน

การตรวจสอบหมายเลข IP ของ Router ที่ใช้งานสามารถตรวจสอบด้วยคำสั่งดังนี้
netstat -r -n
route -n
route -rn
ip r
ip route
ip r | grep default
ip route show default
arp -n | awk '{print $1}'
netstat -nr | awk '$1 == "0.0.0.0"{print$2}'
nmcli dev show enp0s3 | grep GATEWAY
ip route show | awk '/default/ {print $3}'
ip route show | grep -i 'default via'| awk '{print $3 }'
route -n | sed -nr 's/(0\.0\.0\.0) +([^ ]+) +\1.*/\2/p'
route -n | grep -Po "0\.0\.0\.0\s*\K\S+(?=\s*0\.0\.0\.0)"

ใช้คำสั่ง nmcli
yum install nmcli -y nm-tool | grep -i gateway | xargs echo | cut -d' ' -f2
nm-tool | grep -i gateway | awk '{print $2}

ตัวอย่าง

------------------EXAMPLE---------------------
[root@logs ~]# netstat -r -n
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3

------------------EXAMPLE---------------------
[root@logs ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3

------------------EXAMPLE---------------------
[root@logs ~]# ip r
default via 10.0.2.2 dev enp0s3 proto static metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.16 metric 100

------------------EXAMPLE---------------------
[root@logs ~]# ip route
default via 10.0.2.2 dev enp0s3 proto static metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.16 metric 100

------------------EXAMPLE---------------------
[root@logs ~]# ip r | grep default
default via 10.0.2.2 dev enp0s3 proto static metric 100

------------------EXAMPLE---------------------
[root@logs ~]# ip route show default
default via 10.0.2.2 dev enp0s3 proto static metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.16 metric 100

------------------EXAMPLE---------------------
[root@logs ~]# arp -n | awk '{print $1}'
Address
10.0.2.2

------------------EXAMPLE---------------------
[root@logs ~]# netstat -nr | awk '$1 == "0.0.0.0"{print$2}'
10.0.2.2

------------------EXAMPLE---------------------
[root@logs ~]# nmcli dev show enp0s3 | grep GATEWAY
IP4.GATEWAY: 10.0.2.2
IP6.GATEWAY: --

------------------EXAMPLE---------------------
[root@logs ~]# ip route show | awk '/default/ {print $3}'
10.0.2.2

------------------EXAMPLE---------------------
[root@logs ~]# ip route show | grep -i 'default via'| awk '{print $3 }'
10.0.2.2

------------------EXAMPLE---------------------
[root@logs ~]# route -n | sed -nr 's/(0\.0\.0\.0) +([^ ]+) +\1.*/\2/p'
10.0.2.2

------------------EXAMPLE---------------------
[root@logs ~]# route -n | grep -Po "0\.0\.0\.0\s*\K\S+(?=\s*0\.0\.0\.0)"
10.0.2.2

--
Write by Dr.Arnut Ruttanatirakul
(c) 2018 by SysAdmin Knowledge
http://www.sysadmin.in.th
November 16, 2018