动态路由是指路由器能够自动地建立自己的路由表, 并且能够根据实际情况的变化适时地进行调整.
简述
动态路由是与静态路由相对的一个概念, 指路由器能够根据路由器之间的交换的特定路由信息自动地建立自己的路由表, 并且能够根据链路和节点的变化适时地进行自动调整. 当网络中节点或节点间的链路发生故障, 或存在其它可用路由时, 动态路由可以自行选择最佳的可用路由并继续转发报文.
原理
动态路由机制的运作依赖路由器的两个基本功能: 路由器之间适时的路由信息交换, 对路由表的维护:
路由器之间适时地交换路由信息.
动态路由之所以能根据网络的情况自动计算路由, 选择转发路径, 是由于当网络发生变化时, 路由器之间彼此交换的路由信息会告知对方网络的这种变化, 通过信息扩散使所有路由器都能得知网络变化.
路由器根据某种路由算法 (不同的动态路由协议算法不同) 把收集到的路由信息加工成路由表, 供路由器在转发 IP 报文时查阅.
在网络发生变化时, 收集到最新的路由信息后, 路由算法重新计算, 从而可以得到最新的路由表.
协议
RIP
路由信息协议(RIP) 是内部网关协议 IGP 中最先得到广泛使用的协议. RIP 是一种分布式的基于距离向量的路由选择协议, 是因特网的标准协议, 其最大优点就是实现简单, 开销较小.
OSPF
OSPF(Open Shortest Path First 开放式最短路径优先)是一个内部网关协议 (Interior Gateway Protocol, 简称 IGP), 用于在单一自治系统(autonomous system,AS) 内决策路由.
IS-IS
IS-IS(Intermediate System-to-Intermediate System, 中间系统到中间系统)路由协议最初是 ISO(the International Organization for Standardization, 国际标准化组织)为 CLNP(Connection Less Network Protocol, 无连接网络协议)设计的一种动态路由协议.
BGP
边界网关协议 (BGP) 是运行于 TCP 上的一种自治系统的路由协议. BGP 是唯一一个用来处理像因特网大小的网络的协议, 也是唯一能够妥善处理好不相关路由域间的多路连接的协议.
特点
1, 无需管理员手工维护, 减轻了管理员的工作负担.
2, 占用了网络带宽.
3, 在路由器上运行路由协议, 使路由器可以自动根据网络拓朴结构的变化调整路由条目;
4, 网络规模大, 拓扑复杂的网络
配置实验
实验拓扑图
配置过程
R1 路由器的配置
- R1#conf t
- R1(config)#int f0/0
- R1(config-if)#ip add 192.168.20.2 255.255.255.0
- R1(config-if)#no shut //f0/0 接口配置 IP 地址并且开启
- R1(config-if)#int f0/1
- R1(config-if)#ip add 192.168.30.1 255.255.255.0
- R1(config-if)#no shut //f0/1 接口配置 IP 地址并且开启
- R1(config)#ip route 192.168.10.0 255.255.255.0 192.168.20.1 // 配置到 192.168.10.0 网段的静态路由
- R1(config)#router ospf 1 // 开启 ospf 协议
- R1(config-router)#network 192.168.30.0 255.255.255.0 area 1 // 在 area 1 宣告 192.168.30.0 网段
- R1(config-router)#redistribute static subnets // 重分发静态路由
- R1(config-router)#redistribute connected subnets // 重分发直连网段
R2 路由器的配置
- R2#conf t
- R2(config)#int f0/0
- R2(config-if)#ip add 192.168.10.1 255.255.255.0
- R2(config-if)#no shut //f0/0 接口配置 IP 并且开启
- R2(config)#int f0/1
- R2(config-if)#ip add 192.168.20.1 255.255.255.0
- R2(config-if)#no shut //f0/1 接口配置 IP 并且开启
- R2(config)#ip route 0.0.0.0 0.0.0.0 192.168.20.2 // 配置默认路由
R3 路由器的配置
- R3#conf t
- R3(config)#int f0/0
- R3(config-if)#ip add 192.168.30.2 255.255.255.0
- R3(config-if)#no shut //f0/0 接口配置 IP 并且开启
- R3(config)#int f0/1
- R3(config-if)#ip add 192.168.40.1 255.255.255.0
- R3(config-if)#no shut //f0/1 接口配置 IP 并且开启
- R3(config)#int f1/1
- R3(config-if)#no switchport // 开启路由功能
- R3(config-if)#ip add 12.0.0.1 255.255.255.0
- R3(config-if)#no shut //f1/1 接口配置 IP 并且开启
- R3(config)#int f1/0
- R3(config-if)#no switchport
- R3(config-if)#ip add 192.168.70.1 255.255.255.0
- R3(config-if)#no shut //f1/0 接口配置 IP 并且开启
- R3(config)#router ospf 1 // 开启 ospf 协议
- R3(config-router)#network 192.168.30.0 255.255.255.0 area 1 // 在 area 1 宣告 192.168.30.0 网络
- R3(config-router)#network 192.168.40.0 255.255.255.0 area 0 // 在 area 0 宣告 192.168.40.0 网络
- R3(config-router)#network 192.168.70.0 255.255.255.0 area 0 // 在 area 0 宣告 192.168.70.0 网络
- R3(config-router)#ex
- R3(config)#ip route 0.0.0.0 0.0.0.0 12.0.0.2 // 配置默认路由
- R3(config)#router ospf 1
- R3(config-router)#default-information originate // 重分发默认路由
R4 路由器的配置
- R4#conf t
- R4(config)#int f0/0
- R4(config-if)#ip add 192.168.40.2 255.255.255.0
- R4(config-if)#no shut //f0/0 接口配置 IP 并且开启
- R4(config)#int f0/1
- R4(config-if)#ip add 192.168.50.1 255.255.255.0
- R4(config-if)#no shut //f0/1 接口配置 IP 并且开启
- R4(config)#router ospf 1 // 开启 ospf 协议
- R4(config-router)#network 192.168.40.0 255.255.255.0 area 0 // 在 area 0 宣告 192.168.40.0 网段
- R4(config)#router rip // 开启 rip 协议
- R4(config-router)#version 2 // 选择版本 2
- R4(config-router)#network 192.168.50.0 // 宣告 192.168.50.0 网段
- R4(config-router)#no auto-summary // 关闭路由汇总
- R4(config-router)#ex
- R4(config)#router ospf 1
- R4(config-router)#redistribute rip subnets // 在 ospf 协议中重分发 RIP
- R4(config)#router rip
- R4(config-router)#redistribute ospf 1 metric 3 // 在 RIP 协议中重分发 ospf, 跳数为 3 (这里 3-5 最合适)
- R4(config-router)#ex
R5(ISP 运营商)的配置
- ISP#conf t
- ISP(config)#int f0/0
- ISP(config-if)#ip add 12.0.0.2 255.255.255.0
- ISP(config-if)#no shut //f0/0 配置 IP 并且开启
- ISP(config-if)#ex
- ISP(config)#int f0/1
- ISP(config-if)#ip add 13.0.0.1 255.255.255.0
- ISP(config-if)#no shut //f0/1 配置 IP 并且开启
- ISP(config-if)#ex
- ISP(config)#ip route 0.0.0.0 0.0.0.0 12.0.0.1 // 配置默认路由
R6 路由器的配置
- R6#conf t
- R6(config)#int f0/0
- R6(config-if)#ip add 192.168.50.2 255.255.255.0
- R6(config-if)#no shut //f0/0 接口配置 IP 并且开启
- R6(config-if)#ex
- R6(config)#int f0/1
- R6(config-if)#ip add 192.168.60.1 255.255.255.0
- R6(config-if)#no shut //f0/1 接口配置 IP 并且开启
- R6(config-if)#ex
- R6(config)#router rip // 开启 RIP 协议
- R6(config-router)#version 2 // 选择版本 2
- R6(config-router)#network 192.168.50.0 // 在 RIP 协议中宣告 192.168.50.0 网段
- R6(config-router)#network 192.168.60.0 // 宣告 192.168.60.0 网段
- R6(config-router)#no auto-summary // 关闭路由汇总
- R6(config-router)#ex
配置完毕后我们逐个查看路由器的路由表
R1 路由器的路由表
R2 路由器的路由表
R3 路由器的路由表
R4 路由器的路由表
R5(ISP)路由器的路由表
R6 路由器的路由表
好, 接下来我们使用 vpcs 配置四台 pc 机的 IP 进行全网互通的验证
来源: http://blog.51cto.com/13659301/2125753