1. 程式人生 > >NETWORK筆記9:預設路由與浮動路由

NETWORK筆記9:預設路由與浮動路由

預設路由:一種特殊的靜態路由,只有從路由表中找不到任何明確匹配的路由條目時,才會使用預設路由。(當訪問Internet時,一些網路出口只有一個,此時沒有必要配置)

浮動路由:配置一個管理距離更大的靜態路由,作為應急出發的備份路徑,在主路由有效的情況下,浮動路由不會出現在路由表中。


實驗名稱:華為路由器配置靜態路由預設路由實現全網互通

實驗拓撲圖:

image.png

實驗步驟:PC配置IP子網掩碼閘道器

                 路由器配置介面和靜態路由

                 驗證

實驗結果:實現全網互通為浮動路由做準備

實驗命令:

R1

<Huawei>system-view 

Enter system view, return user view with Ctrl+Z.

[Huawei]sysname R1

[R1]interface GigabitEthernet 0/0/0

[R1-GigabitEthernet0/0/0]undo shutdown 

Info: Interface GigabitEthernet0/0/0 is not shutdown.

[R1-GigabitEthernet0/0/0]ip address 192.168.1.254 255.255.255.0

[R1-GigabitEthernet0/0/0]quit

[R1]interface GigabitEthernet 0/0/1

[R1-GigabitEthernet0/0/1]undo shutdown 

Info: Interface GigabitEthernet0/0/1 is not shutdown.

[R1-GigabitEthernet0/0/1]ip address 192.168.2.1 255.255.255.0

[R1-GigabitEthernet0/0/1]quit

[R1]ip route-static 0.0.0.0 0.0.0.0 192.168.2.2       //ip 路由-靜態 (預設路由或預設路由一種特殊的靜態路由!)

[R1]display ip routing-table        #顯示 IP 路由-表 

Route Flags: R - relay, D - download to fib

      標記                    下載   到 路由表

------------------------------------------------------------------------------

Routing Tables: Public

         Destinations : 11       Routes : 11       


Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

目標地址   掩碼     協議                         下一跳          介面 

        0.0.0.0/0   Static  60   0          RD   192.168.2.2     GigabitEthernet

0/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

    192.168.1.0/24  Direct  0    0           D   192.168.1.254   GigabitEthernet

0/0/0               直連

  192.168.1.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/0

  192.168.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/0

    192.168.2.0/24  Direct  0    0           D   192.168.2.1     GigabitEthernet

0/0/1

    192.168.2.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/1

  192.168.2.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/1

255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0


R2

<Huawei>sysn

<Huawei>sys

<Huawei>system-view 

Enter system view, return user view with Ctrl+Z.

[Huawei]sysname R2

[R2]interface GigabitEthernet 0/0/0

[R2-GigabitEthernet0/0/0]undo shutdown 

Info: Interface GigabitEthernet0/0/0 is not shutdown.

[R2-GigabitEthernet0/0/0]ip address 192.168.2.2 255.255.255.0

Nov 19 2018 19:09:16-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/0]quit

[R2]interface GigabitEthernet 0/0/1

[R2-GigabitEthernet0/0/1]undo shutdown 

Info: Interface GigabitEthernet0/0/1 is not shutdown.

[R2-GigabitEthernet0/0/1]ip address 192.168.3.1 255.255.255.0

Nov 19 2018 19:10:00-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-GigabitEthernet0/0/1]quit 

[R2]ip route-static 192.168.1.0 255.255.255.0 192.168.2.1        //#IP 路由-靜態 目標網路ID 子網掩碼 下一跳埠

[R2]ip route-static 192.168.4.0 255.255.255.0 192.168.3.2

[R2]display ip routing-table 

Route Flags: R - relay, D - download to fib

------------------------------------------------------------------------------

Routing Tables: Public

         Destinations : 12       Routes : 12       


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

    192.168.1.0/24  Static  60   0          RD   192.168.2.1     GigabitEthernet

0/0/0

    192.168.2.0/24  Direct  0    0           D   192.168.2.2     GigabitEthernet

0/0/0

    192.168.2.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/0

  192.168.2.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/0

    192.168.3.0/24  Direct  0    0           D   192.168.3.1     GigabitEthernet

0/0/1

    192.168.3.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/1

  192.168.3.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/1

    192.168.4.0/24  Static  60   0          RD   192.168.3.2     GigabitEthernet

0/0/1

255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0



R3

<Huawei>sys

<Huawei>system-view 

Enter system view, return user view with Ctrl+Z.

[Huawei]sysname R3

[R3]interface GigabitEthernet 0/0/1

[R3-GigabitEthernet0/0/1]undo shutdown

Info: Interface GigabitEthernet0/0/1 is not shutdown.

[R3-GigabitEthernet0/0/1]ip address 192.168.3.2 255.255.255.0

Nov 19 2018 19:11:07-08:00 R3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 

on the interface GigabitEthernet0/0/1 has entered the UP state. 

[R3-GigabitEthernet0/0/1]quit

[R3]interface GigabitEthernet 0/0/0

[R3-GigabitEthernet0/0/0]undo shutdown

Info: Interface GigabitEthernet0/0/0 is not shutdown.

[R3-GigabitEthernet0/0/0]ip address 192.168.4.254 255.255.255.0

Nov 19 2018 19:12:23-08:00 R3 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 

on the interface GigabitEthernet0/0/0 has entered the UP state. 

[R3-GigabitEthernet0/0/0]quit

[R3]ip route-static 0.0.0.0 0.0.0.0 192.168.3.1        //ip 路由-靜態 (預設路由或預設路由一種特殊的靜態路由!)

[R3]display ip routing-table 

Route Flags: R - relay, D - download to fib

------------------------------------------------------------------------------

Routing Tables: Public

         Destinations : 11       Routes : 11       


Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface


        0.0.0.0/0   Static  60   0          RD   192.168.3.1     GigabitEthernet

0/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

    192.168.3.0/24  Direct  0    0           D   192.168.3.2     GigabitEthernet

0/0/1

    192.168.3.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/1

  192.168.3.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/1

    192.168.4.0/24  Direct  0    0           D   192.168.4.254   GigabitEthernet

0/0/0

  192.168.4.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/0

  192.168.4.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet

0/0/0

255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0


=====================================================================================


實驗名稱:思科配置靜態路由預設路由實現全網互通

實驗拓撲圖:

image.png

實驗步驟:PC配置IP子網掩碼閘道器

                 路由器配置介面和靜態路由

                 驗證並儲存

實驗結果:實現全網互通為浮動路由做準備

實驗命令:

R1

Router>enable

Router#configure terminal 

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#hostname R1

R1(config)#no ip domain lookup

R1(config)#interface gigabitEthernet 0/1

R1(config-if)#no shutdown

R1(config-if)#ip address 192.168.1.254 255.255.255.0

R1(config-if)#exit

R1(config)#interface gigabitEthernet 0/0

R1(config-if)#no shutdown

R1(config-if)#ip address 192.168.2.1 255.255.255.0

R1(config-if)#exit

R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.2        //靜態預設路由

R1(config)#end

R1#show ip route 

Codes: L - local, C - connected, S - static, 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 192.168.2.2 to network 0.0.0.0


     192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks

C       192.168.1.0/24 is directly connected, GigabitEthernet0/1

L       192.168.1.254/32 is directly connected, GigabitEthernet0/1

     192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks

C       192.168.2.0/24 is directly connected, GigabitEthernet0/0

L       192.168.2.1/32 is directly connected, GigabitEthernet0/0

S*   0.0.0.0/0 [1/0] via 192.168.2.2

                     屬性

R3#write


R2

Router>enable

Router#configure terminal 

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#hostname R2

R2(config)#no ip domain lookup

R2(config)#interface gigabitEthernet 0/0

R2(config-if)#no shutdown

R2(config-if)#ip address 192.168.2.2 255.255.255.0

R2(config-if)#exit

R2(config)#interface gigabitEthernet 0/2

R2(config-if)#no shutdown

R2(config-if)#ip address 192.168.3.1 255.255.255.0

R2(config-if)#exit

R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1

R2(config)#ip route 192.168.4.0 255.255.255.0 192.168.3.2

R2(config)#end

R2#show ip route         直連             靜態

Codes: L - local, C - connected, S - static, 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


S    192.168.1.0/24 [1/0] via 192.168.2.1

     192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks

C       192.168.2.0/24 is directly connected, GigabitEthernet0/0

L       192.168.2.2/32 is directly connected, GigabitEthernet0/0

     192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks

C       192.168.3.0/24 is directly connected, GigabitEthernet0/2

L       192.168.3.1/32 is directly connected, GigabitEthernet0/2

S    192.168.4.0/24 [1/0] via 192.168.3.2

                              屬性

R2#write


R3

Router>enable

Router#configure terminal 

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#hostname R3

R3(config)#no ip domain lookup

R3(config)#interface gigabitEthernet 0/2

R3(config-if)#no shutdown

R3(config-if)#ip address 192.168.3.2 255.255.255.0

R3(config-if)#exit

R3(config)#interface gigabitEthernet 0/1

R3(config-if)#no shutdown

R3(config-if)#ip address 192.168.4.254 255.255.255.0

R3(config-if)#exit

R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.1        //靜態預設路由

R3(config)#end

R3#show ip route        直連              靜態

Codes: L - local, C - connected, S - static, 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 192.168.3.1 to network 0.0.0.0


     192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks

C       192.168.3.0/24 is directly connected, GigabitEthernet0/2

L       192.168.3.2/32 is directly connected, GigabitEthernet0/2

     192.168.4.0/24 is variably subnetted, 2 subnets, 2 masks

C       192.168.4.0/24 is directly connected, GigabitEthernet0/1

L       192.168.4.254/32 is directly connected, GigabitEthernet0/1

S*   0.0.0.0/0 [1/0] via 192.168.3.1

                     屬性

R3#write