当前位置: 首页 > news >正文

配置OSPF路由

OSPF路由

1.OSPF路由

1.1 OSPF简介

      OSPF(Open Shortest Path First,开放式最短路径优先)路由协议是另一个比较常用的路由协议之一,它通过路由器之间通告网络接口的状态,使用最短路径算法建立路由表。在生成路由表时,OSPF协议优先考虑线路的速率等因素(费用),而经过的跳数则不是重点参考条件。
     OSPF 路由协议可以支持在一个自治区域中运行,也可以支持在多个自治区域之间运行。
下面主要介绍单区域内OSPF的配置方法。
    如图1所示,在网络拓扑图中,每个路由器都使用OSPF 协议生成路由表,其中RouterO与Router3之间线路的速率比较慢(费用比较高,为100),而其他三条线路的速率比较快(费用比较小,每条都是10)。

2.PC设备配置

2.1 PC设备信息及接口配置

配置PC设备的接口信息,如表1-1所示。

设备

连接的路由器

IP地址

子网掩码

网关地址

PC1

R1

192.168.1.2

255.255.255.0

192.168.1.1

PC2

R1

192.168.2.2

255.255.255.0

192.168.2.1

PC3

R2

172.16.0.2

255.255.0.0

172.16.0.1

PC4

R3

172.18.0.2

255.255.0.0

172.18.0.1

PC5

R4

172.17.0.2

255.255.0.0

172.17.0.1

表1-1

3.路由器接口配置

3.1 路由器接口信息及配置

配置路由器设备的接口信息,如表1-2所示。

路由器

接口

IP地址

子网掩码

OSPF费用

连接设备

R1

GigabitEthernet0/0/0

192.168.1.1

255.255.255.0

-

连接到设备PC1

R1

GigabitEthernet0/0/1

192.168.2.1

255.255.255.0

-

连接到设备PC2

R1

Serial0/1/0

13.0.0.2

255.0.0.0

100

连接到设备R4

R1

Serial0/1/1

10.0.0.1

255.0.0.0

10

连接到设备R2

R2

GigabitEthernet0/0/0

172.16.0.1

255.255.0.0

-

连接到设备PC3

R2

Serial0/1/0

11.0.0.1

255.0.0.0

10

连接到设备R3

R2

Serial0/1/1

10.0.0.2

255.0.0.0

10

连接到设备R1

R3

GigabitEthernet0/0/0

172.18.0.1

255.255.0.0

-

连接到设备PC4

R3

Serial0/1/1

11.0.0.2

255.0.0.0

10

连接到设备R2

R3

Serial0/1/0

12.0.0.1

255.0.0.0

10

连接到设备R4

R4

GigabitEthernet0/0/0

172.17.0.1

255.255.0.0

-

连接到设备PC5

R4

Serial0/1/1

13.0.0.1

255.0.0.0

-

连接到设备R1

R4

Serial0/1/0

12.0.0.2

255.0.0.0

-

连接到设备R3

表1-2

图1 使用OSPF生成路由表的网络拓扑图

4.OSPF配置

4.1 OSPF费用配置

然后在指定接口的配置模式下,使用“ip ospf cost 费用”命令为每一个接口上的线路配置费用。
  在Router0 中配置接口的我用,其中 Se1/0接口连接的线路费用是100,Se0/0费用是10.


R1(config)#interface s0/0 

R1(config-if) #ip ospf cost 10 

R1(config-if)#exit
R1(config) #interface s1/0
R1(config-if)#ip ospf cost 100


  在R2中配置全部接口的费用都是10。

R2(config)#interface s0/0 

R2(config-if)#ip ospf cost 10 

R2(config-if)#exit
Routerl(config)#interface s1/0
Routerl(config-if)#ip ospf cost 10


  在R3中配置全部接口的费用都是10。


R3(config) #interface s0/0 

R3(config-if)#ip ospf cost 10 

R3(config-if)#exit
R3(config)#interface s1/0
R3(config-if)#ip ospf cost 10

4.2 OSPF网络配置

      最后在每个路由器中使用router ospf命令,其后面需要指定一个数字作为OSPF进程的进程号,这样就可以进入指定进程号的OSPF配置环境中了。在这个配置环境中,同样使用network广播本地路由器直接连接的网络IP地址,其后的参数不是子网掩码,而是使用“area区域号”作为最后一个参数(由于实例是在一个区域中,即单区域,因此其区域号都设置为1)。

在路由器R1中配置OSPF协议。

R1(config)# router ospf 1
R1(config-router)#network 192.168.1.0 0.0.0.255 area 1

R1(config-router)#network 192.168.2.0 0.0.0.255 area 1

R1(config-router)#network 10.0.0.0 0.255.255.255 area 1

R1(config-router)#network 11.0.0.0 0.255.255.255 area 1

在路由器 Routerl中配置 OSPF协议。


R2(config) #router ospf 1
Routerl(config-router)#network 172.16.0.0 0.0.255.255 area 1 

Roüterl(config-router)#network 10.0.0.0 0.255.255.255 area 1 

Routerl(config-router)#network 11.0.0.0 0.255.255.255 area 1


  在路由器R3中配置OSPF协议。


outer(config)#router ospf 1
R3(config-router)#network 172.17.0.0 0.0.255.255 area 1 

R3(config-router)#network 11.0.0.00.255.255.255 area 1 

R3(config-router)#network 12.0.0.0 0.255.255.255 area 1

5.路由表查看

5.1 查看路由表

查看路由器R1中的路由表,其中以O开头的路由记录都是由OSPF协议计算得
到的。

R1#show ip route ospf

O 11.0.0.0 [110/20] via 10.0.0.2, 00:30:17, Serial0/1/1

O 12.0.0.0 [110/30] via 10.0.0.2, 00:30:07, Serial0/1/1

O 172.16.0.0 [110/11] via 10.0.0.2, 00:30:17, Serial0/1/1

O 172.17.0.0 [110/31] via 10.0.0.2, 00:30:07, Serial0/1/1

O 172.18.0.0 [110/21] via 10.0.0.2, 00:30:07, Serial0/1/1

R1#

结合线路的费用,OSPF 协议没有使用R1与R4之间的线路,而是使用了R1→R2→R3→R4路径(到 172.17.0.0 网络的下一跳路由是R2,其入口地址是10.0.0.2)。
在 PC1中使用tracert 命令检查实际路径是否与路由表中的记录相符合。

Cisco Packet Tracer PC Command Line 1.0

C:\>tracert 172.18.0.2

Tracing route to 172.18.0.2 over a maximum of 30 hops:

  1   0 ms      0 ms      0 ms      192.168.2.1

  2   0 ms      0 ms      5 ms      10.0.0.2

  3   0 ms      20 ms     1 ms      11.0.0.2

  4   *         11 ms     0 ms      172.18.0.2

Trace complete.

C:\>

路由器中还提供了多条命令用于查看OSPF协议的详细信息。
Show ip ospf neighbor 可以显示本地路由的OSPF邻居的信息,包括它们的路由器ID,接口地址和IP地址等。

R1#show ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address         Interface

2.2.2.2           0   FULL/  -        00:00:30    10.0.0.2        Serial0/1/1

4.4.4.4           0   FULL/  -        00:00:31    13.0.0.1        Serial0/1/0

R1#


Show ip ospf database 用于显示本地路由的OSPF库内容(与路由表内容相似)。

R1#show ip ospf database

OSPF Router with ID (1.1.1.1) (Process ID 1)

Router Link States (Area 1)

Link ID     ADV Router    Age    Seq#          Checksum Link count

1.1.1.1    1.1.1.1        607   0x80000008     0x00ac4f 6

4.4.4.4    4.4.4.4        608   0x80000007     0x009f4e 5

3.3.3.3    3.3.3.3        607   0x80000007     0x00cbfd 5

2.2.2.2    2.2.2.2        607   0x80000007     0x006679 5

R1#

Show ip protocols 命令用于显示与路由协议相关的参数与定时器信息,本命令也可以在启用了RIP路由协议的路由器中使用。

R1#show ip protocols

Routing Protocol is "ospf 1"

  Outgoing update filter list for all interfaces is not set

  Incoming update filter list for all interfaces is not set

  Router ID 1.1.1.1

  Number of areas in this router is 1. 1 normal 0 stub 0 nssa

  Maximum path: 4

  Routing for Networks:

    192.168.1.0 0.0.0.255 area 1

    192.168.2.0 0.0.0.255 area 1

    10.0.0.0 0.0.0.255 area 1

    13.0.0.0 0.0.0.255 area 1

  Routing Information Sources: 

    Gateway         Distance      Last Update

    1.1.1.1              110      00:15:02

    2.2.2.2              110      00:15:01

    3.3.3.3              110      00:15:03

    4.4.4.4              110      00:15:03

  Distance: (default is 110)

R1#

6.实验脚本

6.1 脚本示例

//R1

enconf thostn R1int g0/0/0ip add 192.168.1.1 255.255.255.0no shint g0/0/1ip add 192.168.2.1 255.255.255.0no shint s0/1/0ip add 13.0.0.2 255.0.0.0no ship ospf cost 100int s0/1/1ip add 10.0.0.1 255.0.0.0no ship ospf cost 10exitrouter ospf 1router-id 1.1.1.1network 192.168.1.0 0.0.0.255 area 1network 192.168.2.0 0.0.0.255 area 1network 10.0.0.0 255.255.255.0 area 1network 13.0.0.0 255.255.255.0 area 1endw!

//R2

enconf thostn R2int g0/0/0ip add 172.16.0.1 255.255.0.0no shint s0/1/0ip add 11.0.0.1 255.0.0.0no ship ospf cost 10int s0/1/1ip add 10.0.0.2 255.0.0.0no ship ospf cost 10exitrouter ospf 1router-id 2.2.2.2network 172.16.0.0 0.0.255.255 area 1network 11.0.0.0 255.255.255.0 area 1network 10.0.0.0 255.255.255.0 area 1endw!

//R3

enconf thostn R3int g0/0/0ip add 172.18.0.1 255.255.0.0no shint s0/1/1ip add 11.0.0.2 255.0.0.0no ship ospf cost 10int s0/1/0ip add 12.0.0.1 255.0.0.0no ship ospf cost 10exitrouter ospf 1router-id 3.3.3.3network 172.18.0.0 0.0.255.255 area 1network 11.0.0.0 255.255.255.0 area 1network 12.0.0.0 255.255.255.0 area 1endw!

//R4

enconf thostn R4int g0/0/0ip add 172.17.0.1 255.255.0.0no shint s0/1/1ip add 13.0.0.1 255.0.0.0no shint s0/1/0ip add 12.0.0.2 255.0.0.0no shexitrouter ospf 1router-id 4.4.4.4network 172.17.0.0 0.0.255.255 area 1network 12.0.0.0 255.255.255.0 area 1network 13.0.0.0 255.255.255.0 area 1endw!

当面对挑战时,不要害怕失败,因为每次失败都是成功的一步。相信自己,勇往直前,你能够战胜一切!

http://www.lryc.cn/news/179593.html

相关文章:

  • CCF CSP认证 历年题目自练Day17
  • 基于Matlab实现多因子选股模型(附上源码+数据)
  • 【中秋国庆不断更】OpenHarmony多态样式stateStyles使用场景
  • Qt扩展-QCustomPlot绘图基础概述
  • 二、局域网联机
  • 决策树剪枝:解决模型过拟合【决策树、机器学习】
  • Ubuntu部署运行ORB-SLAM2
  • 二十,镜面IBL--打印BRDF积分贴图
  • 自动驾驶:未来的道路上的挑战与机遇
  • Go 语言 iota 的神奇力量
  • 前端开发和后端开发的一些建议
  • 基于 SpringBoot+Vue 的教室人事档案管理系统
  • Lua学习笔记:require非.lua拓展名的文件
  • Python 编程基础 | 第三章-数据类型 | 3.3、浮点数
  • beego---ORM相关操作
  • 【网络原理】初始网络,了解概念
  • 对象存储,从单机到分布式的演进
  • 结构型设计模式——桥接模式
  • keepalived的vip实现nginx节点的主备
  • C++之std::atomic解决多线程7个问题(二百四)
  • tailwindcss 如何在 uniapp 中使用
  • oracle-使用PLSQL工具自行修改用户密码
  • 自动驾驶技术:现状与未来
  • C++ 类构造函数 析构函数
  • C++标准模板(STL)- 输入/输出操纵符-(std::get_time,std::put_time)
  • 蓝桥等考Python组别九级004
  • gitee 远程仓库操作基础(二)
  • Scala第四章节
  • 【C++入门指南】类和对象(上)
  • web:[极客大挑战 2019]PHP