主頁 >  其他 > HCNA Routing&Switching之靜態路由

HCNA Routing&Switching之靜態路由

2021-07-03 06:30:00 其他

  前文我們聊到了路由的相關概念和路由基礎方面的話題,回顧請參考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通信;有了預設路由我們只需要寫一條了路由,即可匹配任意路由;這里需要提醒一下,預設路由一般用于末梢網路,如果不是末梢網路的路由器,需要結合靜態明細路由或動態路由;

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/288883.html

標籤:其他

上一篇:使用AVPro Video在Unity中播放開場視頻(CG)筆記

下一篇:C語言——簡單的走迷宮小游戲(無指標,無鏈表,無......!!!)

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more