亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Linux命令之網(wǎng)絡命令route詳解

 更新時間:2023年10月31日 11:31:42   作者:恒悅sunsite  
route命令是Linux系統(tǒng)中的一個網(wǎng)絡管理工具,用于顯示和操作IP路由表,它可以用來查看當前系統(tǒng)的路由表信息,添加、刪除或修改路由表項,以及顯示路由表中的詳細信息,本文給大家介紹Linux命令之網(wǎng)絡命令route詳解,感興趣的朋友一起看看吧

一、route命令簡介

  route命令是Linux系統(tǒng)中的一個網(wǎng)絡管理工具,用于顯示和操作IP路由表。它可以用來查看當前系統(tǒng)的路由表信息,添加、刪除或修改路由表項,以及顯示路由表中的詳細信息。route命令可以幫助用戶診斷和解決網(wǎng)絡連接問題,以及進行網(wǎng)絡規(guī)劃和優(yōu)化。

二、route命令使用示例

1、查看命令版本

  route命令也屬于net-tools工具集中的命令,如果linux系統(tǒng)沒有此命令,我們可以通過安裝net-tools軟件包來安裝此命令。

[root@s152 ~]# route --version
net-tools 2.10-alpha
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +I18N +SELINUX
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE -BLUETOOTH
HW: +ETHER +ARC +SLIP +PPP +TUNNEL -TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64

2、獲取命令幫助

  通過–help或者-h參數(shù)可以獲取命令幫助,route命令可以查看或者更新、修改、刪除系統(tǒng)路由表。

3、查看操作系統(tǒng)路由

  使用-n參數(shù)查看路由明細,當然不用參數(shù)也可以查看,-n表示不解析主機名。

[root@s152 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

4、添加一段路由

  使用add參數(shù)添加路由,可以添加一個網(wǎng)段也可以添加一個主機路由。

[root@s152 ~]# route add -net 192.168.122.0/24 gw 192.168.0.166
[root@s152 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.0 192.168.0.166 255.255.255.0 UG 0 0 0 eth0

5、刪除一段路由

  使用del參數(shù)刪除一段或者一個主機路由。

[root@s152 ~]# route del -net 192.168.122.0/24
[root@s152 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0

5、添加一個主機路由

[root@s152 ~]# route add -host 192.168.122.1 gw 192.168.0.166
[root@s152 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.1 192.168.0.166 255.255.255.255 UGH 0 0 0 eth0
[root@s152 ~]# ping 192.168.122.1
PING 192.168.122.1 (192.168.122.1) 56(84) bytes of data.
64 bytes from 192.168.122.1: icmp_seq=1 ttl=64 time=0.795 ms
…

6、添加一條禁止訪問路由

  使用reject參數(shù)表示拒絕路由,用于訪問安全控制,禁止主機訪問明確不安全或者無權(quán)訪問的主機。添加后查看路由表,狀態(tài)為嘆號,表示禁止訪問,優(yōu)先普通路由策略。

7、刪除默認路由

  使用del default gw刪除默認網(wǎng)關(guān)。

[root@s166 ~]# route del default gw 192.168.0.1
[root@s166 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

8、添加默認路由

  使用add default gw添加默認網(wǎng)關(guān)。

[root@s166 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[root@s166 ~]# route add default gw 192.168.0.1
[root@s166 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

三、route命令使用語法及參數(shù)說明

1、使用語法

查看路由用法:#route [-nNvee] [-FC] []
更新路由用法:#route [-v] [-FC] {add|del|flush} …

2、參數(shù)說明

參數(shù)選項參數(shù)說明
-n直接使用 IP 地址,不進行 DNS 解析主機
-ee顯示更詳細的路由信息
add添加路由信息
del刪除路由信息
target指定目標網(wǎng)絡或主機??梢杂?IP 地址或主機/網(wǎng)絡名
-net到一個網(wǎng)絡的路由,后面接的是一個網(wǎng)絡號地址
-host到一個主機的路由,后面接的是一個主機地址
netmask NM為添加的路由指定網(wǎng)絡掩碼,NM表示掩碼地址,如255.255.255.0
gw GW為發(fā)往目標網(wǎng)絡/主機的任何分組指定網(wǎng)關(guān)
dev lf指定由哪個網(wǎng)絡設備出去,后面接網(wǎng)絡設備名,如 etho 等

3、Flags路由標記信息

Flags標記標記說明
U(route is up)表示此路由當前為啟動狀態(tài)
H(target is a host)目標路由是一個主機(IP)而非網(wǎng)絡
R(reinstate route for dynamic routing):使用動態(tài)路由時,恢復路由信息標識
G(use gateway)表示需要通過外部的主機(gateway)來轉(zhuǎn)接傳遞數(shù)據(jù)
M(modified from routing daemon or redirect)表示路由已經(jīng)被修改了
D(dynamically installed by daemon or redirect)已經(jīng)服務設定為動態(tài)路由
!(reject route )這個路由將不會被接受( 用來抵擋不安全的網(wǎng)絡)

四、靜態(tài)路由永久配置方式

  我們使用route命令配置的路由都是臨時生效,在網(wǎng)卡重啟或者系統(tǒng)重啟后配置失效,如果我們需要配置永久靜態(tài)路由可以使用如下幾種方式。

方式一:

vi /etc/sysconfig/network-scripts/route-eth0 #<==默認不存在此文件
加入如下內(nèi)容
192.168.1.0/24 via 10.0.0.254

方式二:

vi /etc/sysconfig/static-routes #<==默認不存在此文件
加入如下內(nèi)容
any net 192.168.1.0/24 gw 10.0.0.254

方式三:

vi /etc/rc.local
加入如下內(nèi)容
route add -net 192.168.1.0/24 gw 10.0.0.254

到此這篇關(guān)于Linux命令之網(wǎng)絡命令route詳解的文章就介紹到這了,更多相關(guān)Linux route命令內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論