|
路由的基本概念:
1 路由:判断从源主机到目标主机所经过的最佳路径,从而实现数据的转发,这就是路由技术。
2 路由表:在每个路由器中都有一张路由表,路由表包含了该路由器掌握的所有目的地的网络地址,以及通过此路由器到达这些网络地址的最佳路径。
路由表的形成:
- 直连网段:当在路由器的接口上配置了IP地址,并且接口状态为"up"时,路由表中会出现直连路由项。
- 非直连网段:通过静态路由或动态路由写到路由表中。
3 管理距离和度量值:路由器只把最优的路由条目添加到路由表中,路由器在选择路由条目时使用两个参数,即管理距离(Administrative Distance)和度量值(Metrics)。
- 管理距离:指一种路由协议的路由可信度,是一种优先级度量,管理距离越小,优先级越高。在Cisco IOS中使用的默认管理距离如下所示(不同品牌的网络设备可能不一样):
路由类型 管理距离
直连路由 0
静态路由 1
OSPF 110
RIP 120
- 度量值:度量值代表距离,用来确定寻路时的最优路由。每一种路由算法在产生路由表时都会为每一条网络路径产生一个数值(度量值),最小的值表示最优路径。度量值的计算可以只考虑路径的一个特性,但复杂的度量值是综合了路径的多个特性产生的。常用的度量值有跳数、成本、带宽、时延等。OSPF路由协议的度量值为成本(开销),RIP路由协议的度量值为跳数。
当路由器接收到相同目的地的路由条目时,首先比较管理距离,选择管理距离小的路由条目添加到路由表中,如果管理距离相同,则比较度量值,选择度量值小的路由条目添加到路由表中。当收到的目的地址、管理距离和度量值都相同的路由条目时,路由表中会形成负载均衡的路由条目。在某些情况下,也可以修改管理距离,对同一网段使用不同的管理距离,再让路由器选择最优的路由(可信度最高,即管理距离小)添加到路由表中,当线路出现故障时,管理距离小的路由失效,管理距离大的路由为最佳路由,会被写入到路由表中,即为浮动路由。
4 路由的类型
1)静态路由:由管理员在路由器中手工配置的固定路由。
特点:
- 适合小规模的网络环境
- 静态路由是单向的,如果要实现双方互相通信,必须在通信双方配置双向的静态路由。
- 静态路由缺少足够的灵活性,如果拓朴结构改变,需要重新手工配置。
2)动态路由:通过某种路由协议实现路由器之间共享网络连接信息和状态信息,从而更新路由表(选择最优路径)。
度量值:上面已叙述过,不再多讲
收敛:动态路由协议包含了一系列过程,如本地路由器向其它路由器通告本地直连网段、接收其它路由器的路由信息等。因此,使所有路由器的路由表达到一致的状态叫收敛。实现全网信息共享以及所有路由器计算最优路径所花费的时间的总和就是收敛时间。
OSPF(开放式最短路径优先)动态路由协议:
OSPF是一种内部网关协议(IGP),用来解决AS(自治系统:共同管理下的互联网络如一个企业或一座城市)内部通信的,而外部网关协议(EGP)用来解决AS间通信的。OSPF将AS分割成多个小的区域,OSPF路由器只在区域内部学习完整的链路状态信息,而不必了解整个AS内部所有的链路状态。
OSPF适应环境:
- 网络规模:大中型规模的网络,当网络中的路由器在十台以上甚至更多。
- 拓朴结构:拓朴结构为网状,或路由器之间都有互通的需求。
- 路由器自身的要求:OSPF对路由器CPU的处理能力和内存大小都有一定的要求,性能较低的路由器不建议使用OSPF协议。
OSPF路由器的Router>
运行OSPF协议的路由器需要了解每条链路是连接在哪台路由器上的,因此,需要一个唯一的标识来标记OSPF网络中的路由器,即Router> OSPF协议中的DR(指定路由器)和BDR(备份指定路由器)
运行OSPF的路由器通过DR和BDR与邻居路由器建立邻接关系,互相传递链路状态信息。
自动选举DR和BDR:Router>
手工选举DR和BDR:手工选举需要设置路由器的优先级,范围是0-255,值越大,优先级越高。如果优先级为0,则不参与选举。如果优先级相同,则比较Router> 通常在广播多路访问网络上(如以太网),最先初始化的两台具有选举资格的路由器将成为DR和BDR路由器。
OSPF路由表:
- 区域内路由:路由条目前面的“O”代表OSPF区域内的路由。
- 区域间路由:路由条目前面的“O IA”代表OSPF区域间的路由,即在其它区域但仍在OSPF AS内的目的地路径,它至少通过了一台ABR路由器。
OSPF路由类型的优先级:
- 区域内路径:优先级 1
- 区域间路径:优先级 2
- E1外部路径:优先级 3
- E2外部路径:优先级 4(默认的OSPF外部路由)
路由表添加路由条目时,如果目的网段相同,则会选择优先级最高的路由条目添加到路由表中。
OSPF网络架构如下:
R1的配置:
R1(config)#router ospf 100 #配置OSPF进程号,只有本地意义
R1(config-router)#router-id 1.1.1.1 #指定Router> R1(config-router)#network 10.1.1.0 0.0.0.3 area 0 #宣告OSPF协议运行的接口和所在区域
R1(config-router)#network 10.1.1.4 0.0.0.3 area 1
R2的配置:
R2(config)#router ospf 100
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 10.1.1.8 0.0.0.3 area 0
R2(config-router)#network 10.1.1.12 0.0.0.3 area 1
R3的配置:
R3(config)#router ospf 100
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 10.1.1.0 0.0.0.3 area 0
R3(config-router)#network 10.1.1.8 0.0.0.3 area 0
R3(config-router)#network 192.168.1.0 0.0.0.255 area 0
R4的配置:
R4(config)#router ospf 100
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 10.1.1.4 0.0.0.3 area 1
R4(config-router)#network 10.1.1.12 0.0.0.3 area 1
R4(config-router)#network 172.16.1.0 0.0.0.255 area 1
显示路由器的路由协议信息:
R1#sh ip protocols
Routing Protocol is "ospf 100"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router> It is an area border router
Number of areas in this router is 2. 2 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
10.1.1.0 0.0.0.3 area 0
10.1.1.4 0.0.0.3 area 1
Reference bandwidth unit is 100 mbps
Routing Information Sources:
Gateway Distance Last Update
4.4.4.4 110 00:14:48
2.2.2.2 110 00:14:48
3.3.3.3 110 00:17:19
Distance: (default is 110)
查看路由表:
R1#sh ip route
Codes: 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
i - IS-IS, su - IS-IS summary, 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
172.16.0.0/32 is subnetted, 1 subnets
O 172.16.1.1 [110/2] via 10.1.1.6, 00:03:55, FastEthernet1/0
10.0.0.0/30 is subnetted, 4 subnets
O 10.1.1.8 [110/2] via 10.1.1.1, 00:06:26, FastEthernet0/0
O 10.1.1.12 [110/2] via 10.1.1.6, 00:03:55, FastEthernet1/0
C 10.1.1.0 is directly connected, FastEthernet0/0
C 10.1.1.4 is directly connected, FastEthernet1/0
192.168.1.0/32 is subnetted, 1 subnets
O 192.168.1.1 [110/2] via 10.1.1.1, 00:06:26, FastEthernet0/0
仅显示与OSPF相关的路由信息:
R1#sh ip route ospf
172.16.0.0/32 is subnetted, 1 subnets
O 172.16.1.1 [110/2] via 10.1.1.6, 00:17:27, FastEthernet1/0
10.0.0.0/30 is subnetted, 4 subnets
O 10.1.1.8 [110/2] via 10.1.1.1, 00:19:58, FastEthernet0/0
O 10.1.1.12 [110/2] via 10.1.1.6, 00:17:27, FastEthernet1/0
192.168.1.0/32 is subnetted, 1 subnets
O 192.168.1.1 [110/2] via 10.1.1.1, 00:19:58, FastEthernet0/0
验证网络是否畅通:
R3#ping 172.16.1.1 source 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
Packet sent with a source address of 192.168.1.1
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 52/66/76 ms
查看邻接关系:
R1#sh ip ospf neighbor
Neighbor> 3.3.3.3 1 FULL/BDR 00:00:34 10.1.1.1 FastEthernet0/0
4.4.4.4 1 FULL/BDR 00:00:32 10.1.1.6 FastEthernet1/0
R3#sh ip ospf neighbor
Neighbor> 2.2.2.2 1 FULL/DR 00:00:33 10.1.1.10 FastEthernet1/0
1.1.1.1 1 FULL/DR 00:00:35 10.1.1.2 FastEthernet0/0
查看接口是否加入正确的区域:
R1#sh ip ospf interface
FastEthernet0/0 is up, line protocol is up
Internet Address 10.1.1.2/30, Area 0
Process> Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 1.1.1.1, Interface address 10.1.1.2
Backup Designated router (ID) 3.3.3.3, Interface address 10.1.1.1
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:07
Supports Link-local Signaling (LLS)
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 0, maximum is 1
Last flood scan time is 0 msec, maximum is 4 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 3.3.3.3 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
FastEthernet1/0 is up, line protocol is up
Internet Address 10.1.1.5/30, Area 1
Process> Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 1.1.1.1, Interface address 10.1.1.5
Backup Designated router (ID) 4.4.4.4, Interface address 10.1.1.6
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:06
Supports Link-local Signaling (LLS)
Index 1/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 0, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 4.4.4.4 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
查看OSPF数据库:
R1#sh ip ospf database
OSPF Router with> Router Link States (Area 0)
Link> 1.1.1.1 1.1.1.1 1390 0x80000003 0x00AD5E 1
2.2.2.2 2.2.2.2 1373 0x80000003 0x0022D1 1
3.3.3.3 3.3.3.3 1367 0x80000005 0x00083C 3
Net Link States (Area 0)
Link> 10.1.1.2 1.1.1.1 1390 0x80000001 0x007AA0
10.1.1.10 2.2.2.2 1374 0x80000001 0x002EDC
Summary Net Link States (Area 0)
Link> 10.1.1.4 1.1.1.1 1749 0x80000001 0x00A189
10.1.1.4 2.2.2.2 1218 0x80000001 0x008D98
10.1.1.12 1.1.1.1 1225 0x80000001 0x005BC6
10.1.1.12 2.2.2.2 1507 0x80000001 0x0033EB |
|