您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Linux下怎么查看路由表”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Linux下怎么查看路由表”這篇文章吧。
是一個存儲在 或者聯(lián)網(wǎng)計算機中的電子表格或類數(shù)據(jù)庫。路由表存儲著指向特定 的路徑。路由表中含有網(wǎng)絡(luò)周邊的 信息,主要目標(biāo)是為了實現(xiàn) 和 選擇。
[root@VM_139_74_centos ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 eth0 10.0.0.10 10.139.128.1 255.255.255.255 UGH 0 0 0 eth0 10.139.128.0 0.0.0.0 255.255.224.0 U 0 0 0 eth0 link-local 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-0ab63c131848 172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-bccbfb788da0 172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-7485db25f958 [root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.139.128.1 0.0.0.0 UG 0 0 0 eth0 10.0.0.10 10.139.128.1 255.255.255.255 UGH 0 0 0 eth0 10.139.128.0 0.0.0.0 255.255.224.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-0ab63c131848 172.19.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-bccbfb788da0 172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-7485db25f958
Destination | 目標(biāo)網(wǎng)絡(luò)或目標(biāo)主機。Destination 為 default(0.0.0.0)時,表示這個是默認網(wǎng)關(guān),所有數(shù)據(jù)都發(fā)到這個網(wǎng)關(guān)(這里是 10.139.128.1) |
---|---|
Gateway | 網(wǎng)關(guān)地址,0.0.0.0 表示當(dāng)前記錄對應(yīng)的 Destination 跟本機在同一個網(wǎng)段,通信時不需要經(jīng)過網(wǎng)關(guān)(同一個局域網(wǎng)內(nèi)2臺主機通信不需要經(jīng)過網(wǎng)關(guān)) |
Genmask | Destination 字段的網(wǎng)絡(luò)掩碼,Destination 是主機時需要設(shè)置為 255.255.255.255,是默認路由時會設(shè)置為 0.0.0.0 |
Flags | 標(biāo)志U – Up表示有效G – Gateway表示連接路由,若無這個字段表示直連目的地址H – Host表示目標(biāo)是具體主機,而不是網(wǎng)段R 恢復(fù)動態(tài)路由產(chǎn)生的表項D 由路由的后臺程序動態(tài)地安裝M 由路由的后臺程序修改! 拒絕路由 |
Metric | 路由距離,到達指定網(wǎng)絡(luò)所需的中轉(zhuǎn)數(shù),是大型局域網(wǎng)和廣域網(wǎng)設(shè)置所必需的 (不在Linux內(nèi)核中使用。) |
Ref | 路由項引用次數(shù) (不在Linux內(nèi)核中使用。) |
Use | 此路由項被路由軟件查找的次數(shù) |
Iface | 網(wǎng)卡名字,例如 eth0;要去往這個網(wǎng)段需要使用哪一個網(wǎng)絡(luò)接口。也就是eth0這張網(wǎng)卡 |
顯示詳細信息
1、主機路由,路由表中指向單個 IP 地址或主機名的路由記錄,其 Flags 字段為 H。下面示例中,對于 10.0.0.10 這個主機,通過網(wǎng)關(guān) 10.139.128.1 網(wǎng)關(guān)路由:
[root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.10 10.139.128.1 255.255.255.255 UGH 0 0 0 eth0 ...
2、網(wǎng)絡(luò)路由,主機可以到達的網(wǎng)絡(luò)。下面示例中,對于 10.0.0.0/24 這個網(wǎng)絡(luò),通過網(wǎng)關(guān) 10.139.128.1 網(wǎng)關(guān)路由:
[root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 10.139.128.1 255.255.255.0 UG 0 0 0 eth0
3、默認路由,當(dāng)目標(biāo)主機的 IP 地址或網(wǎng)絡(luò)不在路由表中時,數(shù)據(jù)包就被發(fā)送到默認路由(默認網(wǎng)關(guān))上。默認路由的 Destination 是 default 或 0.0.0.0。
[root@VM_139_74_centos ~]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 eth0
選項:
-A:設(shè)置地址類型
-C:打印 Linux 內(nèi)核的路由緩存
-v:顯示詳細信息
-n:不執(zhí)行 DNS 反向查找,直接顯示數(shù)字形式的 IP 地址
-e:netstat 格式顯示路由表
-net:到一個網(wǎng)絡(luò)的路由表
-host:到一個主機的路由表
參數(shù):
add:增加路由記錄
del:刪除路由記錄
target:目的網(wǎng)絡(luò)或目的主機
gw:設(shè)置默認網(wǎng)關(guān)
mss:設(shè)置TCP的最大區(qū)塊長度(MSS),單位MB
window:指定通過路由表的TCP連接的TCP窗口大小
dev:路由記錄所表示的網(wǎng)絡(luò)接口
1、添加主機路由,添加主機路由時,需要指定網(wǎng)絡(luò) ID 和主機 ID,此時需要設(shè)置 netmask 255.255.255.255:
[root@VM_139_74_centos ~]# route add -net 10.0.0.10 netmask 255.255.255.255 gw 10.139.128.1 dev eth0 [root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.10 10.139.128.1 255.255.255.255 UGH 0 0 0 eth0 ...
2、添加網(wǎng)絡(luò)路由,添加網(wǎng)絡(luò)路由時,只需指定網(wǎng)絡(luò) ID,通過 netmask 設(shè)置掩碼長度:
[root@VM_139_74_centos ~]# route add -net 10.0.0.0 netmask 255.255.255.0 gw 10.139.128.1 dev eth0 [root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.0.0 10.139.128.1 255.255.255.0 UG 0 0 0 eth0 ...
3、添加同一個局域網(wǎng)的主機,不指定 gw 選項時,添加的路由記錄不使用網(wǎng)關(guān):
[root@VM_139_74_centos ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 [root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 224.0.0.0 0.0.0.0 240.0.0.0 U 0 0 0 eth0 ...
4、屏蔽路由
[root@VM_139_74_centos ~]# route add -net 224.0.0.0 netmask 240.0.0.0 reject [root@VM_139_74_centos ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 224.0.0.0 - 240.0.0.0 ! 0 - 0 - ...
5、刪除可用路由
route del -net 224.0.0.0 netmask 240.0.0.0
6、刪除屏蔽路由
route del -net 224.0.0.0 netmask 240.0.0.0 reject
7、刪除和添加設(shè)置默認網(wǎng)關(guān),添加或刪除默認網(wǎng)關(guān)時,Linux 會自動檢查網(wǎng)關(guān)的可用性:
[root@VM_139_74_centos ~]# route add default gw 192.168.1.1 SIOCADDRT: Network is unreachable [root@VM_139_74_centos ~]# route del default gw 192.168.1.1 SIOCDELRT: No such process
以上是“Linux下怎么查看路由表”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。