R1 R2 R3属于OSPF 的骨干区域,R1 R2 R3位于10.1.1.0/24 网段
R2 R3 R4 位于OSPF 的40.1.1.0/24 网段.
希望R2 作为 10.1.1.0 网段的DR, R3作为BDR;R3 作为40.1.1.0 网段的DR,R2 作为BDR.
基础配置:
R1 配置:
R1(config)#line console 0
R1(config-line)#exec-timeout 0 0
R1(config-line)#logging synchronous
R1(config-line)#exit
R1(config)#no ip do lo
R1(config)#interface loopback 0
R1(config-if)#ip address 1.1.1.1 255.255.255.255
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#interface f0/0
R1(config-if)#ip address 10.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R2配置:
R2(config)#line console 0
R2(config-line)#exec-timeout 0 0
R2(config-line)#logging synchronous
R2(config-line)#exit
R2(config)#no ip do lo
R2(config)#ho R2
R2(config)#interface loopback 0
R2(config-if)#ip address 2.2.2.2 255.255.255.255
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface f0/0
R2(config-if)#ip address 10.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#interface f0/1
R2(config-if)#ip address 40.1.1.2 255.255.255.0
R2(config-if)#no shu
R2(config-if)#no shutdown
R2(config-if)#exit
R3配置:
R3(config)#line console 0
R3(config-line)#exec-timeout 0 0
R3(config-line)#logging synchronous
R3(config-line)#exit
R3(config)#no ip do lo
R3(config)#ho R3
R3(config)#interface loopback 0
R3(config-if)#ip address 3.3.3.3 255.255.255.255
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#interface f0/0
R3(config-if)#ip address 10.1.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#interface f0/1
R3(config-if)#ip address 40.1.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R4配置:
R4(config)#line console 0
R4(config-line)#exec-timeout 0 0
R4(config-line)#logging synchronous
R4(config-line)#exit
R4(config)#no ip do lo
R4(config)#ho R4
R4(config)#interface loopback 0
R4(config-if)#ip address 4.4.4.4 255.255.255.255
R4(config-if)#no shutdown
R4(config-if)#exit
R4(config)#interface f0/1
R4(config-if)#ip address 40.1.1.4 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#exit
启用OSPF,默认情况下,OSPF进行DR选举时的优先级 默认为1,比较规则是 优先级越大越优先,优先级相同, router-id越大越优先。因此干预选举可以通过设置router-id和修改接口的优先级进行。在10.1.1.0 网段上,由于R1 R2 R3的优先级为默认的1 ,因此 优先级大的 R3(3.3.3.3),就成为DR,R2(2.2.2.2)成为BDR.但是要考虑,如果R1 R2率先接入网络,当DR BDR选举完成之后再接入R3的话,R3错过选举之后,就不能抢占DR BDR了。
R2 R3 R4也一样,因此正常情况下R4为DR,R3为BDR
R1配置:
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1 //手工指定router-id
R1(config-router)#network 1.1.1.1 0.0.0.0 area 0 --------采取反子网掩码的方式进行通告,类似于通告了一个1.1.1.1 255.255.255.255 的路由信息,采用反子网掩码,是为了区别配置IP地址是的子网掩码
R1(config-router)#network 10.1.1.0 0.0.0.255 area 0
R1(config-router)#exit
R1(config)#end
R2配置:
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 2.2.2.2 0.0.0.0 area 0
R2(config-router)#network 10.1.1.0 0.0.0.255 area 0
R2(config-router)#network 40.1.1.0 0.0.0.255 area 0
R2(config-router)#end
R3配置:
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 3.3.3.3 0.0.0.0 area 0
R3(config-router)#network 10.1.1.0 0.0.0.255 area 0
R3(config-router)#network 40.1.1.0 0.0.0.255 area 0
R3(config-router)#exit
R4 配置:
R4(config)#router ospf 1
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 4.4.4.4 0.0.0.0 area 0
R4(config-router)#network 40.1.1.0 0.0.0.255 area 0
R4(config-router)#end
查看邻居表:
R1配置:
R1#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/BDR 00:00:32 10.1.1.2 FastEthernet0/0
3.3.3.3 1 FULL/DR 00:00:31 10.1.1.3 FastEthernet0/0
R2配置:
R2#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 1 FULL/BDR 00:00:38 40.1.1.3 FastEthernet0/1
4.4.4.4 1 FULL/DR 00:00:38 40.1.1.4 FastEthernet0/1
1.1.1.1 1 FULL/DROTHER 00:00:38 10.1.1.1 FastEthernet0/0
3.3.3.3 1 FULL/DR 00:00:36 10.1.1.3 FastEthernet0/0
R2#
R3配置:
R3#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/DROTHER 00:00:37 40.1.1.2 FastEthernet0/1
4.4.4.4 1 FULL/DR 00:00:36 40.1.1.4 FastEthernet0/1
1.1.1.1 1 FULL/DROTHER 00:00:32 10.1.1.1 FastEthernet0/0
2.2.2.2 1 FULL/BDR 00:00:37 10.1.1.2 FastEthernet0/0
R3#
R4配置:
R4#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/DROTHER 00:00:36 40.1.1.2 FastEthernet0/1
3.3.3.3 1 FULL/BDR 00:00:35 40.1.1.3 FastEthernet0/1
R4#
R4#
这时,为了满足要求,让R2成为10.1.1.0 网段的DR,可以修改R2的router-id,改为22.22.22.22
,只要比R3的3.3.3.3 大就可以;为了是R3成为40.1.1.0 网段的DR,可以修改R3的f0/1
的接口优先级。
R2配置:
R2(config)#router ospf 1
R2(config-router)#ro
R2(config-router)#router-id 22.22.22.22
Reload or use "clear ip ospf process" command, for this to take effect //系统提示,要想新的router-id生效,要重启OSPF进程
R2(config-router)#
R2(config-router)#end
R3 配置:
R3(config)#interface f0/1
R3(config-if)#ip ospf priority 5
R3(config-if)#end
R3#
这个时候,将R1 R2 R3 R4的OSPF进程重启,然后再观察。
R1配置:
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: y //重启OSPF进程,这个要在四个路由器上同时敲下去
R1#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 1 FULL/BDR 00:00:35 10.1.1.3 FastEthernet0/0
22.22.22.22 1 FULL/DR 00:00:36 10.1.1.2 FastEthernet0/0
R1#
R2配置:
R2#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R2#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 5 FULL/DR 00:00:34 40.1.1.3 FastEthernet0/1
4.4.4.4 1 FULL/DROTHER 00:00:36 40.1.1.4 FastEthernet0/1
1.1.1.1 1 FULL/DROTHER 00:00:35 10.1.1.1 FastEthernet0/0
3.3.3.3 1 FULL/BDR 00:00:34 10.1.1.3 FastEthernet0/0
R2#
R3配置:
R3#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R3#
R3#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
4.4.4.4 1 FULL/DROTHER 00:00:33 40.1.1.4 FastEthernet0/1
22.22.22.22 1 FULL/BDR 00:00:32 40.1.1.2 FastEthernet0/1
1.1.1.1 1 FULL/DROTHER 00:00:32 10.1.1.1 FastEthernet0/0
22.22.22.22 1 FULL/DR 00:00:32 10.1.1.2 FastEthernet0/0
R3#
R4配置:
R4#sho ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 5 FULL/DR 00:00:35 40.1.1.3 FastEthernet0/1
22.22.22.22 1 FULL/BDR 00:00:36 40.1.1.2 FastEthernet0/1
R4#
R4#clear ip ospf process
Reset ALL OSPF processes? [no]: y
R4#
这时看到10.1.1.0网段,R2的router-id最大成为DR,R3的router-id次之,成为BDR;
40.1.1.0 网段,R3的优先级最大成为DR,R2的router-id最大,成为BDR.