OSPF配置实验(一) |
您所在的位置:网站首页 › ospf修改routerid › OSPF配置实验(一) |
单区域OSPF 命令: R1(config)#router ospf 1 //启动OSPF进程 R1(config-router)#router-id 1.1.1.1 //配置路由器ID R1(config-router)#network 172.16.1.0 0.0.0.255 area 0 //通告直连网络 R1(config-router)#network 172.16.1.0 255.255.255.0 area 0 //通告直连网络 说明:网络地址的后面即可以跟通配符掩码,在高版本IOS中也可以跟网络掩码,IOS会自动转换成通配符掩码。
R1(config)#router ospf 1 R1(config-router)#router-id 1.1.1.1 R1(config-router)#network 172.16.1.0 0.0.0.255 area 0 R1(config-router)#network 172.16.12.0 0.0.0.255 area 0 R2(config)#router ospf 1 R2(config-router)#router-id 2.2.2.2 R2(config-router)#network 172.16.2.0 0.0.0.255 area 0 R2(config-router)#network 172.16.12.0 0.0.0.255 area 0 R2(config-router)#network 172.16.23.0 0.0.0.255 area 0 R3(config)#router ospf 1 R3(config-router)#router-id 3.3.3.3 R3(config-router)#network 172.16.3.0 0.0.0.255 area 0 R3(config-router)#network 172.16.23.0 0.0.0.255 area 0 R3(config-router)#network 172.16.34.0 0.0.0.255 area 0 R4(config)#router ospf 1 R4(config-router)#router-id 4.4.4.4 R4(config-router)#network 172.16.4.0 0.0.0.255 area 0 R4(config-router)#network 172.16.34.0 0.0.0.255 area 0
说明: 1.OSPF路由进程ID的范围在1-65535之间,而且只有本地含义,不同路由器的路由进程ID可以不同。如果要想启 动OSPF路由进程,至少确保有一个接口是up的。同一台路由器上可以启动多个OSPF进程,但会消耗更多的CPU 和内存等资源。 2.区域ID是0-4294967295的数,也可以是IP地址的格式A.B.C.D。当网络区域为0或0.0.0.0时称为主干区域。 3.Router ID选择遵循如下顺序: 1>最优先的是在OSPF进程中使用“router-id”指定了RID; 2>如果没有在OSPF进程中指定RID,则选择IP地址最大的环回接口的IP地址为RID; 3>如果没有环回接口,则选择活动的IP地址最大的物理接口的IP地址为RID。 ①如果使用“secondary”配置IP地址时,该地址不起作用,即不参与RID竞选; ②使用“router-id”后,应使用命令“clear ip ospf process”重置ospf进程,新配置的RID才能生效; ③2、3步只有在下次重启路由器时才会生效,即后来加入大的IP地址也不能选举为RID直到路由器重启。 4.Router ID重新选举规则: 1>使用“router-id”和“clear ip ospf process”命令; 2>重启路由器(不一定)。
实验调试 R1#show ip route ospf 1 //查看OSPF路由表 以上输出结果表明在同一个区域内,通过OSPF路由协议学习到的路由条目用代码“O”表示。 OSPF度量值cost计算公式 = 所有链路入接口的cost之和; 接口cost计算公式 = 108/带宽(bps)取整;环回接口的cost值为1。 说明: 1.环回接口所在网络的OSPF路由条目的掩码长度都是32位,这是环回接口的特性,尽管通告了24位,解决的办法 是在环回接口下修改网络类型为“Point-to-Point”这样收到的路由条目的掩码长度和通告的就能一致: R1(config-if)#ip ospf network point-to-point //设置网络类型为点到点网络 OSPF定义了6种网络类型,分别为:点对点、广播多路访问(BMA)、非广播多路访问(NBMA)、点对多点、环回接 口、虚拟链路(Virtual Links)。2.路由条目“172.16.4.4/32”的度量值为“193”,到路由器R1经过的入接口包括:R4的loopback0、R3的 S0/0、R2的S0/1及R1的S0/0,所以计算如下:1+108/1544000+108/1544000+108/1544000=193。也可以直接通过 命令“ip ospf cost”配置接口的cost值,并且它是优先计算的cost值的,命令如下: R1(config-if)#ip ospf cost 64 //设置接口cost为64
OSPF邻居关系不能建立的常见原因: 1.Hello间隔和Dead间隔不同; 1>同一链路上的Hello间隔和Dead间隔必须相同才能建立邻居关系; 2>默认时,Dead间隔是Hello间隔的4倍。可以在接口下通过如下命令调整: R1(config-if)#ip ospf hello-intrval 10 //设置Hello包发送间隔为10s R1(config-if)#ip ospf dead-interval 40 //设置Dead时间为40s 2.区域ID不一样; 3.特殊区域(如stub、nssa等)区域类型不匹配; 4.认证类型或密码不一致; 5.路由器ID相同; 6.Hello包被ACL拒绝; 7.链路上的MTU不匹配; 8.接口下OSPF网络类型不匹配。R1#show ip ospf database //查看OSPF链路状态数据库的信息 广播多路访问链路上的OSPF 命令: R1(config-router)#auto-cost reference-bandwidth 1000 //修改OSPF计算度量值的参考带宽,单位MB/s
R1(config-router)#auto-cost reference-bandwidth 1000 R2(config)#router ospf 1 R2(config-router)#auto-cost reference-bandwidth 1000R3(config)#router ospf 1 R3(config-router)#auto-cost reference-bandwidth 1000R4(config)#router ospf 1 R4(config-router)#auto-cost reference-bandwidth 1000说明:“auto-cost reference-bandwidth”命令是修改计算OSPF度量值参考带宽的。如果以太口带宽为千兆,而采用默认的百兆参考带宽,计算出来的cost是0.1,这显然是不太合理的。修改参考带宽要在路由器内所有的OSPF路由器上配置,目的是确保参考标准是相同的。 另外,当执行命令“auto-cost reference-bandwidth”时,系统也会提示如下信息:
说明: 1.DR和BDR有自己的组播地址224.0.0.6; 2.DR和BDR的选举是以各网络为基础的,也就是说DR和BDR选举是路由器的接口特性,而不是整个路由器的特性; 3.DR选举是非抢占的,除非人为地重新选举。 4.DR选举的原则: ①首要因素是时间,最先启动的路由器会启动一个Waite Timer计时器(Cisco规定是40s),在计时器超时前如 果没有新的OSPF路由器启动,它就被选举为DR,如果有新的路由器启动那么它们将按照②、③进行选举; ②如果同时启动,或者重新选举,则看接口优先级(范围为0-255),优先级最高的被选举成DR,默认情况下, 多路访问网络的接口优先级为1,点到点网络接口优先级为0,如果接口优先级被设置为0,那么该接口将不 参与DR选举,修改接口优先级命令是“ip ospf priority”: R1(config-if)#ip ospf priority 150 //修改端口优先级为150 ③如果同时启动,而优先级相同,则最后看RID,RID最高的被选举成DR。 5.重新选举DR/BDR的方法: ①重启路由器(不一定); ②“clear ip ospf process”(不一定)。 R4#show ip ospf int f0/0 //分别在路由器R4和R1上执行该命令
OSPF区域认证 命令 区域简单口令认证: R1(config-router)#area 0 authentication //区域0启用简单口令认证 R1(config-if)#ip ospf authentication-key cisco //配置认证密码 区域MD5认证: R1(config-router)#area 0 authentication message-digest //区域0启用MD5认证 R1(config-if)#ip ospf message-digest-key 1 md5 cisco //配置认证Key ID及密匙 区域简单口令认证 R1(config)#router ospf 1 R1(config-router)#area 0 authentication R1(config)#int s0/0 R1(config-if)#ip ospf authentication-key cisco R2(config)#router ospf 1 R2(config-router)#area 0 authentication R2(config)#int s0/0 R2(config-if)#ip ospf authentication-key cisco 实验调试 R1#show ip ospf R1#show ip ospf int s0/0 R1#debug ip ospf packet 认证: 1.如果R1区域0没有启用认证,而R2区域0启用简单口令认证,则R2会出现下面的信息: R2#debug ip ospf events R2#debug ip ospf events R1(config)#router ospf 1 R1(config-router)#area 0 authentication message-digest R1(config)#int s0/0 R1(config-if)#ip ospf message-digest-key cisco R2(config)#router ospf 1 R2(config-router)#area 0 authentication message-digest R2(config)#int s0/0 R2(config-if)#ip ospf message-digest-key cisco实验调试R1#show ip ospf
R1#show ip ospf int s0/0 以上输出最后两行信息表明该接口启用了MD5认证,而且使用密钥ID为1进行认证。 R1#debug ip ospf packet 认证 1.如果R1的区域0启用MD5认证,而R2的区域0启用简单口令认证,则R2会出现下面的信息: R2#debug ip ospf events OSPF接口认证 命令 接口简单口令认证: R1(config-if)#ip ospf authentication //接口启用简单口令认证 R1(config-if)#ip ospf authentication-key cisco //配置认证密码 接口MD5认证: R1(config-if)#ip ospf authentication message-digest //接口启用MD5认证 R1(config-if)#ip ospf message-digest-key 1 md5 cisco //配置认证Key ID及密匙 接口简单口令认证 R1(config)#int s0/0 R1(config-if)#ip ospf authentication R1(config-if)#ip ospf authentication-key cisco R2(config)#int s0/0 R2(config-if)#ip ospf authentication R2(config-if)#ip ospf authentication-key cisco 实验调试 R1#show ip ospf int s0/0 以上输出最后一行信息表明该接口启用了简单口令认证。 R1#debug ip ospf packet
认证: 1.如果R1的s0/0没有启用认证,而R2的s0/0启用简单口令认证,则R2会出现下面的信息: R2#debug ip ospf events 2.如果R1和R2的s0/0都启用简单口令认证,但R2的s0/0没有配置密码或密码错误,则R2会出现下面的信息: R2#debug ip ospf events
R1(config)#int s0/0 R1(config-if)#ip ospf authentication message-digest R1(config-if)#ip ospf message-digest-key cisco R2(config)#int s0/0 R2(config-if)#ip ospf authentication message-digest R2(config-if)#ip ospf message-digest-key cisco实验调试R1#show ip ospf int s0/0 R1#debug ip ospf packet 认证 1.如果R1的s0/0启用MD5认证,而R2的s0/0启用简单口令认证,则R2会出现下面的信息: R2#debug ip ospf events
命令: R1(config)#ip route 0.0.0.0 0.0.0.0 loopback 1 //添加静态默认路由 R1(config)#router ospf 1 R1(config-router)#default-information originate //再发布默认路由 说明:“default-information originate”命令后面可以加可选的“always”参数,如果不使用该参数,路由器上必须存在一条默认路由,否则该命令不产生任何效果。如果使用该参数,无论路由器上是否存在默认路由,路由器都会向OSPF区域内注入一条默认路由。 实验调试 R4#show ip route
R4#show ip ospf database
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |