直連路由的不足 不能去往非本身直連的其餘網段(地方)
非直連路由:須要靜態路由或動態路由,將網段添加到路由表中
問題?AR1上沒有到達以下的網段路由網絡
23.1.1.0/24 2.2.2.2/32 3.3.3.3/32
靜態路由通常適用於結構簡單的網絡。不過,即便是在複雜網絡環境中,合理地配置一些靜態路由也能夠改進網絡的性能
ide
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 查看路由表中的靜態路由
注意: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.3學習
ip 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沒法迴應數據code
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網段是本身的直連,所以把數據包交給R1blog
<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>
AR1的配置:接口
ip route-static 3.3.3.3 255.255.255.255 12.1.1.2
AR2的配置:ip
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
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
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以下配置:
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協議