一、OSPF基本概念 OSPF(Open Shortest Path First)是一个内部网关协议(Interior Gateway Protocol,简称IGP)。与RIP相对,OSPF是链路状态路有协议,而RIP是距离向量路由协议。 链路是路由器接口的另一种说法,因此OSPF也称为接口状态路由协议。OSPF通过路由器之间通告网络接口的状态来建立链路状态数据库,生成最短路径树,每个OSPF路由器使用这些最短路径构造路由表。


二、关于OSPF的实验操作 1、组网需求 • • 所有的交换机都运行 OSPF,并将整个自治系统划分为 3 个区域。 • • 其中 Switch A 和 Switch B 作为 ABR 来转发区域之间的路由。 • • 配置完成后,每台交换机都应学到 AS 内的到所有网段的路由 2配置步骤 (1) 配置各接口的 IP 地址 例SwitchB: <H3C>sys [H3C]hostname SwitchB [SwitchB]vlan 100 [SwitchB-vlan100]port g 1/0/10 [SwitchB-vlan100]quit [SwitchB]vlan 200 [SwitchB-vlan200]port g 1/0/20 [SwitchB-vlan200]quit [SwitchB]inter vlan 100 [SwitchB-Vlan-interface100]ip add 10.1.1.2 24 [SwitchB-Vlan-interface100]quit [SwitchB]inter vlan 200 [SwitchB-Vlan-interface200]ip add 10.3.1.1 24 [SwitchB-Vlan-interface200]quit [SwitchB]

(2) 配置 OSPF 基本配置 配置 Switch A。 <SwitchA> system-view [SwitchA] router id 10.2.1.1 [SwitchA] ospf [SwitchA-ospf-1] area 0 [SwitchA-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255 [SwitchA-ospf-1-area-0.0.0.0] quit [SwitchA-ospf-1] area 1 [SwitchA-ospf-1-area-0.0.0.1] network 10.2.1.0 0.0.0.255 [SwitchA-ospf-1-area-0.0.0.1] quit [SwitchA-ospf-1] quit

配置 Switch B。 <SwitchB> system-view [SwitchB] router id 10.3.1.1 [SwitchB] ospf [SwitchB-ospf-1] area 0 [SwitchB-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255 [SwitchB-ospf-1-area-0.0.0.0] quit [SwitchB-ospf-1] area 2 [SwitchB-ospf-1-area-0.0.0.2] network 10.3.1.0 0.0.0.255 [SwitchB-ospf-1-area-0.0.0.2] quit [SwitchB-ospf-1] quit 配置 Switch C。 <SwitchC> system-view [SwitchC] router id 10.4.1.1 [SwitchC] ospf [SwitchC-ospf-1] area 1 [SwitchC-ospf-1-area-0.0.0.1] network 10.2.1.0 0.0.0.255 [SwitchC-ospf-1-area-0.0.0.1] network 10.4.1.0 0.0.0.255 [SwitchC-ospf-1-area-0.0.0.1] quit [SwitchC-ospf-1] quit 配置 Switch D。 <SwitchD> system-view [SwitchD] router id 10.5.1.1 [SwitchD] ospf [SwitchD-ospf-1] area 2 [SwitchD-ospf-1-area-0.0.0.2] network 10.3.1.0 0.0.0.255 [SwitchD-ospf-1-area-0.0.0.2] network 10.5.1.0 0.0.0.255 [SwitchD-ospf-1-area-0.0.0.2] quit [SwitchD-ospf-1] quit

(3)验证配置 查看 Switch A 的 OSPF 邻居。 [SwitchA] display ospf peer verbose


查看 Switch A 的 OSPF 路由信息。 [SwitchA] display ospf routing


查看 Switch D 的 OSPF 路由信息。 [SwitchD] display ospf routing


在 Switch D 上使用 Ping 进行测试连通性。 [SwitchD] ping 10.4.1.1


3、实验操作2 配置OSPF引入自治系统外部路由

  1. 组网需求 • • 所有的交换机都运行 OSPF,整个自治系统划分为 3 个区域。 • • 其中 Switch A 和 Switch B 作为 ABR 来转发区域之间的路由。 • • 在 Switch C 上配置为 ASBR 引入外部路由(静态路由),且路由信息可正确的在 AS 内传播。

2.配置步骤 (1) 配置各接口的 IP 地址(略) (2) 配置OSPF(同前例 ) (3) 配置引入自治系统外部路由 在 Switch C 上配置一条到目的网段 3.1.2.0/24 的静态路由。 <SwitchC> system-view [SwitchC] ip route-static 3.1.2.1 24 10.4.1.2 在 Switch C 上配置 OSPF 引入静态路由。 [SwitchC] ospf 1 [SwitchC-ospf-1] import-route static 验证配置 查看 Switch D 的 ABR/ASBR 信息。 <SwitchD> display ospf abr-asbr 查看 Switch D 的 OSPF 路由表。 <SwitchD> display ospf routing


3、实验操作3 配置OSPF发布聚合路由

  1. 组网需求 • • Switch A 和 Switch B 位于 AS 200 内,AS 200 内使用 OSPF 作为 IGP 协议。 • • Switch C、Switch D 和 Switch E 位于 AS 100 内,AS 100 内使用 OSPF 作为 IGP 协议。 • • Switch B 和 Switch C 之间建立 EBGP 连接,配置 BGP 引入 OSPF 和直连路由,配置 OSPF 进程引入 BGP 路由。 • • 为了减小 Switch A 的路由表规模,在 Switch B 上配置路由聚合,只发布聚合后的路由 10.0.0.0/8。

  1. 配置步骤 (1) 配置接口的 IP 地址

(2) 配置 OSPF 配置 Switch A。 <SwitchA> system-view [SwitchA] router id 11.2.1.2 [SwitchA] ospf [SwitchA-ospf-1] area 0 [SwitchA-ospf-1-area-0.0.0.0] network 11.2.1.0 0.0.0.255 [SwitchA-ospf-1-area-0.0.0.0] quit [SwitchA-ospf-1] quit 配置 Switch B。 <SwitchB> system-view [SwitchB] router id 11.2.1.1 [SwitchB] ospf [SwitchB-ospf-1] area 0 [SwitchB-ospf-1-area-0.0.0.0] network 11.2.1.0 0.0.0.255 [SwitchB-ospf-1-area-0.0.0.0] quit [SwitchB-ospf-1] quit 配置 Switch C。 <SwitchC> system-view [SwitchC] router id 11.1.1.2 [SwitchC] ospf [SwitchC-ospf-1] area 0 [SwitchC-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255 [SwitchC-ospf-1-area-0.0.0.0] network 10.2.1.0 0.0.0.255 [SwitchC-ospf-1-area-0.0.0.0] quit [SwitchC-ospf-1] quit 配置 Switch D。 <SwitchD> system-view [SwitchD] router id 10.3.1.1 [SwitchD] ospf [SwitchD-ospf-1] area 0 [SwitchD-ospf-1-area-0.0.0.0] network 10.1.1.0 0.0.0.255 [SwitchD-ospf-1-area-0.0.0.0] network 10.3.1.0 0.0.0.255 [SwitchD-ospf-1-area-0.0.0.0] quit 配置 Switch E。 <SwitchE> system-view [SwitchE] router id 10.4.1.1 [SwitchE] ospf [SwitchE-ospf-1] area 0 [SwitchE-ospf-1-area-0.0.0.0] network 10.2.1.0 0.0.0.255 [SwitchE-ospf-1-area-0.0.0.0] network 10.4.1.0 0.0.0.255 [SwitchE-ospf-1-area-0.0.0.0] quit [SwitchE-ospf-1] quit

(3) 配置 BGP,引入 OSPF 和直连路由 配置 Switch B。 [SwitchB] bgp 200 [SwitchB-bgp] peer 11.1.1.2 as 100 [SwitchB-bgp] address-family ipv4 unicast [SwitchB-bgp-ipv4] import-route ospf [SwitchB-bgp-ipv4] import-route direct [SwitchB-bgp-ipv4] peer 11.1.1.2 enable 注意不要少了这句 [SwitchB-bgp-ipv4] quit [SwitchB-bgp] quit 配置 Switch C。 [SwitchC] bgp 100 [SwitchC-bgp] peer 11.1.1.1 as 200 [SwitchC-bgp] address-family ipv4 unicast [SwitchC-bgp-ipv4] import-route ospf [SwitchC-bgp-ipv4] import-route direct [SwitchC-bgp-ipv4] peer 11.1.1.1 enable #注意不要少了这句 [SwitchC-bgp-ipv4] quit [SwitchC-bgp] quit

(4) 在 Switch B 和 Switch C 上配置 OSPF 引入 BGP 路由 在 Switch B 上配置 OSPF 引入 BGP 路由。 [SwitchB] ospf [SwitchB-ospf-1] import-route bgp 在 Switch C 上配置 OSPF 引入 BGP 路由。 [SwitchC] ospf [SwitchC-ospf-1] import-route bgp 查看 SwitchA 的路由表信息。 [SwitchA] display ip routing-table

(5) 在 Switch B 上配置路由聚合,只发布聚合路由 10.0.0.0/8。 [SwitchB-ospf-1] asbr-summary 10.0.0.0 8 查看 Switch A 的路由表信息。 [SwitchA] display ip routing-table