路由器(Router),是連接因特網中各局域網、廣域網的設備,它會根據信道的情況自動選擇和設定路由,以最佳路徑,按前后順序發送信號,路由器工作在網絡層,用來跨網段通信,路由器具有判斷網絡地址和選擇IP路徑的功能,它能在多網絡互聯環境中,建立靈活的連接,可用完全不同的數據分組和介質訪問方法連接各種子網,路由器只接受源站或其他路由器的信息,屬網絡層的一種互聯設備,因此路由器是互聯網中必不可少的網絡設備之一.
文字描述,摘抄自《網絡設備配置與管理》精簡內容,部分內容來自華為(HCIP認證》課程筆記,適合學習面試,其中的架構圖,與搭建流程為自己規划並實驗的。
路由器,其最重要的功能就是路由,路由是指路由器接收到數據時選擇最佳路徑將數據穿過網絡傳輸到目標地址的行為,每個路由器負責自己的本地數據的路由或轉發,通過多個路由器依次接力將數據最終傳遞到目標主機,路由的工作流程包括路由選擇
和路由轉發
兩個方面.
路由基本配置
路由器與交換機不同,交換機不需要配置也可以正常工作,但是路由器必須經過配置后才可以正常使用
,路由器的登陸方式基本和交換機保持一致,下面將用一個實例實現路由器的基本配置,包括配置路由器的主機名稱,密碼,控制台端口,WAN接口和LAN接口等,來實現一個基本的路由結構.
首先我們准備兩台路由器(1841型號)
,需要注意的是設備之間的連接所選用的線路類型,一般情況下路由器和PC之間使用交叉線
,兩台路由器相連接使用串行線
,配置成以下拓撲結構即可:
但在實際連接兩個路由器時,發現沒有Serial接口
,這是因為該型號的路由器默認沒有提供串口,我們可以在思科模擬器上選擇WIC-2T模塊
,並將其拖入空的插槽處,重啟交換機即可完成配置.
接着來看一下網絡拓撲結構中,每個設備的具體配置參數,包括類型,IP地址,默認網關等信息.
[設備名稱] [設備接口] [IP地址] [默認網關]
PC1 --- 192.168.1.2/24 192.168.1.1
PC2 --- 192.168.2.2/24 192.168.2.1
Router0 Fa0/0 192.168.1.1/24 ---
Serial0/0/0 10.10.10.10/24 ---
Router1 Fa0/0 192.168.2.1/24 ---
Serial0/0/0 10.10.10.20/24 ---
開啟路由遠程登陸: 這里我們將啟用Router1路由器
的遠程登陸功能,並設置一個登陸密碼為lyshark
.
Router# enable
Router# configure terminal
Router(config)# hostname Router0 // 配置主機名為Router0
Router0(config)# enable secret lyshark // 配置特權模式密碼為lyshark
Router0(config)# line console 0 // 啟用控制台
Router0(config-line)# password lyshark // 設置控制台登錄密碼
Router0(config-line)# login // 允許用戶登錄
Router0(config-line)# exit
Router0(config)# line vty 0 2 // 配置序號為0-2的3個虛擬登陸終端
Router0(config-line)# password lyshark // 配置終端登錄密碼
Router0(config-line)# login // 啟用登陸終端
配置WAN接口: 路由器通過WAN接口接入到互聯網上,而常見的WAN接口都是串行接口用Serial表示
,首先可以使用show controller 命令
判斷Serial 0/0/0
是否為DCE端,然后決定是否要配置.
Router0> show controller Serial0/0/0
Interface Serial0/0/0
Hardware is PowerQUICC MPC860
DCE V.35, clock rate 2000000 // 此處判斷是DEC端
根據上述標注顯示內容Srial0/0/0
為DCE端口,下面需要對兩台路由分別配置時鍾頻率.
#----在Router0上操作-------------------------
Router0> enable
Router0# configure terminal
Router0(config)# interface Serial0/0/0 // 選擇串行接口Srial0/0/0
Router0(config-if)# ip address 10.10.10.10 255.255.255.0 // 配置外網IP地址
Router0(config-if)# clock rate 64000 // 配置始終頻率為6400
Router0(config-if)# no shutdown // 開啟端口
#----在Router1上操作-------------------------
Router1> enable
Router1# configure terminal
Router1(config)# interface Serial0/0/0
Router1(config-if)# ip address 10.10.10.20 255.255.255.0
Router1(config-if)# clock rate 64000
Router1(config-if)# no shutdown
配置LAN接口: LAN接口用來指定內網通訊的地址,接下來分別對兩台路由器做配置.
#----在Router0上操作-------------------------
Router0> enable
Router0# configure terminal
Router0(config)# interface fa0/0 // 選擇以太網接口fa0/0
Router0(config)# ip address 192.168.1.1 255.255.255.0
Router0(config)# no shutdown
#----在Router1上操作-------------------------
Router1> enable
Router1# configure terminal
Router1(config)# interface fa0/0
Router1(config)# ip address 192.168.2.1 255.255.255.0
Router1(config)# no shutdown
查配置信息: 最后可以使用show ip route命令
,查看路由器的路由信息,確定網絡是否正確連接.
Router0# show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 1 subnets
C 10.10.10.0 is directly connected, Serial0/0/0 // 外網地址
C 192.168.1.0/24 is directly connected, FastEthernet0/0 // 內網地址
查接口信息: 也可以使用show ip interface brief命令
,查看路由器的接口信息.
Router0# show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.1.1 YES manual up up
Serial0/0/0 10.10.10.10 YES manual up up
Serial0/0/1 unassigned YES unset administratively down down
Vlan1 unassigned YES unset administratively down down
最后測試通信: 在路由器Route0
上可以ping通Route1
,每個主機也可以ping通自己網段的路由器.
Router0# ping 10.10.10.20
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.10.10.20, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/6 ms
上述小實驗到這里就算配置成功了,但是這里留下了一個疑問,那就是PC0
PingPC1
無法通信,這就涉及到路由器沒有相應的路由條目的問題,這些問題將在后面小實驗中做解釋.
配置靜態路由
靜態路由需要管理員根據實際需求一條條自己手動配置,路由器不會自動生成所需的靜態路由,靜態路由中包括目標節點或目標網絡的IP地址,還可以包括下一跳IP地址,以及在本路由器上使用該靜態路由時的數據包出接口等,但是手動配置靜態路由需要管理員非常了解網絡的拓撲結構才能夠完成配置,在網絡規模較大時還需要耗費大量的經歷和時間去維護,所以並不是所有的網絡都適合配置靜態路由.
一般情況下以下幾種情況可以考慮使用靜態路由
1.網絡的拓撲結構相對較簡單,比如就一台路由器和交換機的情況,可使用靜態路由.
2.網絡保密性要求較高,網絡管理員需要控制鏈路或者控制路由表,則可使用靜態路由.
3.網絡僅通過單個ISP接入Internet,則該ISP就是網絡唯一的出口,所以不需要配置靜態路由.
4.路由資源有限,無法運行路由選擇協議,在這種情況下,需要手動配置路由條目來更新路由表數據.
接下來以一個實例具體介紹靜態路由的配置流程,在思科模擬器中選擇2台1841路由器
,按照以下網絡拓撲結構構建網路,然后為每台路由器配置靜態路由,實現不同網絡間的數據互通.
配置客戶主機: 首先我們根據上圖的配置要求配置好IP地址網關等數據,下面的參數是具體的地址規划.
[設備名稱] [設備接口] [IP地址] [默認網關]
PC0 --- 192.168.1.2/24 192.168.1.1
PC1 --- 192.168.1.3/24 192.168.1.1
PC2 --- 192.168.2.2/24 192.168.2.1
PC3 --- 192.168.2.3/24 192.168.2.1
Router0 Fa0/0 192.168.1.1/24 ---
Serial0/0/0 10.10.10.10/24 ---
Router1 Fa0/0 192.168.2.1/24 ---
Serial0/0/0 10.10.10.20/24 ---
配置路由器: 接着我們分別給路由器配置好地址參數,在這里fa0/0端口
是內網IP地址,serial0/0/0端口
則是外網IP地址,配置是應注意次序,如果配反了則看不到效果.
#----在Router0上操作-------------------------
Router0> enable
Router0# configure terminal
Router0(config)# interface fa0/0 // 配置內網地址
Router0(config-if)# ip address 192.168.1.1 255.255.255.0
Router0(config-if)# no shutdown
Router0(config)# interface serial0/0/0 // 配置外網地址
Router0(config-if)# clock rate 64000
Router0(config-if)# ip address 10.10.10.10 255.255.255.0
Router0(config-if)# no shutdown
#----在Router1上操作-------------------------
Router0> enable
Router0# configure terminal
Router1(config)# interface fa0/0 // 配置內網地址
Router1(config-if)# ip address 192.168.2.1 255.255.255.0
Router1(config-if)# no shutdown
Router1(config)# interface serial0/0/0 // 配置外網地址
Router1(config-if)# clock rate 64000
Router1(config-if)# ip address 10.10.10.20 255.255.255.0
Router1(config-if)# no shutdown
檢測路由配置: 當配置好上面的步驟以后,PC0與PC1主機是可通信的,Route0與Route1也可通信,但PC0無法與PC3通信,原因就是因為路由器沒有配置靜態路由的關系,這一步我們只需要確保同一個網段內能通信即可.
#----在PC0上操作-------------------------
PC0> ping 192.168.1.1
PC0> ping 192.168.1.2
PC0> ping 192.168.1.3
Pinging 192.168.1.3 with 32 bytes of data:
Reply from 192.168.1.3: bytes=32 time=0ms TTL=128
#----在Route0上操作----------------------
Router0#ping 10.10.10.20
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.10.10.20, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/7/12 ms
配置靜態路由: 接下來我們需要在兩台路由器上分別配置路由條目,使用ip route命令
配置,如果想要刪除路由可使用no ip route命令
即可刪除指定路由條目.
#----在Router0上操作-------------------------
Router0> enable
Router0# configure terminal
[目的網絡] [目的掩碼] [下一跳地址]
Router0(config)# ip route 192.168.2.0 255.255.255.0 10.10.10.20
#----在Router1上操作-------------------------
Router1> enable
Router1# configure terminal
Router1(config)# ip route 192.168.1.0 255.255.255.0 10.10.10.10 // 指定返回時的路由
#----檢查配置參數情況-------------------------
Router0# show ip interface brief // 顯示端口ip
Router0# show ip route // 檢查路由參數
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 1 subnets
C 10.10.10.0 is directly connected, Serial0/0/0
C 192.168.1.0/24 is directly connected,FastEthernet0/0
S 192.168.2.0/24 [1/0] via 10.10.10.20
最后的測試: 當配置好路由條目以后,我們在PC0主機上Ping檢測PC3的連通性,會發現原來無法連通的兩個網段,現在可以正常通信了,也就說明我們的路由配置生效了.
PC0> ping 192.168.2.2
Pinging 192.168.2.2 with 32 bytes of data:
Reply from 192.168.2.2: bytes=32 time=12ms TTL=126
Ping statistics for 192.168.2.2:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 12ms, Maximum = 12ms, Average = 12ms
以上的路由配置方法,適用於小型網絡環境,在大型網絡環境中這種靜態路由的配置方式很不適合維護,一旦設備過多,則可能自己都搞不清頭緒,所以在生產環境中,我們會使用動態路由的方式來實現路由器的配置,接下來繼續學習動態路由的配置方式吧.
RIP 動態路由
動態路由是基於某種協議實現的,常見的路由協議有內內部網關協議(IGP)
和邊界網關協議(BGP)
,其中內部網關協議又分為路由信息協議(RIP)
和開放式最短路徑優先協議(OSPF)協議
.
其中RIP(路由信息協議)
是最先被廣泛應用的內部網關路由協議,RIP使用跳數來衡量到達目標地址的距離,跳數是指數據從源地址到達目標地址之間經過的路由器個數.從路由器到直接連接的網絡的跳數定義為1,每經過一個路由器則數值會增加1,RIP允許的最大跳數是15跳
,超過15跳的網絡將無法到達,因此RIP適合用於小型的網絡環境中.
RIP協議默認會每隔30秒
就會與其他相連的網絡廣播自己的路由表,收到廣播的路由器會將收到的信息與自己路由表進行比較,判斷是否將其中的路由條目加入到自己的路由表中,目前RIP共有3中版本,RIPv1,RIPv2,RIPng
,其中RIPng應用於IPv6網絡環境中,RIPv1是有類路由協議,RIPv2則是無類路由協議.
配置參數簡介: 首先我們根據上圖的配置要求配置好路由器各種基本參數,下面的參數是具體的地址規划.
[設備名稱] [設備接口] [IP地址] [默認網關]
Router1 Serial0/0/0 192.168.10.1/24 ---
Router2 Serial0/0/0 192.168.10.2/24 ---
Serial0/0/1 192.168.20.1/24 ---
Router3 Serial0/0/0 192.168.20.2/24 ---
Serial0/0/1 192.168.30.1/24 ---
Router4 Serial0/0/0 192.168.30.2/24 ---
配置路由器: 根據上表的結構配置好路由器的各種參數,主要配置路由器的接口IP地址.
Router>enable
Router#configure terminal
#----在Router1上操作-------------------------
Router1(config)# interface Serial0/0/0
Router1(config-if)# ip address 192.168.10.1 255.255.255.0
Router1(config-if)# no shutdown
#----在Router2上操作-------------------------
Router2(config)# interface Serial0/0/0
Router2(config-if)# ip address 192.168.10.2 255.255.255.0
Router1(config-if)# no shutdown
Router2(config)# interface Serial0/0/1
Router2(config-if)# ip address 192.168.20.1 255.255.255.0
Router1(config-if)# no shutdown
#----在Router3上操作-------------------------
Router3(config)# interface Serial0/0/0
Router3(config-if)# ip address 192.168.20.2 255.255.255.0
Router1(config-if)# no shutdown
Router3(config)# interface Serial0/0/1
Router3(config-if)# ip address 192.168.30.1 255.255.255.0
Router1(config-if)# no shutdown
#----在Router4上操作-------------------------
Router4(config)#interface Serial0/0/0
Router4(config-if)#ip address 192.168.30.2 255.255.255.0
Router1(config-if)# no shutdown
配置並啟用RIP路由: 在每台路由器上啟用並配置好RIP動態路由.
Router>enable
Router#configure terminal
#----在Router1上啟用RIP路由協議並配置-------------------
Router1(config)# router rip // 啟用RIP路由
Router1(config-router)# version 2 // 指定使用RIP版本為RIPv2
Router1(config-router)# network 192.168.10.0 // 聲明與Router1直連的網絡號
Router1(config-router)# exit
#----在Router2上啟用RIP路由協議並配置-------------------
Router2(config)# router rip
Router2(config-router)# version 2
Router2(config-router)# network 192.168.10.0 // 聲明與Router2直連的網絡號
Router2(config-router)# network 192.168.20.0 // 聲明與Router3直連的網絡號
Router2(config-router)# exit
#----在Router3上啟用RIP路由協議並配置-------------------
Router3(config)# router rip
Router3(config-router)# version 2
Router3(config-router)# network 192.168.20.0 // 聲明與Router3直連的網絡號
Router3(config-router)# network 192.168.30.0 // 聲明與Router4直連的網絡號
Router3(config-router)# exit
#----在Router4上啟用RIP路由協議並配置-------------------
Router4(config)# router rip
Router4(config-router)# version 2
Router4(config-router)# network 192.168.30.0 // 聲明與Router4直連的網絡號
Router4(config-router)# exit
檢查配置信息: 配置完成后,在Router1
上執行show ip route 命令
查看RIP配置結果,如下.
Router1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.10.0/24 is directly connected, Serial0/0/0
R 192.168.20.0/24 [120/1] via 192.168.10.2, 00:00:01, Serial0/0/0 // R表示當前是RIP路由
R 192.168.30.0/24 [120/2] via 192.168.10.2, 00:00:01, Serial0/0/0 // 路由條目是RIP自動生成的
測試連通性: 此時我們在Router1
路由器上Ping路由器Router4
是可以通信的,說明配置成功了.
Router1#ping 192.168.30.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.30.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 3/15/27 ms
## OSPF 動態路由
在上面的配置試驗中我們通過使用RIP協議
完成了一個路由器之間的數據通信,但是RIP協議最大僅僅支持15個路由節點,雖然在中小型網絡中這些節點足夠使用了,但是在一些大型企業中往往需更多的跳數,就是因為這種需求我們的OSPF協議
就由此誕生啦.
OSPF(開放式最短路徑優先)
,該協議是基於鏈路狀態的協議規范,因此也可以稱為鏈路狀態協議
,和RIP協議相同,OSPF協議同樣使用跳數
計量路徑開銷,但是與RIP不同的是,OSPF協議不受物理跳數的限制,其路徑開銷與網絡中的鏈路開銷等相關.
OSPF協議采用了FPS算法
來計算最短路徑數,SPF算法將每一個路由作為根(ROOT)
,來計算其數據包到達每一個目標路由器之間的距離,每個路由器根據一個統一的數據庫LSDB
計算出路由域
的拓撲結構圖,該結構很像是一顆樹,所以就叫做最短路徑樹.
OSPF協議的優點
1.OSPF采用了SPF算法,從而可以很好的避免路由器環路的產生.
2.OSPF協議雖然也使用跳數作為計量單位,但不受物理跳數的限制.
3.當網絡鏈路狀態發生變化時,OSPF能夠迅速捕捉並應用,收斂快,路由信息流量小.
4.OSPF路由協議支持路由認證體系,且還可以定義不同的認證方式,提高了網絡安全性.
5.OSPF協議提供了較好的負載均衡性,其數據更新比較智能,相應的減小了網絡流量的帶寬.
在配置OSPF路由之前還有一個小知識點需要補充,在下面的配置試驗中你會看到例如0.0.0.255
這樣的網絡號,這種網絡號被稱作通配符掩碼
,通常情況下通配符掩碼可由,255.255.255.255(廣播地址)
減去當前的255.255.255.0(子網掩碼)
,來獲得,此處小實驗的通配符掩碼為0.0.0.255 area 0
.
接下來開始步入正題,我們還是使用RIP路由的拓撲結構
以及IP地址
的配置都相同,但是這里在配置動態路由的時候,我們使用OSPF的方式來配置,過程如下:
配置路由器: 首先更具上表的結構配置好路由器的各種參數.
Router>enable
Router#configure terminal
#----在Router1上操作-------------------------
Router1(config)# interface Serial0/0/0
Router1(config-if)# ip address 192.168.10.1 255.255.255.0
Router1(config-if)# no shutdown
#----在Router2上操作-------------------------
Router2(config)# interface Serial0/0/0
Router2(config-if)# ip address 192.168.10.2 255.255.255.0
Router1(config-if)# no shutdown
Router2(config)# interface Serial0/0/1
Router2(config-if)# ip address 192.168.20.1 255.255.255.0
Router1(config-if)# no shutdown
#----在Router3上操作-------------------------
Router3(config)# interface Serial0/0/0
Router3(config-if)# ip address 192.168.20.2 255.255.255.0
Router1(config-if)# no shutdown
Router3(config)# interface Serial0/0/1
Router3(config-if)# ip address 192.168.30.1 255.255.255.0
Router1(config-if)# no shutdown
#----在Router4上操作-------------------------
Router4(config)# interface Serial0/0/0
Router4(config-if)# ip address 192.168.30.2 255.255.255.0
Router1(config-if)# no shutdown
配置並啟用OSPF路由: 在每台路由器上啟用並配置好OSPF動態路由.
Router>enable
Router#configure terminal
#----在Router1上啟用OSPF路由協議並配置-------------------
Router1(config)# router ospf 1 // 啟用OSPF路由,並設置進程號為1
Router1(config-router)# router-id 1.1.1.1 // 為Router1配置RID編號
Router1(config-router)# network 192.168.10.0 0.0.0.255 area 0 // 配置路由記錄
Router1(config-router)# exit
#----在Router2上啟用OSPF路由協議並配置-------------------
Router2(config)# router ospf 1 // 啟用OSPF路由,並設置進程號為1
Router2(config-router)# router-id 2.2.2.2 // 為Router2配置RID編號
Router2(config-router)# network 192.168.10.0 0.0.0.255 area 0 // 配置路由記錄
Router2(config-router)# network 192.168.20.0 0.0.0.255 area 0
Router2(config-router)# exit
#----在Router3上啟用OSPF路由協議並配置-------------------
Router3(config)# router ospf 1 // 啟用OSPF路由,並設置進程號為1
Router3(config-router)# router-id 3.3.3.3 // 為Router3配置RID編號
Router3(config-router)# network 192.168.20.0 0.0.0.255 area 0
Router3(config-router)# network 192.168.30.0 0.0.0.255 area 0
Router3(config-router)# exit
#----在Router4上啟用OSPF路由協議並配置-------------------
Router3(config)# router ospf 1 // 啟用OSPF路由,並設置進程號為1
Router3(config-router)# router-id 4.4.4.4 // 為Router4配置RID編號
Router3(config-router)# network 192.168.30.0 0.0.0.255 area 0
Router3(config-router)# exit
檢查配置信息: 配置完成后,在Router1
上執行show ip route 命令
查看OSPF配置結果,如下.
Router#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.10.0/24 is directly connected, Serial0/0/0 // C表示是本機默認路由
O 192.168.20.0/24 [110/128] via 192.168.10.2, 00:02:25, Serial0/0/0 // O表示當前是OSPF路由
O 192.168.30.0/24 [110/192] via 192.168.10.2, 00:01:55, Serial0/0/0 // 路由條目是OSPF自動生成的
測試連通性: 此時我們在Router1
路由器上Ping路由器Router4
是可以通信的,說明配置成功了.
Router1#ping 192.168.30.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.30.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 3/15/27 ms
## 實戰:配置RIP企業環境
接下來,我們通過使用三層交換機配合路由器,來實現一個跨網段通信的案例,其配置流程是,首先配置三層交換機並划分好VLAN的層次,接着在配置Router0這里不需要配置VLAN,原因是三層交換機與Router0共享VLAN,最后在配置外網口的Router1路由器,其拓撲結構如下圖所示:
配置三層交換: 首先先來配置三層交換機,創建3個VLAN,並划分成三個VLAN虛擬局域網.
Switch> enable
Switch# configure terminal
#----配置三層交換的VLAN10並把端口fa0/1加入到VLAN-------------------
Switch(config)# vlan 10 // 創建VLAN10
Switch(config-vlan)# interface fa0/1 // 將Fa1倆端口加入到VLAN10
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan 10 // 把端口加入到VLAN10
Switch(config-if-range)# no shutdown // 啟用端口
Switch(config-if-range)# exit
#----配置三層交換的VLAN20並把端口fa0/2加入到VLAN-------------------
Switch(config)# vlan 20
Switch(config-vlan)# interface fa0/2
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan 20
Switch(config-if-range)# no shutdown
Switch(config-if-range)# exit
#----配置三層交換的VLAN30並把端口fa0/3加入到VLAN-------------------
Switch(config)# vlan 30
Switch(config-vlan)# interface fa0/3
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 30
Switch(config-if)# no shutdown
Switch(config-if)# exit
配置三層交換IP地址: 給上面分配好的三個VLAN虛擬局域網一個IP地址,這里指定為各自的網關地址就好.
Switch> enable
Switch# configure terminal
#----給三層交換的VLAN10內的主機添加網關-------------------
Switch(config)# interface vlan 10 // 選擇vlan10接口
Switch(config-if)# ip address 192.168.1.1 255.255.255.0 // 配置網關地址
Switch(config-if)# no shutdown // 開啟端口
Switch(config-if)# exit
#----給三層交換的VLAN20內的主機添加網關-------------------
Switch(config)# interface vlan 20 // 選擇vlan20接口
Switch(config-if)# ip address 192.168.2.1 255.255.255.0 // 配置網關地址
Switch(config-if)# no shutdown // 開啟端口
Switch(config-if)# exit
#----給三層交換的VLAN30內的主機添加網關-------------------
Switch(config)# interface vlan 30 // 選擇vlan30接口
Switch(config-if)# ip address 192.168.3.1 255.255.255.0 // 配置網關地址
Switch(config-if)# no shutdown // 開啟端口
Switch(config-if)# exit
配置路由器Router0: 配置好網關后,接着配置路由器Router0,配置接口IP地址,注意在DCE接口需要配置時鍾.
Router> enable
Router# configure terminal
#----配置路由fa0/0端口的IP地址-------------------
Router0(config)# interface fa0/0
Router0(config-if)# ip address 192.168.3.2 255.255.255.0
Router0(config-if)# no shutdown
Router0(config-if)# exit
#----配置路由fa0/1端口的IP地址-------------------
Router0(config)# interface fa0/1
Router0(config-if)# ip address 192.168.4.1 255.255.255.0
Router0(config-if)# no shutdown
Router0(config-if)# exit
#----配置路由se0/0/0連接外網端口IP----------------
Router0(config)# interface se0/0/0
Router0(config-if)# ip address 1.1.1.1 255.0.0.0
Router0(config-if)# no shutdown
Router0(config-if)# exit
配置路由器Router1: 最后配置外網與內網的銜接路由器Router1,配置好外網口IP地址以及內網口地址.
Router> enable
Router# configure terminal
#----配置路由器1的內網口地址-------------------
Router1(config)# interface se0/0/0
Router1(config-if)# ip address 1.1.1.2 255.0.0.0
Router1(config-if)# no shutdown
Router1(config-if)# exit
#----配置路由器1的外網口地址-------------------
Router1(config)# interface fa0/0
Router1(config-if)# ip address 10.10.10.10 255.0.0.0
Router1(config-if)# no shutdown
開啟三層交換機路由: 開啟三層交換機路由功能,並配置RIP動態路由,指明每個路由器的網段地址.
Switch(config)# ip routing
Switch(config)# router rip
Switch(config-router)# network 192.168.1.0
Switch(config-router)# network 192.168.2.0
Switch(config-router)# network 192.168.3.0
Switch(config-router)# network 192.168.4.0
配置二層路由器RIP: 最后還需要分別配置兩個路由器並開啟其路由功能.
#----配置路由器Router0-------------------
Router0(config)# router rip
Router0(config-router)# network 192.168.3.0
Router0(config-router)# network 192.168.4.0
#----配置路由器Router1-------------------
Router1(config)# route rip
Router1(config-router)# network 192.168.3.0
Router1(config-router)# network 192.168.4.0
Router1(config-router)# network 192.168.4.0
Router1(config-router)# network 1.1.1.1
以上配置流程就是全部的實驗配置過程,在配置完成功能后,我們首先通過使用ping命令來測試內部主機是否能夠Ping通,最后的實驗結果是,內網主機均可以實現通信,外網主機無法和內網主機通信.