# 一、实验名称
动态路由RIP/OSPF配置
# 二、实验目的
学习配置动态路由协议, 使得
# 三、实验内容
1. 熟悉路由器的基本配置指令;
2. 了解RIP工作的原理与配置指令;
3. 了解OSPF工作的原理与配置指令;
4. 对照实验指导书中的实验12、实验13的要求,配置相应RIP及OSPF,实现不同网段下主机的通信。
# 四、实验仪器
Cisco Packet Tracer Version:8.2.2.0400
# 五、实验原理
- **RIP(Routing Information Protocol)**:基于距离矢量算法,通过跳数来决定最佳路径。其优点是简单易用,但不适用于大型网络,因为它的最大跳数限制为15。
- **OSPF(Open Shortest Path First)**:基于链路状态算法,使用最短路径优先(SPF)算法计算最优路径。OSPF支持更复杂的网络拓扑,能够更好地适应大规模网络环境,具有更高的效率和更好的扩展性。
# 六、实验过程及实验结果
### 1. RIP
##### 1.1 基础拓扑连接与IP地址配置
其中接口, IP, 网关信息如下
| 名称 | 接口 | IP 地址 | 网关 |
| -------- | ---- | -------------- | --------- |
| Router A | F0/0 | 192.168.1.1/24 | |
| Router A | F0/1 | 172.1.1.1/24 | |
| Router B | F0/0 | 172.2.2.1/24 | |
| Router B | F0/1 | 192.168.1.2/24 | |
| PC0 | | 172.1.1.2/24 | 172.1.1.1 |
| PC1 | | 172.1.1.3/24 | 172.1.1.1 |
| PC2 | | 172.2.2.2/24 | 172.2.2.1 |
| PC3 | | 172.2.2.3/24 | 172.2.2.1 |
##### 1.2 配置路由器接口IP地址
在 Router0 中进行如下配置
```bash
Router>en
Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no ip domain-look
Router(config)#int f0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#int f0/1
Router(config-if)#ip address 172.1.1.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#
```
在 Router1 中配置与上述类似
##### 1.3 RIP路由配置
在 Router0 中进行如下配置
```bash
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#network 172.1.1.0
Router(config-router)#network 192.168.1.0
Router(config-router)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#
```
在 Router1 中配置与上述类似
进行上述配置之后, 使用 `show ip route` 得到输出如下

##### 1.4 连通性测试
在PC0中对其他三台主机使用ping命令, 三者均能ping通
##### 1.5 思考题(1)
1. 首先给两个路由器装上串口模块 `WIC-1T`
2. 使用 `Serial DCE` 线讲router0的 `Se0/0/0` 与router1的 `Se0/0/0` 相连
3. 在router0中配置DCE接口
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int s0/0/0
Router(config-if)#clock rate 64000
Router(config-if)#no shutdown
Router(config-if)#exit
```
4. 在router0中重新配置 RIP
```bash
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#network 172.1.1.0
Router(config-router)#network 192.168.1.0
Router(config-router)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#
```
5. router1中重新配置 RIP
```bashh
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#network 172.2.2.0
Router(config-router)#network 192.168.1.0
Router(config-router)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#
```
6. 分别在router0, router1中使用 `show controller s0/0/0` 查看接口配置

router0中的s0/0/0为DCE, router1中为DTE
6. 再次测试主机间的连通性, 发现此时不同网段下主机可以通信

##### 1.6 思考题(2)
1. 在最左方添加好新的网络拓扑
2. 分配新添加网段涉及到的IP
| 设备 | 接口 | IP地址 | 子网掩码 | 网关 |
| -------- | ---- | -------------- | ------------- | --------- |
| Router 2 | F0/0 | 192.168.2.1/24 | 255.255.255.0 | |
| | F0/1 | 172.3.3.1/24 | 255.255.255.0 | |
| Router 1 | F0/2 | 192.168.2.2/24 | 255.255.255.0 | |
| PC4 | | 172.3.3.2/24 | 255.255.255.0 | 172.3.3.1 |
| PC5 | | 172.3.3.3/24 | 255.255.255.0 | 172.3.3.1 |
3. 路由配置
在router0上进行如下配置
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#network 192.168.2.0
Router(config-router)#exit
Router(config)#
```
在router2上进行如下配置
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip address 192.168.2.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#end
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#network 192.168.2.0
Router(config-router)#network 172.3.3.0
Router(config-router)#exit
Router(config)#
```
在router1上进行如下配置
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router rip
Router(config-router)#version 2
Router(config-router)#no auto-summary
Router(config-router)#network 192.168.1.0
Router(config-router)#network 192.168.2.0
Router(config-router)#exit
Router(config)#
```
4. 进行连通性测试
分别在不同子网的设备下尝试ping其他子网的主机, 发现均成功. 此时不同网段下主机可以通信

-----
### 2. OSPF
##### 2.1 基础拓扑连接与IP地址配置
其中接口, IP, 网关信息如下
| 名称 | 接口 | IP 地址 | 网关 |
| -------- | ---- | -------------- | --------- |
| Router A | F0/0 | 192.168.1.1/24 | |
| Router A | F0/1 | 172.1.1.1/24 | |
| Router B | F0/0 | 172.2.2.1/24 | |
| Router B | F0/1 | 192.168.1.2/24 | |
| PC0 | | 172.1.1.2/24 | 172.1.1.1 |
| PC1 | | 172.1.1.3/24 | 172.1.1.1 |
| PC2 | | 172.2.2.2/24 | 172.2.2.1 |
| PC3 | | 172.2.2.3/24 | 172.2.2.1 |
##### 2.2 配置路由器接口IP地址
在 Router0 中进行如下配置
```bash
Router>en
Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#no ip domain-look
Router(config)#int f0/0
Router(config-if)#ip address 192.168.1.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#int f0/1
Router(config-if)#ip address 172.1.1.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#
```
在 Router1 中配置与上述类似
##### 2.3 OSPF路由配置
```bash
在 Router0 中进行如下配置### Router0
Router(config)#router ospf 100
Router(config-router)#net 172.1.1.0 0.0.0.255 area 0
Router(config-router)#net 192.168.1.0 0.0.0.255 area 0
Router(config-router)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#
```
在 Router1 中配置与上述类似
进行上述配置之后, 使用 `show ip route` 得到输出如下
##### 1.4 连通性测试
在PC0中对其他三台主机使用ping命令, 三者均能ping通
##### 1.5 思考题(1)
1. 首先给两个路由器装上串口模块 `WIC-1T`
2. 使用 `Serial DCE` 线讲router0的 `Se0/0/0` 与router1的 `Se0/0/0` 相连
3. 在router0中配置DCE接口
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int s0/0/0
Router(config-if)#clock rate 64000
Router(config-if)#no shutdown
Router(config-if)#exit
```
4. 在router0中重新配置 OSPF
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 1
Router(config-router)#network 172.1.1.0 0.0.0.255 area 0
Router(config-router)#network 192.168.1.0 0.0.0.255 area 0
Router(config-router)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
```
5. router1中重新配置 OSPF
```bashh
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 1
Router(config-router)#network 172.2.2.0 0.0.0.255 area 0
Router(config-router)#network 192.168.1.0 0.0.0.255 area 0
Router(config-router)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
```
6. 分别在router0, router1中使用 `show controller s0/0/0` 查看接口配置

router0中的s0/0/0为DCE, router1中为DTE
6. 再次测试主机间的连通性, 发现此时不同网段下主机可以通信

##### 1.6 思考题(2)
1. 在最左方添加好新的网络拓扑

2. 分配新添加网段涉及到的IP
| 设备 | 接口 | IP地址 | 子网掩码 | 网关 |
| -------- | ---- | -------------- | ------------- | --------- |
| Router 2 | F0/0 | 192.168.2.1/24 | 255.255.255.0 | |
| | F0/1 | 172.3.3.1/24 | 255.255.255.0 | |
| Router 1 | F0/2 | 192.168.2.2/24 | 255.255.255.0 | |
| PC4 | | 172.3.3.2/24 | 255.255.255.0 | 172.3.3.1 |
| PC5 | | 172.3.3.3/24 | 255.255.255.0 | 172.3.3.1 |
3. 路由配置
在router0上进行如下配置
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 1
Router(config-router)#network 192.168.2.0 0.0.0.255 area 0
Router(config-router)#exit
Router(config)#
```
在router2上进行如下配置
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 1
Router(config-router)#network 192.168.2.0 0.0.0.255 area 0
Router(config-router)#network 172.3.3.0 0.0.0.255 area 0
Router(config-router)#exit
Router(config)#
```
在router1上进行如下配置
```bash
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 1
Router(config-router)#network 192.168.1.0 0.0.0.255 area 0
Router(config-router)#network 192.168.2.0 0.0.0.255 area 0
Router(config-router)#exit
Router(config)#进行连通性测试
```
分别在不同子网的设备下尝试ping其他子网的主机, 发现均成功. 此时不同网段下主机可以通信

# 七、讨论与结论
#### 讨论
**RIP vs OSPF**:
- RIP由于其实现简单,适合小型网络部署,但对于较复杂的网络环境,其性能和可扩展性有限。相比之下,OSPF因其高效性和灵活性,更适合于大型企业网络。
- RIP的最大跳数限制使其不适合跨越多个路由器的网络架构,而OSPF则没有这种限制。
#### 结论
本实验通过配置RIP和OSPF两种动态路由协议,深入理解了它们的工作机制及其适用场景。实验结果表明:
- RIP协议虽然易于配置,但由于其固有的局限性,在处理复杂网络时表现不佳。
- OSPF协议展示了更强的适应能力,能够有效应对较大规模的网络环境,提供更优化的路由选择。
通过本次实验,我们不仅掌握了如何在Cisco Packet Tracer中配置这两种路由协议,还加深了对网络路由概念的理解,同时也认识到合理选择路由协议对于构建高效、可靠的网络至关重要。