linux網(wǎng)絡(luò)運(yùn)維命令--route
共 3549字,需瀏覽 8分鐘
·
2024-07-25 07:33
鏈接:https://www.cnblogs.com/du-z/p/16332641.html
簡(jiǎn)介
route - show / manipulate the IP routing table
Route操作內(nèi)核的IP路由表。它的主要用途是在使用ifconfig(8)程序配置后,通過(guò)接口建立到特定主機(jī)或網(wǎng)絡(luò)的靜態(tài)路由。
當(dāng)使用add或del選項(xiàng)時(shí),route會(huì)修改路由表。如果沒(méi)有這些選項(xiàng),route將顯示路由表的當(dāng)前內(nèi)容。
要注意的是,直接在命令行下執(zhí)行route命令來(lái)添加路由,不會(huì)永久保存,當(dāng)網(wǎng)卡重啟或者機(jī)器重啟之后,該路由就失效了;可以在/etc/rc.local中添加route命令來(lái)保證該路由設(shè)置永久有效。
下載安裝
yum install net-tools
使用用法
route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]
-c 顯示更多信息
-n 不解析名字
-v 顯示詳細(xì)的處理信息
-F 顯示發(fā)送信息
-C 顯示路由緩存
-f 清除所有網(wǎng)關(guān)入口的路由表。
-p 與 add 命令一起使用時(shí)使路由具有永久性
add : 添加一條新路由
del : 刪除一條路由
-net : 目標(biāo)地址是一個(gè)網(wǎng)絡(luò)
-host : 目標(biāo)地址是一個(gè)主機(jī)
netmask : 當(dāng)添加一個(gè)網(wǎng)絡(luò)路由時(shí),需要使用網(wǎng)絡(luò)掩碼
gw : 路由數(shù)據(jù)包通過(guò)網(wǎng)關(guān)。注意,你指定的網(wǎng)關(guān)必須能夠達(dá)到
metric : 設(shè)置路由跳數(shù)
輸出
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.10.0 - 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
輸出說(shuō)明:
內(nèi)核路由表的輸出按以下列組織
Destination : 目標(biāo)網(wǎng)絡(luò)或目標(biāo)主機(jī)。
Gateway :網(wǎng)關(guān)地址或'*',如果沒(méi)有設(shè)置。
Genmask :目的網(wǎng)絡(luò)的子網(wǎng)掩碼;'255.255.255.255'表示主機(jī)目的地址,'0.0.0.0'表示默認(rèn)路由。
Flags :
U(路線向上)
H(目標(biāo)為主機(jī))
G(使用網(wǎng)關(guān))
R(恢復(fù)動(dòng)態(tài)路由路由)
D(通過(guò)守護(hù)進(jìn)程或重定向動(dòng)態(tài)安裝)
M(來(lái)自路由守護(hù)進(jìn)程或重定向)
A(通過(guò)addrconf安裝)
C(緩存條目)
!(拒絕)
Metric :到目標(biāo)的“距離”(通常以跳數(shù)計(jì)算)。最近的內(nèi)核不使用它,但是路由守護(hù)進(jìn)程可能需要它
Ref :此路由的引用數(shù)。(Linux內(nèi)核中不使用。)
Use :對(duì)路由的查找計(jì)數(shù)。根據(jù)-F和-C的使用,這將是路由緩存未命中(-F)或命中(-C)
Iface :該路由的報(bào)文將被發(fā)送到的接口
示例
查詢(xún)路由
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
添加路由
[root@master ~]# route add -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.10.0 192.168.209.2 255.255.255.0 UG 0 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
刪除路由
[root@master ~]# route del -net 10.10.10.0 gw 192.168.209.2 netmask 255.255.255.0 dev ens33
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
添加阻斷路由與刪除
[root@master ~]# route add -net 10.10.10.0 netmask 255.255.255.0 reject
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
10.10.10.0 - 255.255.255.0 ! 0 - 0 -
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
[root@master ~]# route del -net 10.10.10.0 netmask 255.255.255.0 reject
[root@master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.209.2 0.0.0.0 UG 100 0 0 ens33
192.168.209.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
秋招已經(jīng)開(kāi)始啦,大家如果不做好充足準(zhǔn)備的話,秋招很難找到好工作。
送大家一份就業(yè)大禮包,大家可以突擊一下春招,找個(gè)好工作!
評(píng)論
圖片
表情
