学习日记——(路由与交换技术)动态路由(rip协议)和静态路由

一、相关知识点

1、动态路由

  1. 动态路由是网络中的路由器之间相互通信,传递路由信息,利用收到的路由信息计算路由并更新路由表的过程。
  2. 实时地适应网络结构变化
  3. 适用于网络规模大、网络拓扑结构复杂的网络
  4. 有多个网络协议,常见的有RIP、OSPF、EIGRP等
  5. 灵活,但开销大
  6. 自动交换路由信息,无需管理员配置

2、RIP路由协议

  1. RIP是一种距离矢量路由协议,内部网关协议,应用于自治系统内。
  2. RIP使用跳数作为路径选择的唯一度量。
  3. 跳数最多不能超过15。
  4. 每30s广播一次消息工作过程。

二、相关例子

1、拓扑结构

此处省略主机的IP地址配置图,读者根据自己的需要自己配置,像我 网关都是设置192.168.1/2/3.254

2、相关代码:

路由表中R代表RIP S代表静态

Route 1:

Router>en

Router#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#host

Router(config)#hostname R1

R1(config)#int g

R1(config)#int gigabitEthernet 0/0

R1(config-if)#ip add

R1(config-if)#ip address 192.168.1.254 255.255.255.0

R1(config-if)#no sh

R1(config-if)#no shutdown

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up

R1(config-if)#e

R1(config-if)#exit

R1(config)#int gigabitEthernet 0/1

R1(config-if)#ip address 192.168.12.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

R1(config-if)#e

R1(config-if)#exit

R1(config)#int gigabitEthernet 0/2

R1(config-if)#ip address 192.168.13.1 255.255.255.0

R1(config-if)#no shutdown

R1(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

R1(config-if)#e

R1(config-if)#exit

R1(config)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

R1(config)#route rip  这段是配置RIP协议,注意:RIP配置的网段是与该路由器的直连网段。

R1(config-router)#net

R1(config-router)#network 192.168.1.0

R1(config-router)#network 192.168.12.0

R1(config-router)#network 192.168.13.0

R1(config-router)#ver

R1(config-router)#version 2(版本号)

R1(config-router)#end

R1#

%SYS-5-CONFIG_I: Configured from console by console

R1#show ip route

Codes: L - local, 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, E - EGP

i - IS-IS, 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

192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.1.0/24 is directly connected, GigabitEthernet0/0

L 192.168.1.254/32 is directly connected, GigabitEthernet0/0

R 192.168.2.0/24 [120/1] via 192.168.12.2, 00:00:09, GigabitEthernet0/1 (R代表的是RIP协议)

R 192.168.3.0/24 [120/1] via 192.168.13.2, 00:00:13, GigabitEthernet0/2    ([120/1],120代表管理距离,1代表开销)

192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.12.0/24 is directly connected, GigabitEthernet0/1

L 192.168.12.1/32 is directly connected, GigabitEthernet0/1

192.168.13.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.13.0/24 is directly connected, GigabitEthernet0/2

L 192.168.13.1/32 is directly connected, GigabitEthernet0/2

R 192.168.23.0/24 [120/1] via 192.168.12.2, 00:00:09, GigabitEthernet0/1

[120/1] via 192.168.13.2, 00:00:13, GigabitEthernet0/2


Route 2:

Router>en

Router#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#host

Router(config)#hostname R2

R2(config)#int g

R2(config)#int gigabitEthernet 0/0

R2(config-if)#ip add

R2(config-if)#ip address 192.168.2.254 255.255.255.0

R2(config-if)#no shu

R2(config-if)#no shutdown

R2(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up

R2(config-if)#e

R2(config-if)#exit

R2(config)#int gigabitEthernet 0/1

R2(config-if)#ip address 192.168.12.2 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up

R2(config-if)#e

R2(config-if)#exit

R2(config)#int gigabitEthernet 0/2

R2(config-if)#ip address 192.168.23.1 255.255.255.0

R2(config-if)#no shutdown

R2(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

R2(config-if)#e

R2(config-if)#exit

R2(config)#

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

R2(config)#route rip 这段是配置RIP协议,注意:RIP配置的网段是与该路由器的直连网段。

R2(config-router)#net

R2(config-router)#network 192.168.2.0

R2(config-router)#network 192.168.12.0

R2(config-router)#network 192.168.23.0

R2(config-router)#ver

R2(config-router)#version 2


Route 3:

Router>en

Router#conf t

Enter configuration commands, one per line. End with CNTL/Z.

Router(config)#host

Router(config)#hostname R3

R3(config)#int g

R3(config)#int gigabitEthernet 0/0

R3(config-if)#ip add

R3(config-if)#ip address 192.168.3.254 255.255.255.0

R3(config-if)#no sh

R3(config-if)#no shutdown

R3(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up

R3(config-if)#e

R3(config-if)#exit

R3(config)#int gigabitEthernet 0/1

R3(config-if)#ip address 192.168.13.2 255.255.255.0

R3(config-if)#no shutdown

R3(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up

R3(config-if)#

R3(config-if)#exit

R3(config)#int gigabitEthernet 0/2

R3(config-if)#ip address 192.168.23.2 255.255.255.0

R3(config-if)#no shutdown

R3(config-if)#

%LINK-5-CHANGED: Interface GigabitEthernet0/2, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/2, changed state to up

R3(config-if)#e

R3(config-if)#exit

R3(config)#route rip 这段是配置RIP协议,注意:RIP配置的网段是与该路由器的直连网段。

R3(config-router)#net

R3(config-router)#network 192.168.3.0

R3(config-router)#network 192.168.13.0

R3(config-router)#network 192.168.23.0

R3(config-router)#ver

R3(config-router)#version 2

R3(config-router)#

R3(config-router)#end

R3#

%SYS-5-CONFIG_I: Configured from console by console

R3#show ip route

Codes: L - local, 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, E - EGP

i - IS-IS, 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.1.0/24 [120/1] via 192.168.13.1, 00:00:05, GigabitEthernet0/1

R 192.168.2.0/24 [120/1] via 192.168.23.1, 00:00:11, GigabitEthernet0/2

192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.3.0/24 is directly connected, GigabitEthernet0/0

L 192.168.3.254/32 is directly connected, GigabitEthernet0/0

R 192.168.12.0/24 [120/1] via 192.168.23.1, 00:00:11, GigabitEthernet0/2

[120/1] via 192.168.13.1, 00:00:05, GigabitEthernet0/1

192.168.13.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.13.0/24 is directly connected, GigabitEthernet0/1

L 192.168.13.2/32 is directly connected, GigabitEthernet0/1

192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.23.0/24 is directly connected, GigabitEthernet0/2

--More--

结果:

PC1 ping PC2 


RIP与静态的对比

Route 1:

en

R1#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R1(config)#ip route 192.168.2.0 255.255.255.0 192.168.12.2

R1(config)#ip route 192.168.3.0 255.255.255.0 192.168.13.2

R1(config)#ip route 192.168.23.0 255.255.255.0 192.168.12.2

R1(config)#do show ip route

Codes: L - local, 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, E - EGP

i - IS-IS, 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

192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.1.0/24 is directly connected, GigabitEthernet0/0

L 192.168.1.254/32 is directly connected, GigabitEthernet0/0

S 192.168.2.0/24 [1/0] via 192.168.12.2

S 192.168.3.0/24 [1/0] via 192.168.13.2

192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.12.0/24 is directly connected, GigabitEthernet0/1

L 192.168.12.1/32 is directly connected, GigabitEthernet0/1

192.168.13.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.13.0/24 is directly connected, GigabitEthernet0/2

L 192.168.13.1/32 is directly connected, GigabitEthernet0/2

S 192.168.23.0/24 [1/0] via 192.168.12.2


Route 2:

R2>en

R2#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.12.1

R2(config)#ip route 192.168.13.0 255.255.255.0 192.168.12.1

R2(config)#ip route 192.168.3.0 255.255.255.0 192.168.23.2

R2(config)#do show ip route

Codes: L - local, 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, E - EGP

i - IS-IS, 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.12.1

192.168.2.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.2.0/24 is directly connected, GigabitEthernet0/0

L 192.168.2.254/32 is directly connected, GigabitEthernet0/0

S 192.168.3.0/24 [1/0] via 192.168.23.2

192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.12.0/24 is directly connected, GigabitEthernet0/1

L 192.168.12.2/32 is directly connected, GigabitEthernet0/1

S 192.168.13.0/24 [1/0] via 192.168.12.1

192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.23.0/24 is directly connected, GigabitEthernet0/2

L 192.168.23.1/32 is directly connected, GigabitEthernet0/2


Route 3:

R3>en

R3#conf t

Enter configuration commands, one per line. End with CNTL/Z.

R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.13.1

R3(config)#ip route 192.168.12.0 255.255.255.0 192.168.13.1

R3(config)#ip route 192.168.2.0 255.255.255.0 192.168.23.1

R3(config)#do show ip route

Codes: L - local, 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, E - EGP

i - IS-IS, 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.13.1

S 192.168.2.0/24 [1/0] via 192.168.23.1

192.168.3.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.3.0/24 is directly connected, GigabitEthernet0/0

L 192.168.3.254/32 is directly connected, GigabitEthernet0/0

S 192.168.12.0/24 [1/0] via 192.168.13.1

192.168.13.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.13.0/24 is directly connected, GigabitEthernet0/1

L 192.168.13.2/32 is directly connected, GigabitEthernet0/1

192.168.23.0/24 is variably subnetted, 2 subnets, 2 masks

C 192.168.23.0/24 is directly connected, GigabitEthernet0/2

L 192.168.23.2/32 is directly connected, GigabitEthernet0/2

总结:当网络中配有RIP路由协议和静态路由,网络会启用静态路由,为什么呢?

因为优先级,静态路由的管理距离比RIP(120)的小,所以会用静态路由。

路由表中R代表RIP S代表静态


这篇文章到这里就写完啦,加油!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值