1.1 单ospf区域
1.1.1 拓扑
1.1.2 配置步骤
①接口地址配置
R1:
#
interface GigabitEthernet0/0/0
ip address 10.2.0.1 255.255.255.0
#
interface LoopBack0
ip address 10.2.1.1 255.255.255.0
#
R2:
#
interface GigabitEthernet0/0/0
ip address 10.2.0.2 255.255.255.0
#
interface LoopBack0
ip address 10.2.2.2 255.255.255.0
#
R3:
#
interface GigabitEthernet0/0/0
ip address 10.2.0.3 255.255.255.0
#
interface LoopBack0
ip address 10.2.3.3 255.255.255.0
#
②配置单区域ospf
R1:
#
ospf 1 router-id 10.2.1.1
area 0.0.0.0
authentication-mode simple cipher test //配置ospf区域认证,使用密文方式,密码为”test“
network 10.2.0.0 0.0.0.255
network 10.2.1.1 0.0.0.0
#
R2:
#
ospf 1 router-id 10.2.2.2
area 0.0.0.0
authentication-mode simple cipher test //配置ospf区域认证,使用密文方式,密码为”test“
network 10.2.0.0 0.0.0.255
network 10.2.2.2 0.0.0.0
#
R3:
#
ospf 1 router-id 10.2.3.3
area 0.0.0.0
authentication-mode simple cipher test //配置ospf区域认证,使用密文方式,密码为”test“
network 10.2.0.0 0.0.0.255
network 10.2.3.3 0.0.0.0
#
③检查ospf配置结果
R1 ping R3 loopback0
#检查邻居信息
dis ospf peer
#检查ospf路由表
dis ospf routing
#检查ospf lsdb
dis ospf lsdb
④配置接口网络类型
loopback接口地址掩码为32,实际为24位,ospf默认loopback接口只连接一个节点,所以在type1 LSA中描述这个接口都以主机形式通告。
修改loopback接口类型为broadcast后,ospf在发布loopback的网络信息时,会按照真实的掩码进行发布:
R3:
#
interface LoopBack0
ip address 10.2.3.3 255.255.255.0
ospf network-type broadcast
#
⑤修改ospf接口的cost值
R1:
#
interface GigabitEthernet0/0/0
ip address 10.2.0.1 255.255.255.0
ospf cost 20
#
⑥silent-interface接口
配置互联接口为slient-interface后,不再从该接口发送、、接收hello报文,已经建立关系的邻居消失。无需建立ospf邻居关系的接口可以配置silent-interface。
1.2 ospf多区域
1.2.1 拓扑
注:R2的loopback1、2模拟外部网络,不在ospf中宣告。
1.2.2 配置步骤
①接口地址配置、修改loopback接口网络类型为broadcast
R1:
#
interface GigabitEthernet0/0/0
ip address 10.2.1.1 255.255.255.0
#
interface LoopBack0
ip address 10.1.1.1 255.255.255.0
ospf network-type broadcast
#
R2:
#
interface GigabitEthernet0/0/0
ip address 10.2.1.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 20.2.1.1 255.255.255.0
#
interface LoopBack0
ip address 10.1.2.2 255.255.255.0
ospf network-type broadcast
#
interface LoopBack1
ip address 100.2.0.1 255.255.255.0
#
interface LoopBack2
ip address 100.2.1.1 255.255.255.0
#
R3:
#
interface GigabitEthernet0/0/0
ip address 10.2.1.3 255.255.255.0
#
interface LoopBack0
ip address 10.1.3.3 255.255.255.0
ospf network-type broadcast
#
interface LoopBack1
ip address 100.3.0.1 255.255.255.0
ospf network-type broadcast
#
interface LoopBack2
ip address 100.3.1.1 255.255.255.0
ospf network-type broadcast
#
R4:
#
interface GigabitEthernet0/0/0
ip address 20.2.1.2 255.255.255.0
#
interface GigabitEthernet0/0/1
ip address 30.2.1.1 255.255.255.0
#
interface LoopBack0
ip address 10.1.4.4 255.255.255.0
ospf network-type broadcast
#
R5:
#
interface GigabitEthernet0/0/0
ip address 30.2.1.2 255.255.255.0
#
interface LoopBack0
ip address 10.1.5.5 255.255.255.0
ospf network-type broadcast
#
interface LoopBack1
ip address 100.5.0.1 255.255.255.0
ospf network-type broadcast
#
interface LoopBack2
ip address 100.5.1.1 255.255.255.0
ospf network-type broadcast
#
②配置ospf
R1:
#
ospf 1 router-id 10.1.1.1
area 0.0.0.2
network 10.1.1.1 0.0.0.0
network 10.2.1.0 0.0.0.255
#
R2:
#
ospf 1 router-id 10.1.2.2
area 0.0.0.0
network 10.1.2.2 0.0.0.0
network 20.2.1.0 0.0.0.255
area 0.0.0.2
network 10.2.1.0 0.0.0.255
#
R3:
#
ospf 1 router-id 10.1.3.3
area 0.0.0.2
network 10.1.3.3 0.0.0.0
network 10.2.1.0 0.0.0.255
network 100.3.0.1 0.0.0.0
network 100.3.1.1 0.0.0.0
#
R4:
#
ospf 1 router-id 10.1.4.4
area 0.0.0.0
network 10.1.4.4 0.0.0.0
network 20.2.1.0 0.0.0.255
area 0.0.0.1
network 30.2.1.0 0.0.0.255
#
R5:
#
ospf 1 router-id 10.1.5.5
area 0.0.0.1
network 10.1.5.5 0.0.0.0
network 30.2.1.0 0.0.0.255
network 100.5.0.1 0.0.0.0
network 100.5.1.1 0.0.0.0
#
③检查ospf配置
dis ospf peer brief
dis ospf routing
dis ospf lsdb
④在ABR、ASBR上配置路由汇总
a.域间路由汇总
在R4上汇总100.5.0.0/23,查看R2路由表,存在100.5.0.0/24、100.5.1.0/24两条路由表,将其汇总为一条。
R4:
#
ospf 1 router-id 10.1.4.4
area 0.0.0.1
abr-summary 100.5.0.0 255.255.254.0
#
再次查看R2路由表
在R2上汇总100.3.0.0/23,查看R4路由表,存在100.3.0.0/24、100.3.1.0/24两条路由表,将其汇总为一条
#
ospf 1 router-id 10.1.2.2
area 0.0.0.2
abr-summary 100.3.0.0 255.255.254.0
#
再次查看R4路由表
b.域外路由汇总
在R2上引入loopback1、loopback2接口路由
R2:
#
ospf 1 router-id 10.1.2.2
import-route direct
#
在R2上对外部路由进行汇总
#
ospf 1 router-id 10.1.2.2
asbr-summary 100.2.0.0 255.255.254.0
#
⑤修改ospf的参考带宽值
opsf默认参考带宽值为100Mbps,cost计算方式为参考带宽/逻辑带宽,且cost值只能为整数,所以在带宽上无法区分百兆以上。同时运行ospf的区域内参考带宽值必须一致。
#
ospf 1 router-id 10.1.2.2
bandwidth-reference 10000
⑥引入缺省路由
类型2的路由只考虑ASBR到该路由目的地址的cost值;
类型1的路由为域内cost值加ASBR到目的地址的cost值。
#
ip route-static 0.0.0.0 0.0.0.0 LoopBack0
#
ospf 1 router-id 10.1.1.1
default-route-advertise always type 1
#