HCNP-路由交换:静态路由

1. 最基本的配置

拓扑图如下
HCNP-路由交换:静态路由_第1张图片

路由器AR1的配置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname r1
[r1]int g0/0/0
[r1-GigabitEthernet0/0/0]ip add 10.1.1.254 24
Aug 26 2019 22:09:20-08:00 r1 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[r1]int g0/0/1
[r1-GigabitEthernet0/0/1]ip add 12.1.1.1 24
Aug 26 2019 22:42:09-08:00 r1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/1 has entered the UP state.
[r1-GigabitEthernet0/0/0]q
[r1]ip route-static 20.1.1.0 24 g0/0/1 12.1.1.2
[r1]ip route-static 23.1.1.0 24 g0/0/1 12.1.1.2
[r1]ip route-static 30.1.1.0 24 g0/0/1 12.1.1.2

路由器AR2的配置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname r2
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip add 20.1.1.254 24
Aug 26 2019 22:19:34-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]int g0/0/1
[r2-GigabitEthernet0/0/1]ip add 12.1.1.2 24
Aug 26 2019 22:20: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]int g0/0/2
[r2-GigabitEthernet0/0/2]ip add 23.1.1.1 24
Aug 26 2019 22:20:23-08:00 r2 %%01IFNET/4/LINK_STATE(l)[2]:The line protocol IP 
on the interface GigabitEthernet0/0/2 has entered the UP state. 
[r2-GigabitEthernet0/0/2]q
[r2]ip route-static 10.1.1.0 24 g0/0/1 12.1.1.1
[r2]ip route-static 30.1.1.0 24 g0/0/2 23.1.1.2

路由器AR3的配置

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname r3
[r3]int g0/0/0
[r3-GigabitEthernet0/0/0]ip add 30.1.1.254 24
Aug 26 2019 22:30:36-08:00 r3 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[r3-GigabitEthernet0/0/0]int g0/0/1
[r3-GigabitEthernet0/0/1]ip add 23.1.1.2 24
Aug 26 2019 22:30:57-08:00 r3 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 
on the interface GigabitEthernet0/0/1 has entered the UP state. 
[r3-GigabitEthernet0/0/1]q
[r3]ip route-static 10.1.1.0 24 g0/0/1 23.1.1.1
[r3]ip route-static 12.1.1.0 24 g0/0/1 23.1.1.1
[r3]ip route-static 20.1.1.0 24 g0/0/1 23.1.1.1

查看AR1的路由表

[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.1.1.0/24  Direct  0    0           D   10.1.1.1        GigabitEthernet
0/0/0
       10.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
     10.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
       12.1.1.0/24  Direct  0    0           D   12.1.1.1        GigabitEthernet
0/0/1
       12.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
     12.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
       20.1.1.0/24  Static  60   0           D   12.1.1.2        GigabitEthernet
0/0/1
       23.1.1.0/24  Static  60   0           D   12.1.1.2        GigabitEthernet
0/0/1
       30.1.1.0/24  Static  60   0           D   12.1.1.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
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

查看AR2的路由表

[r2]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 15       Routes : 15       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.1.1.0/24  Static  60   0           D   12.1.1.1        GigabitEthernet
0/0/1
       12.1.1.0/24  Direct  0    0           D   12.1.1.2        GigabitEthernet
0/0/1
       12.1.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
     12.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
       20.1.1.0/24  Direct  0    0           D   20.1.1.254      GigabitEthernet
0/0/0
     20.1.1.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
     20.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
       23.1.1.0/24  Direct  0    0           D   23.1.1.1        GigabitEthernet
0/0/2
       23.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/2
     23.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/2
       30.1.1.0/24  Static  60   0           D   23.1.1.2        GigabitEthernet
0/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

查看AR3的路由表

[r3]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.1.1.0/24  Static  60   0           D   23.1.1.1        GigabitEthernet
0/0/1
       12.1.1.0/24  Static  60   0           D   23.1.1.1        GigabitEthernet
0/0/1
       20.1.1.0/24  Static  60   0           D   23.1.1.1        GigabitEthernet
0/0/1
       23.1.1.0/24  Direct  0    0           D   23.1.1.2        GigabitEthernet
0/0/1
       23.1.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
     23.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
       30.1.1.0/24  Direct  0    0           D   30.1.1.254      GigabitEthernet
0/0/0
     30.1.1.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
     30.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
      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

PC1进行ping测试

PC>ping 10.1.1.254

Ping 10.1.1.254: 32 data bytes, Press Ctrl_C to break
From 10.1.1.1: Destination host unreachable
From 10.1.1.1: Destination host unreachable
From 10.1.1.1: Destination host unreachable
From 10.1.1.1: Destination host unreachable
From 10.1.1.1: Destination host unreachable

--- 10.1.1.254 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss

PC>ping 10.1.1.254

Ping 10.1.1.254: 32 data bytes, Press Ctrl_C to break
From 10.1.1.254: bytes=32 seq=1 ttl=255 time=421 ms
From 10.1.1.254: bytes=32 seq=2 ttl=255 time=63 ms
From 10.1.1.254: bytes=32 seq=3 ttl=255 time=16 ms
From 10.1.1.254: bytes=32 seq=4 ttl=255 time=32 ms
From 10.1.1.254: bytes=32 seq=5 ttl=255 time=31 ms

--- 10.1.1.254 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 16/112/421 ms

PC>ping 12.1.1.2

Ping 12.1.1.2: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 12.1.1.2: bytes=32 seq=2 ttl=254 time=187 ms
From 12.1.1.2: bytes=32 seq=3 ttl=254 time=94 ms
From 12.1.1.2: bytes=32 seq=4 ttl=254 time=31 ms
From 12.1.1.2: bytes=32 seq=5 ttl=254 time=31 ms

--- 12.1.1.2 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/85/187 ms

PC>ping 23.1.1.1

Ping 23.1.1.1: 32 data bytes, Press Ctrl_C to break
From 23.1.1.1: bytes=32 seq=1 ttl=254 time=62 ms
From 23.1.1.1: bytes=32 seq=2 ttl=254 time=78 ms
From 23.1.1.1: bytes=32 seq=3 ttl=254 time=47 ms
From 23.1.1.1: bytes=32 seq=4 ttl=254 time=47 ms
From 23.1.1.1: bytes=32 seq=5 ttl=254 time=31 ms

--- 23.1.1.1 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 31/53/78 ms

PC>ping 23.1.1.2

Ping 23.1.1.2: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 23.1.1.2: bytes=32 seq=2 ttl=253 time=250 ms
From 23.1.1.2: bytes=32 seq=3 ttl=253 time=94 ms
From 23.1.1.2: bytes=32 seq=4 ttl=253 time=63 ms
From 23.1.1.2: bytes=32 seq=5 ttl=253 time=78 ms

--- 23.1.1.2 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/121/250 ms

PC>ping 30.1.1.254

Ping 30.1.1.254: 32 data bytes, Press Ctrl_C to break
From 30.1.1.254: bytes=32 seq=1 ttl=253 time=78 ms
From 30.1.1.254: bytes=32 seq=2 ttl=253 time=62 ms
From 30.1.1.254: bytes=32 seq=3 ttl=253 time=47 ms
From 30.1.1.254: bytes=32 seq=4 ttl=253 time=78 ms
From 30.1.1.254: bytes=32 seq=5 ttl=253 time=62 ms

--- 30.1.1.254 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 47/65/78 ms

PC>ping 30.1.1.1

Ping 30.1.1.1: 32 data bytes, Press Ctrl_C to break
Request timeout!
From 30.1.1.1: bytes=32 seq=2 ttl=125 time=47 ms
From 30.1.1.1: bytes=32 seq=3 ttl=125 time=63 ms
From 30.1.1.1: bytes=32 seq=4 ttl=125 time=62 ms
From 30.1.1.1: bytes=32 seq=5 ttl=125 time=47 ms

--- 30.1.1.1 ping statistics ---
  5 packet(s) transmitted
  4 packet(s) received
  20.00% packet loss
  round-trip min/avg/max = 0/54/63 ms

2. 缺省路由/默认路由

配置缺省路由

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/2
[Huawei-GigabitEthernet0/0/2]ip add 172.16.1.1 24
[Huawei-GigabitEthernet0/0/2]q
[Huawei]ip route-static 0.0.0.0 0.0.0.0 g0/0/2 172.16.1.2

缺省路由一般只配在末节路由器上

3. 浮动路由

拓扑图如下
HCNP-路由交换:静态路由_第2张图片

<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]int g0/0/1
[Huawei-GigabitEthernet0/0/1]ip add 13.1.1.1 24
Aug 31 2019 16:52:06-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[0]:The line protocol
 IP on the interface GigabitEthernet0/0/1 has entered the UP state. 
[Huawei-GigabitEthernet0/0/1]int g0/0/0
[Huawei-GigabitEthernet0/0/0]ip add 12.1.1.1 24
Aug 31 2019 16:52:27-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[1]:The line protocol
 IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[Huawei-GigabitEthernet0/0/0]q
[Huawei]int LoopBack 1
[Huawei-LoopBack1]ip add 192.168.1.1 24
[Huawei-LoopBack1]q
[Huawei]ip route-static 192.168.3.0 24 g0/0/1 13.1.1.2 preference 60
[Huawei]ip route-static 192.168.3.0 24 g0/0/0 12.1.1.2 preference 50
[Huawei]dis ip rout	
[Huawei]dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 14       Routes : 14       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       12.1.1.0/24  Direct  0    0           D   12.1.1.1        GigabitEthernet
0/0/0
       12.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
     12.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
       13.1.1.0/24  Direct  0    0           D   13.1.1.1        GigabitEthernet
0/0/1
       13.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
     13.1.1.255/32  Direct  0    0           D   127.0.0.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.1.0/24  Direct  0    0           D   192.168.1.1     LoopBack1
    192.168.1.1/32  Direct  0    0           D   127.0.0.1       LoopBack1
  192.168.1.255/32  Direct  0    0           D   127.0.0.1       LoopBack1
    192.168.3.0/24  Static  50   0           D   12.1.1.2        GigabitEthernet
0/0/0
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

当指向同一目的地址的IP和子网掩码都相同时,优先级低的路由生效,优先级相同时Cost值低的路由生效。此时生效的路由称为主路由,其他的路由不生效,称为备用路由。若主路由不可达,则主路由不会生效,优先级第二低的路由生效。当之前不通的主路由重新联通且优先级仍比当前值低,则当前路由不生效,之前的主路由重新生效。

[Huawei-GigabitEthernet0/0/1]int g0/0/0
//使主路由不通
[Huawei-GigabitEthernet0/0/0]shutdown
Aug 31 2019 17:15:47-08:00 Huawei %%01IFPDT/4/IF_STATE(l)[4]:Interface GigabitEt
hernet0/0/0 has turned into DOWN state.
Aug 31 2019 17:15:47-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[5]:The line protocol
 IP on the interface GigabitEthernet0/0/0 has entered the DOWN state.
 [Huawei]dis ip routing-table protocol static 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : Static
         Destinations : 1        Routes : 1        Configured Routes : 2

Static routing table status : <Active>
         Destinations : 1        Routes : 1

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

    192.168.3.0/24  Static  60   0           D   13.1.1.2        GigabitEthernet
0/0/1

Static routing table status : <Inactive>
         Destinations : 0        Routes : 0
//路由条目已经切换,再恢复之前的主路由链路
[Huawei]int g0/0/0
[Huawei-GigabitEthernet0/0/0]undo shutdown 
Aug 31 2019 17:21:04-08:00 Huawei %%01IFPDT/4/IF_STATE(l)[6]:Interface GigabitEt
hernet0/0/0 has turned into UP state.
Aug 31 2019 17:21:04-08:00 Huawei %%01IFNET/4/LINK_STATE(l)[7]:The line protocol
 IP on the interface GigabitEthernet0/0/0 has entered the UP state. 
[Huawei-GigabitEthernet0/0/0]q
[Huawei]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

    192.168.3.0/24  Static  50   0           D   12.1.1.2        GigabitEthernet
0/0/0

Static routing table status : <Inactive>
         Destinations : 1        Routes : 1

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

    192.168.3.0/24  Static  60   0               13.1.1.2        GigabitEthernet
0/0/1

你可能感兴趣的:(路由交换)