静态路由的原理及配置

(1)适用环境

由管理员手工配置而成,配置简单。

需要人工维护:当一个网络故障发生后,静态路由不会自动发生改变。

适合于网络拓扑简单的网络。

(2)静态路由配置命令

小窍门:直连网段不用配置路由,配置非直连的网段即可

华为配置案例5:静态路由_默认路由


[AR1]ip route-static 192.168.2.0 255.255.255.0 12.1.1.2

[AR2]ip route-static 192.168.1.0 24 12.1.1.1

[AR1]dis 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


12.1.1.0/24 Direct 0 0 D 12.1.1.1 GigabitEthernet0/0/1

12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1

12.1.1.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

192.168.1.0/24 Direct 0 0 D 192.168.1.1 GigabitEthernet0/0/0

192.168.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0

192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0

192.168.2.0/24 Static 60 0 RD 12.1.1.2 GigabitEthernet0/0/1

255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0

[AR2]dis 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


12.1.1.0/24 Direct 0 0 D 12.1.1.2 GigabitEthernet0/0/0

12.1.1.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/0

12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/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

192.168.1.0/24 Static 60 0 RD 12.1.1.1 GigabitEthernet0/0/0

192.168.2.0/24 Direct 0 0 D 192.168.2.1 GigabitEthernet0/0/1

192.168.2.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1

192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1

255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0

PC1能ping通PC2

PC>ping 192.168.2.2


Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break

From 192.168.2.2: bytes=32 seq=1 ttl=126 time=94 ms

From 192.168.2.2: bytes=32 seq=2 ttl=126 time=47 ms

From 192.168.2.2: bytes=32 seq=3 ttl=126 time=47 ms

From 192.168.2.2: bytes=32 seq=4 ttl=126 time=31 ms

From 192.168.2.2: bytes=32 seq=5 ttl=126 time=31 ms


--- 192.168.2.2 ping statistics ---

5 packet(s) transmitted

5 packet(s) received

0.00% packet loss

round-trip min/avg/max = 31/50/94 ms

(3)负载均衡

华为配置案例5:静态路由_静态路由_02


AR1:

ip route-static 192.168.2.0 255.255.255.0 12.1.1.2

ip route-static 192.168.2.0 255.255.255.0 21.1.1.2

AR2:

ip route-static 192.168.1.0 255.255.255.0 12.1.1.1

ip route-static 192.168.1.0 255.255.255.0 21.1.1.1


[AR1]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

... ...

192.168.2.0/24 Static 60 0 RD 12.1.1.2 GigabitEthernet0/0/1

Static 60 0 RD 21.1.1.2

... ...

等价路由,实现负载分担

[AR2]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

... ...

192.168.1.0/24 Static 60 0 RD 12.1.1.1 GigabitEthernet0/0/0

Static 60 0 RD 21.1.1.1

... ...

等价路由,实现负载分担

(4)路由优先级

VRP缺省的路由优先级如下表,数值越小优先级越高

路由协议

优先级

DIRECT

0

OSPF

10

IS-IS

15

STATIC

60

RIP

100

OSPF ASE

150

(5)路由备份

华为配置案例5:静态路由_静态路由_03


AR1:

ip route-static 192.168.2.0 255.255.255.0 12.1.1.2

ip route-static 192.168.2.0 255.255.255.0 21.1.1.2 preference 100

AR2:

ip route-static 192.168.1.0 255.255.255.0 12.1.1.1

ip route-static 192.168.1.0 255.255.255.0 21.1.1.1 preference 100


[AR1]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.2.0/24 Static 60 0 RD 12.1.1.2 GigabitEthernet0/0/1


Static routing table status : <Inactive>

#优先级低,备用路由,不加入路由表

Destinations : 1 Routes : 1


Destination/Mask Proto Pre Cost Flags NextHop Interface


192.168.2.0/24 Static 100 0 R 21.1.1.2 GigabitEthernet0/0/2


[AR1]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 GigabitEthernet0/0/1

12.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1

12.1.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/1

21.1.1.0/24 Direct 0 0 D 21.1.1.1 GigabitEthernet0/0/2

21.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2

21.1.1.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

192.168.1.0/24 Direct 0 0 D 192.168.1.1 GigabitEthernet0/0/0

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

192.168.2.0/24 Static 60 0 RD 12.1.1.2 GigabitEthernet0/0/1

255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0


关闭G0/0/1端口,测试备份路由是否生效

[AR1]int g0/0/1

[AR1-GigabitEthernet0/0/1]shutdown

[AR1]dis 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


21.1.1.0/24 Direct 0 0 D 21.1.1.1 GigabitEthernet0/0/2

21.1.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet0/0/2

21.1.1.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

192.168.1.0/24 Direct 0 0 D 192.168.1.1 GigabitEthernet0/0/0

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

192.168.2.0/24 Static 100 0 RD 21.1.1.2 GigabitEthernet0/0/2

255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0


PC1能ping通PC2,备份路由生效

PC>ping 192.168.2.2


Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break

Request timeout!

From 192.168.2.2: bytes=32 seq=2 ttl=126 time=46 ms

From 192.168.2.2: bytes=32 seq=3 ttl=126 time=63 ms

From 192.168.2.2: bytes=32 seq=4 ttl=126 time=62 ms

From 192.168.2.2: bytes=32 seq=5 ttl=126 time=32 ms


--- 192.168.2.2 ping statistics ---

5 packet(s) transmitted

4 packet(s) received

20.00% packet loss

round-trip min/avg/max = 0/50/63 ms

默认路由的原理及配置

(1)概念

缺省路由是一种特殊的路由,可以通过静态路由配置,某些动态路由协议也可以生成缺省路由,如OSPF和IS-IS。

在路由表中,缺省路由以到网络0.0.0.0(掩码为0.0.0.0)的形式出现。

当路由器收到一个在路由表中匹配不到明确路由的数据包时,会将数据包转发给缺省路由指向的下一跳。

(2)默认路由配置命令

华为配置案例5:静态路由_默认路由_04


[AR1]ip route-static 0.0.0.0 0.0.0.0 12.1.1.2


[AR2]ip route-static 192.168.1.0 24 12.1.1.1

[AR2]ip route-static 192.168.2.0 24 23.1.1.3


[AR3]ip route-static 0.0.0.0 0.0.0.0 23.1.1.2


[AR1]dis 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 12.1.1.2 GigabitEthernet0/0/1

... ...


PC1能ping通PC2

PC>ping 192.168.2.2


Ping 192.168.2.2: 32 data bytes, Press Ctrl_C to break

From 192.168.2.2: bytes=32 seq=1 ttl=125 time=47 ms

From 192.168.2.2: bytes=32 seq=2 ttl=125 time=62 ms

From 192.168.2.2: bytes=32 seq=3 ttl=125 time=109 ms

From 192.168.2.2: bytes=32 seq=4 ttl=125 time=110 ms

From 192.168.2.2: bytes=32 seq=5 ttl=125 time=63 ms


--- 192.168.2.2 ping statistics ---

5 packet(s) transmitted

5 packet(s) received

0.00% packet loss

round-trip min/avg/max = 47/78/110 ms

(3)补充说明

缺省路由也支持路由的负载分担与路由备份。

最长匹配原则

华为配置案例5:静态路由_静态路由_05


路由器的每个接口都是一个独立的网段。