前文我們聊到了路由的相關概念和路由基礎方面的話題,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/14947897.html;今天我們聊聊靜態路由相關話題;
回顧:在網絡通信中,兩個路由器要想通信,前提是必須有通往對端的路由;可以說路由是網絡通信的基礎條件;路由有很多種類,不同種類的路由信息其特點,優缺點各不相同;最為簡單的就是直連路由,生成直連路由的必須滿足兩個條件,第一對應接口必須配置ip地址,其次對應接口物理和協議必須處於up狀態;優點是自動生成,管理員只需要把對應接口配置上相應的地址,連上網線,對應直連路由就可以生成;缺點:只能夠到達路由器直連的網絡,不能夠到達非直連的網絡;
實驗:如下圖,配置好各設備的接口ip地址以后,看看對應路由表的變化,看看pc5,pc7以及R1是否能夠ping同pc6?
分析:要想pc5,pc7和R1和pc6通信,首先R1要有去往pc6的路由,其次pc5和pc7的網關指向R1,因為pc6和pc5pc7不在同一網絡(不在同一網絡的設備通信,默認將數據包發送給網關);
未配置R1各接口ip地址前的路由表
<Huawei>dis ip int b *down: administratively down ^down: standby (l): loopback (s): spoofing The number of interface that is UP in Physical is 4 The number of interface that is DOWN in Physical is 0 The number of interface that is UP in Protocol is 1 The number of interface that is DOWN in Protocol is 3 Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 unassigned up down GigabitEthernet0/0/1 unassigned up down GigabitEthernet0/0/2 unassigned up down NULL0 unassigned up up(s) <Huawei>dis ip rou <Huawei>dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 4 Routes : 4 Destination/Mask Proto Pre Cost Flags NextHop Interface 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 <Huawei>
提示:可以看到在未配置接口ip地址前,查看路由表,路由表中只有回環接口的路由信息;查看接口簡要信息也可以發現對應接口的物理狀態是up的,協議狀態是down,不滿足生成直連路由的條件,所以路由表沒有對應接口的路由信息;
配置R1
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R1 [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]ip add 10.0.0.254 24 Jul 2 2021 23:00:05-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. int g0/0/1 [R1-GigabitEthernet0/0/0] [R1-GigabitEthernet0/0/1]ip add 11.0.0.254 24 [R1-GigabitEthernet0/0/1]int g0/0/2 [R1-GigabitEthernet0/0/2]ip add 12.0.0.1 24 Jul 2 2021 23:00:05-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. [R1-GigabitEthernet0/0/2]ip add 12.0.0.1 24 Jul 2 2021 23:00:07-08:00 R1 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP on the interface GigabitEthernet0/0/2 has entered the UP state. [R1-GigabitEthernet0/0/2]q [R1]dis ip int b *down: administratively down ^down: standby (l): loopback (s): spoofing The number of interface that is UP in Physical is 4 The number of interface that is DOWN in Physical is 0 The number of interface that is UP in Protocol is 4 The number of interface that is DOWN in Protocol is 0 Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.0.254/24 up up GigabitEthernet0/0/1 11.0.0.254/24 up up GigabitEthernet0/0/2 12.0.0.1/24 up up NULL0 unassigned up up(s) [R1]dis ip rou [R1]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 13 Routes : 13 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.0/24 Direct 0 0 D 10.0.0.254 GigabitEthernet0/0/0 10.0.0.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 10.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 11.0.0.0/24 Direct 0 0 D 11.0.0.254 GigabitEthernet0/0/1 11.0.0.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 11.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet0/0/2 12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 [R1]
提示:可以看到在r1上的各接口上正確的配置上ip地址信息以后,對應接口的協議狀態就從down轉變為up狀態,同時路由表中也多了對應網絡的路由信息;
配置R2
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R2 [R2]int g0/0/0 [R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24 [R2-GigabitEthernet0/0/0]int g0/0/1 Jul 2 2021 23:05:39-08:00 R2 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. [R2-GigabitEthernet0/0/0]int g0/0/1 [R2-GigabitEthernet0/0/1]ip add 22.0.0.254 24 Jul 2 2021 23:05:40-08:00 R2 %%01IFNET/4/LINK_STATE(l)[3]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. [R2-GigabitEthernet0/0/1]q [R2]dis ip int b *down: administratively down ^down: standby (l): loopback (s): spoofing The number of interface that is UP in Physical is 3 The number of interface that is DOWN in Physical is 1 The number of interface that is UP in Protocol is 3 The number of interface that is DOWN in Protocol is 1 Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 12.0.0.2/24 up up GigabitEthernet0/0/1 22.0.0.254/24 up up GigabitEthernet0/0/2 unassigned down down NULL0 unassigned up up(s) [R2]dis ip rout [R2]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 10 Routes : 10 Destination/Mask Proto Pre Cost Flags NextHop Interface 12.0.0.0/24 Direct 0 0 D 12.0.0.2 GigabitEthernet0/0/0 12.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 22.0.0.0/24 Direct 0 0 D 22.0.0.254 GigabitEthernet0/0/1 22.0.0.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 22.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 [R2]
提示:按照題意我們配置好了兩個路由器的名稱和相關接口的ip地址,對應路由器各自都生成了相應的直連路由;
配置好各pc的ip地址信息,然后用pc5ping pc6看看是否可以正常通信?
配置pc5
提示:pc5和R1的g0/0/0口是直連,所以對應pc5的網關必須指向R1的g0/0/0接口的ip地址;
配置pc6
提示:pc6和R2的g0/0/1口是直連,所以對應pc6的網關必須指向R2的g0/0/1接口的ip地址;
配置pc7
提示:pc7和R1的g0/0/1口是直連,所以對應pc7的網關必須指向R1的g0/0/1接口的ip地址;
驗證:pc5 ping pc6看看是否可以通信?
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fe54:5adc IPv6 address......................: :: / 128 IPv6 gateway......................: :: IPv4 address......................: 10.0.0.1 Subnet mask.......................: 255.255.255.0 Gateway...........................: 10.0.0.254 Physical address..................: 54-89-98-54-5A-DC DNS server........................: PC>ping 22.0.0.1 Ping 22.0.0.1: 32 data bytes, Press Ctrl_C to break Request timeout! Request timeout! Request timeout! Request timeout! Request timeout! --- 22.0.0.1 ping statistics --- 5 packet(s) transmitted 0 packet(s) received 100.00% packet loss PC>
提示:可以看到在pc5上ping pc6,給我們的回饋是請求超時;
在r1的g0/0/2口抓包,看看對應是否有數據包通過?
提示:可以看到在R1的g0/0/2口上沒有抓到任何數據包,說明ping22.0.0.1的數據包沒有在r1和r2直連鏈路上通過,所以我們ping pc6回饋給我們的是請求超時,其原因是R1上沒有去往pc6的路由,當R1收到pc5發來的數據包,查看對應數據包是去往22.0.0.1的,R1在自己的路由表中沒有匹配到去往22.0.0.1的路由,所以R1直接將對應數據包丟棄,不予轉發;
驗證:用pc5 ping pc7 看看是否能夠正常通信?
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fe54:5adc IPv6 address......................: :: / 128 IPv6 gateway......................: :: IPv4 address......................: 10.0.0.1 Subnet mask.......................: 255.255.255.0 Gateway...........................: 10.0.0.254 Physical address..................: 54-89-98-54-5A-DC DNS server........................: PC>ping 11.0.0.1 Ping 11.0.0.1: 32 data bytes, Press Ctrl_C to break Request timeout! From 11.0.0.1: bytes=32 seq=2 ttl=127 time=16 ms From 11.0.0.1: bytes=32 seq=3 ttl=127 time=16 ms From 11.0.0.1: bytes=32 seq=4 ttl=127 time=16 ms From 11.0.0.1: bytes=32 seq=5 ttl=127 time<1 ms --- 11.0.0.1 ping statistics --- 5 packet(s) transmitted 4 packet(s) received 20.00% packet loss round-trip min/avg/max = 0/12/16 ms PC>
提示:可以看到pc5 是可以正常和pc7通信;其實原因很簡單,就是因為R1上有對應去往pc7和pc5的直連路由,所以pc5和pc7可以正常通信;通過上述實驗,可以看到直連路由的優點是它自動生成,只要管理員正確配置了ip地址,並且在接口上接上了線,對應直連路由就會自動生成了;缺點就是不能和非直連的網絡通信;這樣一來我們要想和非直連網絡通信,光憑直連路由是做不到;
靜態路由
所謂靜態路由就是指管理員人工手動添加的路由信息;
添加靜態路由的命令語法
ip route-static 目標網絡 子網掩碼/前綴 下一跳地址/出接口
提示:如果出接口為以太網接口,則必須要指定下一跳地址,如果出接口為串口,可以使用下一跳或出接口來配置;
實驗:還是上面的top,實現pc5能夠ping 通pc6
在R1上添加靜態路由
驗證:現在R1上有去往pc6的路由信息,用pc 5ping pc6 看看是否可以正常通信?
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fe54:5adc IPv6 address......................: :: / 128 IPv6 gateway......................: :: IPv4 address......................: 10.0.0.1 Subnet mask.......................: 255.255.255.0 Gateway...........................: 10.0.0.254 Physical address..................: 54-89-98-54-5A-DC DNS server........................: PC>ping 22.0.0.1 Ping 22.0.0.1: 32 data bytes, Press Ctrl_C to break Request timeout! Request timeout! Request timeout! Request timeout! Request timeout! --- 22.0.0.1 ping statistics --- 5 packet(s) transmitted 0 packet(s) received 100.00% packet loss PC>
提示:可以看到pc5現在依然ping 不通pc6;
在r1的g0/0/2口抓包,看看是否有對應數據包通過?
提示:現在在R1的g0/0/2口可以抓到pc5 ping pc 6的包,但是沒有pc6 回來的包,其原因是R2上沒有到達pc5所在網絡的路由;所以pc5 ping 不同pc6;
在R2上添加去往pc5的路由
驗證:現在用pc5再次ping pc6看看是否能通?
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fe54:5adc IPv6 address......................: :: / 128 IPv6 gateway......................: :: IPv4 address......................: 10.0.0.1 Subnet mask.......................: 255.255.255.0 Gateway...........................: 10.0.0.254 Physical address..................: 54-89-98-54-5A-DC DNS server........................: PC>ping 22.0.0.1 Ping 22.0.0.1: 32 data bytes, Press Ctrl_C to break Request timeout! From 22.0.0.1: bytes=32 seq=2 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=3 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=4 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=5 ttl=126 time=16 ms --- 22.0.0.1 ping statistics --- 5 packet(s) transmitted 4 packet(s) received 20.00% packet loss round-trip min/avg/max = 0/16/16 ms PC>
提示:可以看到pc5可以正常ping 通pc6了;
驗證:在R1的g0/0/2口抓包,看看對應數據包是否有回復了?
提示:可以看到現在在R1的g0/0/2口抓包就有正常回復包;
驗證:pc7 ping pc6,看看是否能夠ping通?
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fe99:6332 IPv6 address......................: :: / 128 IPv6 gateway......................: :: IPv4 address......................: 11.0.0.1 Subnet mask.......................: 255.255.255.0 Gateway...........................: 11.0.0.254 Physical address..................: 54-89-98-99-63-32 DNS server........................: PC>ping 22.0.0.1 Ping 22.0.0.1: 32 data bytes, Press Ctrl_C to break Request timeout! Request timeout! Request timeout! Request timeout! Request timeout! --- 22.0.0.1 ping statistics --- 5 packet(s) transmitted 0 packet(s) received 100.00% packet loss PC>
提示:可以看到pc7到現在依然無法Ping通pc6,其原因是r2沒有回來pc7的路由,所以pc7現在能夠把包送達到pc6,但回不來,所以導致pc7ping不同pc6;要想實現pc7ping通pc6,我們還需要在r2上添加一條去往pc7的路由;
在R2上添加去往pc7的路由
驗證:現在pc7 ping pc6,看看是否可以正常通信?
PC>ipconfig Link local IPv6 address...........: fe80::5689:98ff:fe99:6332 IPv6 address......................: :: / 128 IPv6 gateway......................: :: IPv4 address......................: 11.0.0.1 Subnet mask.......................: 255.255.255.0 Gateway...........................: 11.0.0.254 Physical address..................: 54-89-98-99-63-32 DNS server........................: PC>ping 22.0.0.1 Ping 22.0.0.1: 32 data bytes, Press Ctrl_C to break From 22.0.0.1: bytes=32 seq=1 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=2 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=3 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=4 ttl=126 time=16 ms From 22.0.0.1: bytes=32 seq=5 ttl=126 time=16 ms --- 22.0.0.1 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 16/16/16 ms PC>
提示:可以看到pc7現在也能正常ping通pc6;通過上述實驗我們發現靜態路由的配置還是很簡單,必須手動指定目標網絡,掩碼以及下一跳;其次網絡通信的過程是是雙向的,配置靜態路由,我們必須考慮來回的路由在所經過的路由器都要有對應的路由;如果網絡規模非常大(網段特別多,路由器特別多),如果用手動配置靜態路由的方式,就不是很容易了;所以靜態路由適用於網絡規模不是太大的環境中;除此之外靜態路由有一個非常大的缺點,它不能根據top變化而變化,這樣一來,如果現網中某個接口地址的發生變化,管理員必須手動更改路由信息;
負載分擔
負載分擔就是等價路由即到達同一目標網絡的路由有多條,並且他們的優先級開銷都一樣;
實驗:如下圖,配置pc5和pc6通信的流量都可以走R1,R2之間的兩條鏈路
在R1的g0/0/1接口上配置對應的ip地址,並配置訪問pc6的對應路由信息
<R1>sys Enter system view, return user view with Ctrl+Z. [R1]int g0/0/1 [R1-GigabitEthernet0/0/1]ip add 21.0.0.1 24 [R1-GigabitEthernet0/0/1]q [R1]ip route-s 22.0.0.1 32 21.0.0.2 [R1]dis ip routin [R1]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 14 Routes : 15 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.0/24 Direct 0 0 D 10.0.0.254 GigabitEthernet0/0/0 10.0.0.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 10.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 12.0.0.0/24 Direct 0 0 D 12.0.0.1 GigabitEthernet0/0/2 12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 21.0.0.0/24 Direct 0 0 D 21.0.0.1 GigabitEthernet0/0/1 21.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 21.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 22.0.0.1/32 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/2 Static 60 0 RD 21.0.0.2 GigabitEthernet0/0/1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 [R1]
在R2的g0/0/2接口上配置對應的ip地址,並配置訪問pc5的對應路由信息
<R2>sys Enter system view, return user view with Ctrl+Z. [R2]int g0/0/2 [R2-GigabitEthernet0/0/2]ip add 21.0.0.2 24 Jul 3 2021 00:34:04-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/2 has entered the UP state. [R2-GigabitEthernet0/0/2]q [R2]ip route-s 10.0.0.1 32 21.0.0.1 [R2]dis ip routing [R2]dis ip routing-table Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Routing Tables: Public Destinations : 15 Routes : 16 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.1/32 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0 Static 60 0 RD 21.0.0.1 GigabitEthernet0/0/2 11.0.0.1/32 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0 12.0.0.0/24 Direct 0 0 D 12.0.0.2 GigabitEthernet0/0/0 12.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 12.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0 21.0.0.0/24 Direct 0 0 D 21.0.0.2 GigabitEthernet0/0/2 21.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 21.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2 22.0.0.0/24 Direct 0 0 D 22.0.0.254 GigabitEthernet0/0/1 22.0.0.254/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 22.0.0.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1 127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0 127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0 127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0 [R2]
提示:這樣配置以后,pc5所在網絡和pc6所在網絡的設備通信就有兩條鏈路一起負載,這樣可以減少之前一條鏈路的壓力;
驗證:用tracert 追蹤pc5和pc6通信所走的鏈路
提示:從上面的鏈路追蹤和抓包可以看到現在pc5和pc6通信,兩條鏈路都用上了,pc5pingpc6走下面21網段,回復包全部走12網段所在鏈路,pc6pingpc5 去走12網段所在鏈路,回來走21網段所在鏈路;
浮動路由
浮動路由又稱主備路由,即去往同一網絡的多條路由中有主備之分,默認情況主路由工作(活動路由),一旦活動路由宕掉,備份路由馬上就變為活動路由;一旦主路由恢復,備份路由又會處於非活動狀態;有點類似keepalived的搶占模式,一旦主掛了,備份路由馬上變為主,一旦原來的主活了,現在的主馬上就變為備份路由;其原理就是在等價路由的基礎上,借助路由器轉發原則根據其優先級來確定那條路由存在路由表(最優路由),一旦存在路由表中的最優路由鏈路宕掉,對應接口也會隨之宕掉,所以對應最優路由來說,其出接口就會變為unknow狀態,導致路由不可用,此時根據路由轉發原則,原來的次優路由就會變為最優路由,一旦優先級最小的路由所在鏈路恢復正常,路由器又會根據路由轉發原則把次優路由替換下來,讓其處於非活動狀態;
實驗:還是上述top,在R1上配置12網段所在鏈路為主鏈路,21網段為備份鏈路
配置r1
[R1]dis 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 22.0.0.1/32 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/2 Static 60 0 RD 21.0.0.2 GigabitEthernet0/0/1 Static routing table status : <Inactive> Destinations : 0 Routes : 0 [R1]ip rou [R1]ip route-s 22.0.0.1 32 21.0.0.2 pre 61 Info: Succeeded in modifying route. [R1]dis 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 22.0.0.1/32 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/2 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 22.0.0.1/32 Static 61 0 R 21.0.0.2 GigabitEthernet0/0/1 [R1]
提示:在R1上修改原有去往22.0.0.1 下一跳為21.0.0.2 的路由的優先級為61,此時對應路由器來說,去往22.0.0.1的兩條路由就不再是等價路由,所以下一跳為12.0.0.2的路由就會被選為最優路由,下一跳為21.0.0.2的路由就會被選為次優非活動路由;這里需要提醒的是以上路由只是針對r1,對r2來說,它的路由還是等價路由,並不會改變;
配置R2,12網段所在鏈路為備份鏈路,21網段為主鏈路
[R2]dis ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 2 Routes : 3 Configured Routes : 3 Static routing table status : <Active> Destinations : 2 Routes : 3 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.1/32 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0 Static 60 0 RD 21.0.0.1 GigabitEthernet0/0/2 11.0.0.1/32 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0 Static routing table status : <Inactive> Destinations : 0 Routes : 0 [R2]ip route-s 10.0.0.1 32 12.0.0.1 pre 61 Info: Succeeded in modifying route. [R2]dis ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 2 Routes : 3 Configured Routes : 3 Static routing table status : <Active> Destinations : 2 Routes : 2 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.1/32 Static 60 0 RD 21.0.0.1 GigabitEthernet0/0/2 11.0.0.1/32 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 10.0.0.1/32 Static 61 0 R 12.0.0.1 GigabitEthernet0/0/0 [R2]
驗證:在R1上把12網段所在接口宕掉,看看對應的備份路由是否會成為活動路由?
<R1>sys Enter system view, return user view with Ctrl+Z. [R1]dis ip int b *down: administratively down ^down: standby (l): loopback (s): spoofing The number of interface that is UP in Physical is 4 The number of interface that is DOWN in Physical is 0 The number of interface that is UP in Protocol is 4 The number of interface that is DOWN in Protocol is 0 Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.0.254/24 up up GigabitEthernet0/0/1 21.0.0.1/24 up up GigabitEthernet0/0/2 12.0.0.1/24 up up NULL0 unassigned up up(s) [R1]int g0/0/2 [R1-GigabitEthernet0/0/2]shutdow Jul 3 2021 01:22:12-08:00 R1 %%01IFPDT/4/IF_STATE(l)[0]:Interface GigabitEthernet0/0/2 has turned into DOWN state. [R1-GigabitEthernet0/0/2] [R1-GigabitEthernet0/0/2] Jul 3 2021 01:22:13-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/2 has entered the DOWN state. [R1-GigabitEthernet0/0/2]q [R1]dis 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 22.0.0.1/32 Static 61 0 RD 21.0.0.2 GigabitEthernet0/0/1 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 22.0.0.1/32 Static 60 0 12.0.0.2 Unknown [R1]
提示:可以看到R1上的g0/0/2接口宕掉以后,對應活動路由變成了非活動路由,原來的非活動路由變成了活動路由;當然路由的變化也意味着其數據包的走向也發生了變化,從而實現鏈路切換;
恢復R1上的g0/0/2接口,看看對應路由變化
[R1-GigabitEthernet0/0/2]undo shutdown [R1-GigabitEthernet0/0/2] Jul 3 2021 01:26:52-08:00 R1 %%01IFPDT/4/IF_STATE(l)[2]:Interface GigabitEthernet0/0/2 has turned into UP state. [R1-GigabitEthernet0/0/2] Jul 3 2021 01:26:52-08:00 R1 %%01IFNET/4/LINK_STATE(l)[3]:The line protocol IP on the interface GigabitEthernet0/0/2 has entered the UP state. [R1-GigabitEthernet0/0/2]q [R1]dis 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 22.0.0.1/32 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/2 Static routing table status : <Inactive> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 22.0.0.1/32 Static 61 0 R 21.0.0.2 GigabitEthernet0/0/1 [R1]
提示:可以看到當接口恢復,對應活動路由又會變為非活動路由,實現了鏈路和路由的切換;當然對於r2也是同樣的原理;從某種意義上我們可以理解浮動路由其實就是鏈接的高可用;
缺省路由
從上面的實驗和配置過程來看,使用靜態路由,必須在對應路由器上配置上數據包來回的路由,如果沒有對應網段的路由,則我們就不能夠正常訪問對應的目標網絡;這樣一來我們如果要訪問的網絡非常多,比如互聯網,我們不能也不應該把全互聯網所有路由都寫進路由器,即便可以,運營商和互聯網的路由非常多,一般路由器也存不下,為了解決這樣的問題,缺省路由就可以派上用場了;所謂缺省路由是指,在路由表中,所有未被匹配的路由,都可以被缺省路由所匹配;缺省路由以0.0.0.0為目標網絡,掩碼為0.0.0.0或前綴為0 來表示匹配任意目標網絡;根據路由器的轉發原則,掩碼最長匹配優先,缺省路由的優先級是最低的,即最后才會被匹配;缺省路由的作用是減少路由條目,減輕路由器查找匹配路由的壓力;通常用於末梢網絡,比如家庭上網,企業出口;缺省路由可以靜態配置,也可通過動態路由協議發布;
實驗:靜態配置缺省路由,實現pc5和pc6互通
配置R1
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R1 [R1]int g0/0/0 [R1-GigabitEthernet0/0/0]ip add 10.0.0.254 24 [R1-GigabitEthernet0/0/0]int g0/0/1 [R1-GigabitEthernet0/0/1]ip add 12.0.0.1 24 Jul 3 2021 01:55:33-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. [R1-GigabitEthernet0/0/1]ip add 12.0.0.1 24 [R1-GigabitEthernet0/0/1]q [R1]ip route-s 0.0.0.0 0 12.0.0.2 Jul 3 2021 01:55:33-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. [R1]ip route-s 0.0.0.0 0 12.0.0.2 [R1]dis ip routing-table pro static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 1 Routes : 1 Configured Routes : 1 Static routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 Static 60 0 RD 12.0.0.2 GigabitEthernet0/0/1 Static routing table status : <Inactive> Destinations : 0 Routes : 0 [R1]
配置R2
<Huawei>sys Enter system view, return user view with Ctrl+Z. [Huawei]sys R2 [R2]int g0/0/0 [R2-GigabitEthernet0/0/0]ip add 12.0.0.2 24 [R2-GigabitEthernet0/0/0]int g0/0/1 [R2-GigabitEthernet0/0/1]ip add 22.0.0.254 Jul 3 2021 01:55:45-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP on the interface GigabitEthernet0/0/0 has entered the UP state. [R2-GigabitEthernet0/0/1]ip add 22.0.0.254 24 [R2-GigabitEthernet0/0/1]q [R2]ip route-s 0.0.0.0 0 12.0.0.1 Jul 3 2021 01:55:45-08:00 R2 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP on the interface GigabitEthernet0/0/1 has entered the UP state. [R2]ip route-s 0.0.0.0 0 12.0.0.1 [R2]dis ip routing-table protocol static Route Flags: R - relay, D - download to fib ------------------------------------------------------------------------------ Public routing table : Static Destinations : 1 Routes : 1 Configured Routes : 1 Static routing table status : <Active> Destinations : 1 Routes : 1 Destination/Mask Proto Pre Cost Flags NextHop Interface 0.0.0.0/0 Static 60 0 RD 12.0.0.1 GigabitEthernet0/0/0 Static routing table status : <Inactive> Destinations : 0 Routes : 0 [R2]
驗證:用pc5 ping pc6 看看是否可以互通?
提示:可以看到配置缺省靜態路由以后,pc5是可以正常和pc6通信;同樣的原理,pc6也是可以正常和pc5通信;有了缺省路由我們只需要寫一條了路由,即可匹配任意路由;這里需要提醒一下,缺省路由一般用於末梢網絡,如果不是末梢網絡的路由器,需要結合靜態明細路由或動態路由;