W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
顯示并設置Linux中靜態(tài)路由表
route命令 用來顯示并設置Linux內(nèi)核中的網(wǎng)絡路由表,route命令設置的路由主要是靜態(tài)路由。要實現(xiàn)兩個不同的子網(wǎng)之間的通信,需要一臺連接兩個網(wǎng)絡的路由器,或者同時位于兩個網(wǎng)絡的網(wǎng)關(guān)來實現(xiàn)。
在Linux系統(tǒng)中設置路由通常是為了解決以下問題:該Linux系統(tǒng)在一個局域網(wǎng)中,局域網(wǎng)中有一個網(wǎng)關(guān),能夠讓機器訪問Internet,那么就需要將這臺機器的ip地址設置為Linux機器的默認路由。要注意的是,直接在命令行下執(zhí)行route命令來添加路由,不會永久保存,當網(wǎng)卡重啟或者機器重啟之后,該路由就失效了;可以在/etc/rc.local中添加route命令來保證該路由設置永久有效。
route(選項)(參數(shù))
-A:設置地址類型;
-C:打印將Linux核心的路由緩存;
-v:詳細信息模式;
-n:不執(zhí)行DNS反向查找,直接顯示數(shù)字形式的IP地址;
-e:netstat格式顯示路由表;
-net:到一個網(wǎng)絡的路由表;
-host:到一個主機的路由表。
Add:增加指定的路由記錄;
Del:刪除指定的路由記錄;
Target:目的網(wǎng)絡或目的主機;
gw:設置默認網(wǎng)關(guān);
mss:設置TCP的最大區(qū)塊長度(MSS),單位MB;
window:指定通過路由表的TCP連接的TCP窗口大??;
dev:路由記錄所表示的網(wǎng)絡接口。
顯示當前路由:
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
112.124.12.0 * 255.255.252.0 U 0 0 0 eth1
10.160.0.0 * 255.255.240.0 U 0 0 0 eth0
192.168.0.0 10.160.15.247 255.255.0.0 UG 0 0 0 eth0
172.16.0.0 10.160.15.247 255.240.0.0 UG 0 0 0 eth0
10.0.0.0 10.160.15.247 255.0.0.0 UG 0 0 0 eth0
default 112.124.15.247 0.0.0.0 UG 0 0 0 eth1
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
112.124.12.0 0.0.0.0 255.255.252.0 U 0 0 0 eth1
10.160.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
192.168.0.0 10.160.15.247 255.255.0.0 UG 0 0 0 eth0
172.16.0.0 10.160.15.247 255.240.0.0 UG 0 0 0 eth0
10.0.0.0 10.160.15.247 255.0.0.0 UG 0 0 0 eth0
0.0.0.0 112.124.15.247 0.0.0.0 UG 0 0 0 eth1
其中Flags為路由標志,標記當前網(wǎng)絡節(jié)點的狀態(tài),F(xiàn)lags標志說明:
添加網(wǎng)關(guān)/設置網(wǎng)關(guān):
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 #增加一條到達244.0.0.0的路由。
屏蔽一條路由:
route add -net 224.0.0.0 netmask 240.0.0.0 reject #增加一條屏蔽的路由,目的地址為224.x.x.x將被拒絕。
刪除路由記錄:
route del -net 224.0.0.0 netmask 240.0.0.0
route del -net 224.0.0.0 netmask 240.0.0.0 reject
刪除和添加設置默認網(wǎng)關(guān):
route del default gw 192.168.120.240
route add default gw 192.168.120.240
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: