中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

CentOS中route命令的解析

2019-05-28    來源:愛站科技

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用

很多人對CentOS中的route命令都不是非常理解的,接下來是小編為大家介紹CentOS中route命令的解析,有需要的朋友們下面來跟著小編一起學習學習吧。
?

介紹

Linux系統(tǒng)中的route命令能夠用于IP路由表的顯示和操作。它的主要作用是創(chuàng)建一個靜態(tài)路由讓指定一個主機或者一個網(wǎng)絡通過一個網(wǎng)絡接口,如eth0。當使用”add”或者”del”參數(shù)時,路由表被修改,如果沒有參數(shù),則顯示路由表當前的內容。在一個網(wǎng)絡中,需要一個路由器來轉發(fā)不同廣播域之間的數(shù)據(jù),或是轉發(fā)lan和internet之間的數(shù)據(jù)。有時我們需要設定這個路由器作為linux系統(tǒng)的默認路由,那么就可以通過route命令來操作。甚至我們也可以用我們的linux系統(tǒng)來充當路由器。

要注意的是:直接在命令行下執(zhí)行route命令來添加路由,不會永久保存,當網(wǎng)卡重啟或者機器重啟之后,該路由就失效了;可以在/etc/rc.local中添加route命令來保證該路由設置永久有效。當然如果加上了-p參數(shù)的話那就會永久的生效了。

命令格式

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway][metric Metric]] [if Interface]]

命令參數(shù)

???? -c 顯示更多信息

???? -n 不解析名字

???? -v 顯示詳細的處理信息

???? -F 顯示發(fā)送信息

???? -C 顯示路由緩存

???? -f 清除所有網(wǎng)關入口的路由表。

???? -p 與add 命令一起使用時使路由具有永久性。

???? add:添加一條新路由。

???? del:刪除一條路由。

???? -net:目標地址是一個網(wǎng)絡。

???? -host:目標地址是一個主機。

???? netmask:當添加一個網(wǎng)絡路由時,需要使用網(wǎng)絡掩碼。

???? gw:路由數(shù)據(jù)包通過網(wǎng)關。注意,你指定的網(wǎng)關必須能夠達到。

???? metric:設置路由跳數(shù)。

????????? 1、Command 指定您想運行的命令 (Add/Change/Delete/Print)。

????????? 2、Destination 指定該路由的網(wǎng)絡目標。

????????? 3、mask Netmask 指定與網(wǎng)絡目標相關的網(wǎng)絡掩碼(也被稱作子網(wǎng)掩碼)。

????????? 4、Gateway 指定網(wǎng)絡目標定義的地址集和子網(wǎng)掩碼可以到達的前進或下一躍點 IP 地址。

????????? 5、metric Metric 為路由指定一個整數(shù)成本值標(從 1 至 9999),當在路由表(與轉發(fā)的數(shù)據(jù)包目標地址最匹配)的多個路由中進行選擇時可以使用。

????????? 6、if Interface為可以訪問目標的接口指定接口索引。若要獲得一個接口列表和它們相應的接口索引,使用 route print 命令的顯示功能?梢允褂檬M制或十六進

實例

1 顯示路由信息

[root@localhost~]# route
Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default 192.168.40.1 0.0.0.0  UG 0 0 0 eth0

Flags標志說明

  1. U Up表示此路由當前為啟動狀態(tài)
  2. H Host,表示此網(wǎng)關為一主機
  3. G Gateway,表示此網(wǎng)關為一路由器
  4. R Reinstate Route,使用動態(tài)路由重新初始化的路由
  5. D Dynamically,此路由是動態(tài)性地寫入–》什么時候才會有動態(tài)的路由信息呢?
  6. M Modified,此路由是由路由守護程序或導向器動態(tài)修改

2 添加一條指向某個網(wǎng)絡的路由

[root@localhost~]# route add -net 10.0.0.0 netmask 255.255.255.0 dev eth0

這里是指定這條路由的出口在哪里。-net 10.0.0.0 netmask 255.255.255.0 為指定目標網(wǎng)絡的參數(shù),需要ip地址或地址范圍、子網(wǎng)掩碼用于確定網(wǎng)絡范圍。

[root@localhost~]# route
Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
10.0.0.0 *  255.255.255.0 U 0 0 0 eth0
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default 192.168.40.1 0.0.0.0  UG 0 0 0 eth0

route添加路由都是需要指定目標網(wǎng)絡,及路由出口這兩個參數(shù)。記住加上-p選項能永久添加。

3 添加到某一個ip的路由

[root@localhost~]# route add -host 192.168.40.1dev eth0
[root@localhost ~]# route

可以發(fā)現(xiàn)添加的是主機的話,默認是會幫我們添加一個全255的子網(wǎng)掩碼,表示子網(wǎng)范圍就只有一個而已,那就是這臺主機啦。

Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.1 *  255.255.255.255 UH 0 0 0 eth0

4 屏蔽某一路由

當我們不讓系統(tǒng)到達某個子網(wǎng)范圍或者某個主機是就可以手動的來進行屏蔽。

[root@localhost~]# route add -net 10.10.10.128 netmask 255.255.255.128 reject

前面部分是一樣的,因為我們都是手動來添加一個路由嘛。只是在命令的最后不一樣,我們指定的出口去而是reject(拒絕),也就是拒絕出口。達到屏蔽的效果。還有看下flags會顯示一個!

[root@localhost~]# route
Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.1 *  255.255.255.255 UH 0 0 0 eth0
10.10.10.128 -  255.255.255.128 ! 0 - 0 -
10.0.0.0 *  255.255.255.0 U 0 0 0 eth0
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default 192.168.40.1 0.0.0.0  UG 0 0 0 eth0

5 刪除路由

[root@localhost~]# route
Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.1 *  255.255.255.255UH 0 0 0 eth0
10.10.10.128 -  255.255.255.128 ! 0 - 0 -
10.0.0.0 *  255.255.255.0 U 0 0 0 eth0
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default 192.168.40.1 0.0.0.0  UG 0 0 0 eth0
[root@localhost~]# route del -net 10.10.10.128netmask 255.255.255.128 reject
[root@localhost~]# route

Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.1 *  255.255.255.255UH 0 0 0 eth0
10.0.0.0 *  255.255.255.0 U 0 0 0 eth0
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default 192.168.40.1 0.0.0.0  UG 0 0 0 eth0

說明:刪除路由時,最好是看著路由表上的照樣打進去,這樣比較不會刪錯的。

添加刪除默認網(wǎng)關

[root@localhost ~]# route add default gw 192.168.40.2

[root@localhost~]# route

Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.1 *  255.255.255.255UH 0 0 0 eth0
10.0.0.0 *  255.255.255.0 U 0 0 0 eth0
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default  192.168.40.2 0.0.0.0  UG 0 0 0 eth0
default  192.168.40.1 0.0.0.0  UG 0 0 0 eth0

可以看到此處有兩個默認網(wǎng)關,那到底路由會走哪個呢?

[root@localhost~]# route del default gw192.168.40.2
[root@localhost~]# route

Kernel IP routing table
Destination Gateway  Genmask  Flags Metric Ref Use Iface
192.168.40.1 *  255.255.255.255UH 0 0 0 eth0
10.0.0.0 *  255.255.255.0 U 0 0 0 eth0
192.168.40.0 *  255.255.252.0 U 0 0 0 eth0
169.254.0.0 *  255.255.0.0 U 0 0 0 eth0
default 192.168.40.1 0.0.0.0  UG 0 0 0 eth0

以上就是CentOS中route命令的解析,文中介紹的很詳細,相信對大家的理解和學習具有一定的參考價值!

標簽: [db:TAGG]

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:nginx實現(xiàn)讀寫限流

下一篇:nginx反向代理配置及優(yōu)化的介紹