爲什麼需要非直連路由
直連路由的不足 不能去往非自己直連的其他網段(地方)
非直連路由:需要靜態路由或動態路由,將網段添加到路由表中
問題?AR1上沒有到達如下的網段路由
23.1.1.0/24
2.2.2.2/32
3.3.3.3/32
靜態路由應用場景
- 靜態路由是指由管理員手動配置和維護的路由
- 靜態路由配置簡單,無需像動態路由那樣佔用路由器的CPU資源來計算和分析路由更新
-
靜態路由一般適用於結構簡單的網絡。不過,即使是在複雜網絡環境中,合理地配置一些靜態路由也可以改進網絡的性能
靜態路由語法格式
A. [Huawei]ip route-static 目標網段 目標網段掩碼 下一跳 B. [Huawei]ip route-static 目標網段 目標網段掩碼 出接口 C. [Huawei]ip route-static 目標網段 目標網段掩碼 出接口 下一跳 推薦使用該方式
[R1]ip route-static 23.1.1.0 24 12.1.1.2(下一跳) 串行鏈路 [R1]ip route-static 23.1.1.0 24 GigabitEthernet 0/0/0(出接口) 以太網 [R1]ip route-static 23.1.1.0 24 GigabitEthernet 0/0/0 12.1.1.2(出接口+下一跳)
目標網段:目標網段
目標網段掩碼:掩碼 可以寫255.255.255.0 或者24
下一跳:到達目的地的下一站[R1]display ip routing-table protocol static 查看路由表中的靜態路由
實戰演練通過靜態路由實現網絡互通
在R1上面訪問3.3.3.3路由,該如何實現?ping 3.3.3.3
注意:ping 3.3.3.3 SIP:12.1.1.1 DIP:3.3.3.3
因爲R1配置接口IP地址後,只有12.1.1.0/24和1.1.1.1/32的直連路由,沒有去往目標3.3.3.3的非直連路由,那麼,我們可以在R1上面配置如下靜態路由到達3.3.3.3ip route-static 3.3.3.3 255.255.255.255 g0/0/0 12.1.1.2
配置完成後,R1上面ping 3.3.3.3 發現無法ping通
因爲數據在傳遞的過程中,R1發現到達3.3.3.3得下一跳是12.1.1.2 是R2設備,那麼R1會把這個數據傳遞給R2設備,此時R2設備上沒有到達3.3.3.3的路由,R2設備會丟棄這個報文
那我們可以在R2上面寫靜態路由,使其到達3.3.3.3路由ip route-static 3.3.3.3 255.255.255.255 g0/0/1 23.1.1.3
配置完成後,R1上面ping 3.3.3.3 發現無法ping通
因爲數據在傳遞的過程中,R1發現到達3.3.3.3得下一跳是12.1.1.2 是R2設備,那麼R1會把這個數據傳遞給R2設備,R2設備到達3.3.3.3的下一跳是23.1.1.3 是R3設備,而3.3.3.3路由剛好是R3自身的直連路由,所以,R3會接收這個數據。
但是,數據在傳遞過程中,數據既可以發過去,數據也要能夠回來,即發數據是R1到R3 回數據是R3到R1 由於R3上面沒有到達12.1.1.0/24網段的路由,所以R3無法迴應數據ip route-static 12.1.1.0 255.255.255.255 g0/0/1 23.1.1.2
在R3上面寫完到達23.1.1.0的路由條目後,會把迴應的數據包交給R2,R2發現到達12.1.1.0網段是自己的直連,因此把數據包交給R1
<R1>ping 3.3.3.3 PING 3.3.3.3: 56 data bytes, press CTRL_C to break Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=40 ms Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=50 ms Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=20 ms Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=40 ms --- 3.3.3.3 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 20/36/50 ms <R1>
思考如下:如果在R1上面ping -a 1.1.1.1 3.3.3.3 能夠ping通麼?
AR1的配置:
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
AR2的配置:
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
AR3的配置:
ip route-static 1.1.1.1 255.255.255.255 23.1.1.2
AR2的配置:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
測試如下:
<R1>ping -a 1.1.1.1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=40 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/34/40 ms
思考如下:如果在R1上面ping -a 1.1.1.1 2.2.2.2能夠ping通麼?
AR1的配置:
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
AR2的配置:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
測試如下:
<R1>ping -a 1.1.1.1 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=140 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=20 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=30 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/50/140 ms
思考如下:如果R2訪問ping -a 2.2.2.2 3.3.3.3能夠ping通麼?
AR2的配置:
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
AR3的配置:
ip route-static 2.2.2.2 255.255.255.255 23.1.1.2
測試如下:
<R2>ping -a 2.2.2.2 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=255 time=70 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=255 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=255 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/38/70 ms
思考如下:如果要想實現全網互通?需要在AR1 2 3設備上面分別寫幾條靜態路由
AR1如下配置:
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
ip route-static 23.1.1.0 255.255.255.0 12.1.1.2
AR2如下配置:
ip route-static 1.1.1.1 255.255.255.255 12.1.1.1
ip route-static 3.3.3.3 255.255.255.255 23.1.1.3
AR3如下配置:
ip route-static 1.1.1.1 255.255.255.255 23.1.1.2
ip route-static 12.1.1.0 255.255.255.255 23.1.1.2
ip route-static 2.2.2.2 255.255.255.255 23.1.1.2
測試如下:
<R1>ping 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=10 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 10/24/30 ms
<R1>ping 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=20 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/32/50 ms
<R1>ping 23.1.1.3
PING 23.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=2 ttl=254 time=40 ms
Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=40 ms
Reply from 23.1.1.3: bytes=56 Sequence=4 ttl=254 time=50 ms
Reply from 23.1.1.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 23.1.1.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/40/50 ms
<R1>ping -a 1.1.1.1 2.2.2.2
PING 2.2.2.2: 56 data bytes, press CTRL_C to break
Reply from 2.2.2.2: bytes=56 Sequence=1 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=2 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=3 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=4 ttl=255 time=30 ms
Reply from 2.2.2.2: bytes=56 Sequence=5 ttl=255 time=20 ms
--- 2.2.2.2 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 20/28/30 ms
<R1>ping -a 1.1.1.1 3.3.3.3
PING 3.3.3.3: 56 data bytes, press CTRL_C to break
Reply from 3.3.3.3: bytes=56 Sequence=1 ttl=254 time=50 ms
Reply from 3.3.3.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 3.3.3.3: bytes=56 Sequence=5 ttl=254 time=30 ms
--- 3.3.3.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/34/50 ms
<R1>ping -a 1.1.1.1 23.1.1.3
PING 23.1.1.3: 56 data bytes, press CTRL_C to break
Reply from 23.1.1.3: bytes=56 Sequence=1 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=2 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=3 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=4 ttl=254 time=30 ms
Reply from 23.1.1.3: bytes=56 Sequence=5 ttl=254 time=40 ms
--- 23.1.1.3 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 30/32/40 ms
<R1>
什麼是默認路由
默認路由一般來末節點配置 好處就是僅僅用一條路由代替所有路由條目
[Huawei]ip route-static 0.0.0.0 0 下一跳
R1的配置
ip route-static 2.2.2.2 255.255.255.255 12.1.1.2
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
ip route-static 23.1.1.0 255.255.255.0 12.1.1.2
簡化本R1的配置
ip route-static 0.0.0.0 0 12.1.1.2 代表R1想要去往任何非直連路由都把數據包交給R2設備
簡化本R3的配置
ip route-static 0.0.0.0 0.0.0.0 23.1.1.2 代表R3想要去往任何非直連路由都把數據包交給R2設備
思考如下:爲什麼R2上面不能寫默認路由?寫了之後有什麼問題出現?
因爲R2設備處於R1和R3之間,如果在R2上面寫默認路由
ip route-static 0.0.0.0 0 12.1.1.1
ip route-static 0.0.0.0 0 23.1.1.3
如果此時R1想要訪問3.3.3.3,R1把數據包丟給R2的時候,R2此時有兩個下一跳 一個是R1 一個是R3 那R2到底是丟給R1呢還是R3呢?所以,R2上面建議大家寫明細路由,不要寫默認路由
靜態路由使用出接口和下一跳的場景
靜態路由使用出接口的場景
在串行接口上,可以通過指定下一跳地址或出接口或出接口+下一跳來配置靜態路由
[RTA]ip route-static 192.168.2.0 24 10.0.12.2
[RTA]ip route-static 192.169.2.0 24 s1/0/0
[RTA]ip route-static 192.169.2.0 24 s1/0/0 10.0.12.2
靜態路由使用下一跳的場景
在廣播型的接口(如以太網接口)上配置靜態路由時,必須要指定下一跳地址
[RTA]ip route-static 192.168.2.0 24 10.0.123.2
[RTA]ip route-static 192.169.2.0 24 G0/0/0 10.0.123.2
思考一下?爲什麼不能用出接口呢?
靜態路由的負載分擔
AR1上訪問2.2.2.2的時候,可以通過路徑AR1-AR3-AR2 或者AR1-AR4-AR2 的負載分擔
AR1的配置:
ip route-static 2.2.2.2 255.255.255.255 13.1.1.3
ip route-static 2.2.2.2 255.255.255.255 14.1.1.4
查看AR1的路由表
<R1>display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 2
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet
0/0/0
Static 60 0 RD 14.1.1.4 GigabitEthernet
0/0/1
Static routing table status : <Inactive>
Destinations : 0 Routes : 0
<R1>
測試一下,利用tracert進行路由追蹤
<R1>tracert -a 1.1.1.1 2.2.2.2
traceroute to 2.2.2.2(2.2.2.2), max hops: 30 ,packet length: 40,press CTRL_C t
o break
1 13.1.1.3 130 ms 20 ms 14.1.1.4 30 ms
2 24.1.1.2 30 ms 20 ms 30 ms
<R1>tracert -a 1.1.1.1 2.2.2.2
traceroute to 2.2.2.2(2.2.2.2), max hops: 30 ,packet length: 40,press CTRL_C t
o break
1 14.1.1.4 140 ms 20 ms 10 ms
2 24.1.1.2 100 ms 20 ms 20 ms
<R1>
什麼是浮動路由
浮動路由就是隻讓主鏈路進行工作,備鏈路不讓轉發流量
當主鏈路出現問題的時候,路由器會選擇備用的鏈路,當主鏈路恢復的時候 路由器會選擇主鏈路
在AR1上面的配置:
ip route-static 2.2.2.2 255.255.255.255 13.1.1.3 默認優先級是60
ip route-static 2.2.2.2 255.255.255.255 14.1.1.4 preference 70
查看AR1的路由表
[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet
0/0/0
Static routing table status : <Inactive>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 70 0 R 14.1.1.4 GigabitEthernet
0/0/1
[R1]
當AR1的主鏈路down時候
[R1-GigabitEthernet0/0/0]shutdown
Nov 16 2019 12:27:14-08:00 R1 %%01IFPDT/4/IF_STATE(l)[8]:Interface GigabitEthern
et0/0/0 has turned into DOWN state.
[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 70 0 RD 14.1.1.4 GigabitEthernet
0/0/1
Static routing table status : <Inactive>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 13.1.1.3 Unknown
[R1]
當AR1的主用鏈路恢復正常時
[R1-GigabitEthernet0/0/0]undo shutdown
Nov 16 2019 12:28:25-08:00 R1 %%01IFPDT/4/IF_STATE(l)[10]:Interface GigabitEther
net0/0/0 has turned into UP state.
[R1]display ip routing-table protocol static
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
Destinations : 1 Routes : 2 Configured Routes : 2
Static routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 60 0 RD 13.1.1.3 GigabitEthernet
0/0/0
Static routing table status : <Inactive>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
2.2.2.2/32 Static 70 0 R 14.1.1.4 GigabitEthernet
0/0/1
[R1]
靜態路由不足
靜態路由---不能動態的根據現網拓撲的改變而改變
能不能開發一款協議出來,讓網絡設備之間進行交換各種路由網段協議呢?
於是在早期提出了rip協議 因爲當時的網絡結構比較簡單,RIP協議能夠很有的勝任,而現在網絡結構比較龐大,RIP協議已經不能滿足於現在的網絡當中,所以我們企業網絡中普遍都是OSPF路由協議,RIP協議我們現在只是作爲一個學習的一個協議而已,現網中幾乎不用RIP協議