CCNA 之 五 路由协议 一 静态路由

静态路由

路由选择原理

什么是路由?

就如同去某一个地方,会有很多种路线,每一条路线经都可以称之为路由;
路由器中会维护一张路由表,每一个表项都是一条路由,也就是去往某个网络的路径,然后将对应的数据包从相应的接口送出去。


路由器的工作内容

  • 路由器知道目的地址
  • 发现到达目标地址的可能的路由
  • 选择最佳路径(路由表)
  • 维护路由信息

可以通过在特权模式中使用show ip route命令来查看路由表。

概念:

  • 被动路由协议(Routed protocols):用来在路由器之间传递用户的信息
  • 主动路由协议(routing protocols):用于维护路由器的路由表

路由的来源

  • 直连路由 - 直接连接到路由器上的网络
  • 静态路由 - 管理员手工构建的路由表
  • 动态路由 - 路由器之间动态学习到的路由表

静态路由

静态路由就是工程师手工配置的条目,来告诉路由器,去往某一个网络如何走。

静态路由的配置:

静态路由配置有两种配置,第一种是配置下一跳的方式,第二种是配置出接口的方式。

注意:通信是双向的,因此要注意往返流量。

默认路由
default-route

R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.2

上机实验手动配置静态路由

根据下图配置
default-route

首先配置R1:

R1>en
R1#conf t
R1(config)#int s 0/0
R1(config-if)#ip add 192.168.1.1 255.255.255.0
R1(config-if)#no sh
R1(config-if)#exit
R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.2

再配置R2:

R2>en
R2#conf t
R2(config)#int s 0/0
R2(config-if)#ip add 192.168.1.2 255.255.255.0
R2(config-if)#no sh
R2(config-if)#exit
R2(config)#int s 0/1
R2(config-if)#ip add 192.168.2.1 255.255.255.0
R2(config-if)#no sh
R2(config-if)#end
R2#show 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
C 192.168.1.0/24 is directly connected, Serial0/0
C 192.168.2.0/24 is directly connected, Serial0/1

最后配置R3:

R3>en
R3#conf t
R3(config)#int s 0/0
R3(config-if)#ip add 192.168.2.2 255.255.255.0
R3(config-if)#no sh
R3(config-if)#exit
R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1

验证:
R1:

R1#show 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
C 192.168.1.0/24 is directly connected, Serial0/0
S 192.168.2.0/24 [1/0] via 192.168.1.2
R1#ping 192.168.2.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/22/68 ms

R1路由器上可以看到,静态路由是正常的,并且可以ping通192.168.2.0/24段;

R3:

R3#show ip rout
*Mar 1 00:02:35.907: %SYS-5-CONFIG_I: Configured from console by console
R3#show 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
S 192.168.1.0/24 [1/0] via 192.168.2.1
C 192.168.2.0/24 is directly connected, Serial0/0
R3#ping 192.168.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 4/20/56 ms

R3路由器上可以看到,静态路由是正常的,并且可以ping通192.168.1.0/24段;


动态路由协议RIP

什么是路由?

当路由器收到一个数据包三层,会查看包中的目标地址,在根据目标地址,查看本地的路由表,这个路由表要不是动态获取的、或者是是手动配置的静态路由,如果有,则进行再封包转发,如果没有,则直接丢弃。

路由可以通过show ip route命令进行查看路由表;

R1#show ip route
Gateway of last resort is nt set
     2.0.0.0/24 is subnetted, 1 subnets
O   2.2.2.0 [110/65] via 9.9.12.2, 00:00:02, Serial0/0
     9.0.0.0/24 is subnetted, 1 subnets
C   9.9.12.0 is directly connected, Serial0/0

其中以O开头的表示以动态路由协议获取的;
C表示直连网络;
via 9.9.12.2表示下一跳的地址;
Serial0/0 表示路由的对端接口;

路由协议分类:

  • 静态路由

由管理员根据数据访问需求手工在每台设备上进行添加和维护路由

  • 动态路由

路由器自动进行路由信息的更新合同部,并且当网络拓扑变更时,能够自动收敛;

静态路由协议
优势:

  • 不占用链路上的带宽
  • 不消耗CPURAm资源

劣势:

  • 在大型网络中配置复杂
  • 无法感知到网络拓扑中的情况

动态路由协议
优势:

  • 相比静态路由协议,大型网络中,配置简单
  • 能够动态的感知到网络拓扑的情况

劣势:

  • 占用CPURAM的资源
  • 占用链路上一定的带宽

dong-route

动态路由分为两大类:

  • 内部网关协议
  • 外部网关协议

区别是:AS号,自治愈系统;

距离矢量路由协议

距离矢量的定义:

使用距离矢量路由协议的路由器并不了解到达目的网络的整条路径。
该路由器只知道:

  • 自身与目的网络之间的距离多少跳
  • 应该往哪个方向或使用哪个接口转发数据包

julishiliang

tedian

RIP使用广播的方式来更新整张路由表;

julishijing

Metric 度量值

RIP以跳数作为metric

动态路由协议中,所有的协议都是以Metric度量值来衡量路由的好、坏、优、劣。

同一台route,学习到同一种动态路由协议的去往同一个目的地的route,会比较Metric值,会以最优的Metric值的路由写进路由表中。
这里指的最优,也就是最小的跳数。
当有两条相同的也是最优的Metric值,则会同时使用,这个就是负载均衡。

通过show ip route命令,来查看RIP的Metric度量值。

R1#show ip route
C    192.168.12.0/24 is directly connected, Serial0/0
R    192.168.23.0/24 [120/1] via 192.168.12.2, 00:00:08, Serial0/0

上面加粗的1,表示Metric度量值

管理距离(AD值)

每一种动态路由协议,都有一个AD值。

同一台route,学习到不同的动态路由协议去往同一个目的地的route,会比较AD值最小的路由,把最小的路由写进路由表中。
只有当最优的路线宕掉的时候,才会出现另一跳路径。

目前有多种机制可以消除路由环路。这些机制包括:

  • 定义最大度量以防止技术至无穷大
  • 水平分割
  • 抑制计时器
  • 路由毒化或毒性反转
  • 触发更新

RIP的配置

  • RIP(Routing Information Protocols, 路由信息协议),是应用较早、使用较普遍的内部网关协议(Interios Gateway Protocol, 简称IGP)
  • 适用于小型同类网络,是典型的距离矢量协议。
  • RIP是基于UDP,端口520的应用层协议。
  • 管理型距离:120
  • 最大上线16跳不可达,也是决定了不适用于大型网络。

下面我们根据下列图片中的网络,配置一下RIP

首先我们配置R1:

R1>en
R1#conf t
R1(config)#int s 0/0
R1(config-if)#ip add 192.168.12.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#end
R1#show 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
C 192.168.12.0/24 is directly connected, Serial0/0
R1#conf t
R1(config)#router rip
R1(config-router)#network 192.168.12.0

在配置R2

R2>en
R2#conf t
R2(config)#int s 0/0
R2(config-if)#ip add 192.168.12.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface serial 0/1
R2(config-if)#ip add 192.168.23.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#router rip
R2(config-router)#network 192.168.12.0
R2(config-router)#network 192.168.23.0

最后配置R3

R3>en
R3#conf t
R3(config)#interface serial 0/0
R3(config-if)#ip add 192.168.23.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#exit
R3#show 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
C 192.168.23.0/24 is directly connected, Serial0/0
R3#conf t
R3(config)#router rip
R3(config-router)#network 192.168.23.0


此时配置完成
分别在R1R3上查看:

R1上查看和ping

R1#show 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
C 192.168.12.0/24 is directly connected, Serial0/0
R 192.168.23.0/24 [120/1] via 192.168.12.2, 00:00:05, Serial0/0
R1#ping 192.168.23.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/19/64 ms

R3上查看和ping

R3#show 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
R 192.168.12.0/24 [120/1] via 192.168.23.2, 00:00:01, Serial0/0
C 192.168.23.0/24 is directly connected, Serial0/0
R3#ping 192.168.12.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.12.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 8/23/76 ms

至此,完成实验;

原文地址:https://www.cnblogs.com/winstom/p/9255855.html