路由器的基本配置(二)--- OSPF

有关OSPF的介绍,可以看另一篇博文https://blog.csdn.net/qq_34444097/article/details/80287919

OSPF的配置任务列表

  • 创建OSPF路由过程(require)
  • 使用逻辑地址作为路由ID(optional)
  • 配置OSPF区域认证(optional)
  • 在OSPF区域中配置路由汇总(optional)
  • 当路由被添加到OSPF中时,配置路由汇总(optional)
  • 配置OSFP适应不同的物理网络(optional)
  • 创建虚拟链路(optional)
  • 配置OSPF接口参数(optional)

- 创建OSPF路由过程
创建OSFP路由过程,定义IP地址范围,ip地址所属的OSPF区域。OSFP仅仅发送和接受OSPF报文,广播接口的链路状态到外部。

Router(config)# ip routing      //开启IP routing
Router(config)# router ospf process id[vrf vrf-name]        //开启OSPF,进入OSPF路由配置模式
Router(config-router)# network address wildcard-mask area area-id           //定义area的IP地址范围
Router(config-router)# end      //退回到特权模式

关闭OSPF

Router(config)# no router ospf process-id

下面是一个例子,如何开启OSPF协议

Router(config)# router ospf 1 
Router(config-router)# network 192.168.0.0 255.255.255.0 area 0     //area 0 表示没有区域划分
Router(config-router)# end

- 使用逻辑地址作为路由ID
OSPF允许最大的IP地址作为路由ID。如果接口被关闭,或者ip地址不存在,OSPF路由过程必须再次计算路由ID并且发送所有的路由信息给所有的邻接路由器。如果本地回环地址被配置了,路由过程将会选择回环接口IP地址作为路由ID,如果有多个lookback接口,最大的IP地址将会作为路由ID。
在全局模式下执行

Router(config)#  interface loopback num     //创建逻辑接口
Router(config-if)# ip address ip-address mask       //配置IP地址

- 配置区域认证
区域认证的配置是为了没有认证的和无效的设备学习无效的路由。在广播网络中,区域认证也可以防止无效的没有认证的设备变为被设计的设备为了保证路由系统的稳定性和闯入的防止。
有两种认证方法:
1.简单密码认证;
2.消息摘要认证。

  • 简单密码认证
    该认证允许为每一个区域配置密码。在同一区域中的路由器想要该路由域就不得不配置相同的密码。这种方法的缺点就是有消极攻击的漏洞。
Router(config-if)# ip ospf authentication       //在网络接口上设置认证类型
Router(config-if)# ip ospf authentication-key [0|7] key     //设置明文密码
Router(config-router)# area area-id authentication          //为区域设置明文认证模式
  • 消息摘要认证
    消息认证是一种加密的认证。需要为每一个路由器配置key和key-id,路由器使用建立在OSFP报文上的算法,通过key和key-id生成消息摘要,附加到报文。和简单认证不一样,密码不在线路上交换。一个非减少的序列号也包含在OSPF报文中去防止重放攻击。
Router(config-if)#  ip ospf authentication message-digest       //设置接口类型
Router(config-if)#  ip ospf message-digest-key key-id md5 [0|7] key

实例 - - - 配置OSPF虚拟连接

网络拓扑图:
这里写图片描述
IP地址分配:

  • WAN: 192.168.12.0/24
    WAN1:192.168.12.0/26
    WAN2:192.168.12.64/26
  • LAN:10.12.0.0/16
    LAN1:10.12.1.0/24
    LAN2:10.12.2.0/24
    路由器R2的配置过程
Router>enable
Router#config t
Router(config)#interface s0/1/0
Router(config-if)#ip address 192.168.12.1 255.255.255.192
Router(config-if)#exit
Router(config)#interface s0/1/1
Router(config-if)#ip address 192.168.12.65 255.255.255.192
Router(config-if)#exit
Router(config)#interface f0/0
Router(config-if)#ip address 10.12.1.1 255.255.255.0
Router(config-if)#exit
Router(config)#interface loopback0
Router(config-if)#ip address 22.2.2.2 255.255.255.255
Router(config-if)#exit
Router(config)#route ospf 1
Router(config-router)#network 192.168.12.0 0.0.0.63 area 0
Router(config-router)#network 192.168.12.64 0.0.0.63 area 0
Router(config-router)#network 10.12.1.0 0.0.0.255 area 1

路由器R1的配置

Router>enable
Router#config t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#interface s0/1/0
Router(config-if)#ip address 192.168.12.2 255.255.255.192
Router(config-if)#exit
Router(config)#interface f0/1
Router(config-if)#ip address 10.12.2.1 255.255.255.0
Router(config-if)#exit
Router(config)#router ospf 1
Router(config-router)#network 192.168.12.0 0.0.0.63 area 0
Router(config-router)#network 10.12.2.0 0.0.0.255 area 0
Router(config-router)#exit

路由器R3的配置

Router>enable
Router#config t
Router(config)#interface s0/1/1
Router(config-if)#ip address 192.168.12.66 255.255.255.192
Router(config-if)#exit
Router(config)#interface f0/1
Router(config-if)#ip address 10.12.2.2 255.255.255.0
Router(config-if)#exit
Router(config)#router ospf 1
Router(config-router)#network 192.168.12.64 0.0.0.63 area 0
Router(config-router)#network 10.12.2.0 0.0.0.255 area 0

PC2配置截图
这里写图片描述
PC1配置截图
这里写图片描述
PC3配置截图
这里写图片描述
测试结果
PC3 ping PC1
这里写图片描述

PC3 ping PC2
这里写图片描述

PC1 ping PC2
这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_34444097/article/details/80306678