春风十里不如你 —— Taozi - HCIP 2026-09-27T05:09:00+08:00 Typecho https://www.xiongan.host/index.php/feed/atom/tag/HCIP/ <![CDATA[【OSPF】基础配置案例]]> https://www.xiongan.host/index.php/archives/266/ 2026-09-27T05:09:00+08:00 2026-09-27T05:09:00+08:00 admin https://www.xiongan.host OSPF基础配置实例

ScreenShot_2026-09-27_044241_340.png

配置简单基础案例如图 有R1、R2、R3 要求使用OSPF 使得R1的1.1.1.1与R3的3.3.3.3互通

配置接口

#配置R1接口
[R1]int GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]dis this
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 10.0.1.254 255.255.255.0 
#
return
[R1-GigabitEthernet0/0/0]q
[R1]int LoopBack 0
[R1-LoopBack0]dis this
[V200R003C00]
#
interface LoopBack0
 ip address 1.1.1.1 255.255.255.0 
#
return
[R1-LoopBack0]

#配置R2接口
[R2]int GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]dis this
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 10.0.1.1 255.255.255.0 
#
return
[R2-GigabitEthernet0/0/0]q  
[R2]int GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]dis this
[V200R003C00]
#
interface GigabitEthernet0/0/1
 ip address 10.0.2.1 255.255.255.0 
#
return
[R2-GigabitEthernet0/0/1]

#配置R3接口
[R3]int GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]dis this
[V200R003C00]
#
interface GigabitEthernet0/0/0
 ip address 10.0.2.254 255.255.255.0 
#
return
[R3-GigabitEthernet0/0/0]q
[R3]int LoopBack 0
[R3-LoopBack0]dis this
[V200R003C00]
#
interface LoopBack0
 ip address 3.3.3.3 255.255.255.0 
#
return
[R3-LoopBack0]

配置OSPF

#配置R1 OSPF协议
[R1]ospf 1
[R1-ospf-1]dis this
[V200R003C00]
#
ospf 1 router-id 1.1.1.1 
 area 0.0.0.0 
  network 1.1.1.1 0.0.0.0 
  network 10.0.1.0 0.0.0.255
#
return
[R1-ospf-1]

#配置R2 OSPF协议
[R2]ospf 1
[R2-ospf-1]dis this
[V200R003C00]
#
ospf 1 router-id 2.2.2.2 
 area 0.0.0.0 
  network 10.0.1.0 0.0.0.255 
 area 0.0.0.1 
  network 10.0.2.0 0.0.0.255 
#
return
[R2-ospf-1]

#配置R3 OSPF协议
[R3]ospf 1
[R3-ospf-1]dis this
[V200R003C00]
#
ospf 1 router-id 3.3.3.3 
 area 0.0.0.1 
  network 3.3.3.3 0.0.0.0 
  network 10.0.2.0 0.0.0.255 
#
return
[R3-ospf-1]

此时配置完成后 会有相关提示 最终有Full 代表邻居建立完成

image-20260927045410811.png

结果验证

在路由器R2上查看OSPF邻居表 最终状态为Full 代表成功

[R2]dis ospf peer brief 

     OSPF Process 1 with Router ID 2.2.2.2
          Peer Statistic Information
 ----------------------------------------------------------------------------
 Area Id          Interface                        Neighbor id      State    
 0.0.0.0          GigabitEthernet0/0/0             1.1.1.1          Full        
 0.0.0.1          GigabitEthernet0/0/1             3.3.3.3          Full        
 ----------------------------------------------------------------------------

从R1测试是否正常通3.3.3.3 查看正常通信

ScreenShot_2026-09-27_045757_366.png

如果不成功 可以从R2路由器的出接口抓包查看

ScreenShot_2026-09-27_045959_396.png

扩展

如果在R1新增10.10.10.10地址 R3新增30.30.30.30地址 让他们两个互通

只需要将新网段宣告进 OSPF

#在 R1 上操作:
<R1> system-view
[R1] ospf 1
[R1-ospf-1] area 0.0.0.0
[R1-ospf-1-area-0.0.0.0] network 10.10.10.0 0.0.0.255   <-- 宣告新网段
[R1-ospf-1-area-0.0.0.0] quit
[R1-ospf-1] quit

在 R3 上操作:
<R3> system-view
[R3] ospf 1
[R3-ospf-1] area 0.0.0.1   <-- 注意:R3 之前配置的是 Area 1
[R3-ospf-1-area-0.0.0.1] network 30.30.30.0 0.0.0.255   <-- 宣告新网段
[R3-ospf-1-area-0.0.0.1] quit
[R3-ospf-1] quit

注意:R2 不需要宣告 10.10.10.0 或 30.30.30.0,它只负责中转
测试结果:
<R1>ping -a 10.10.10.10 30.30.30.30
  PING 30.30.30.30: 56  data bytes, press CTRL_C to break
    Reply from 30.30.30.30: bytes=56 Sequence=1 ttl=254 time=40 ms
    Reply from 30.30.30.30: bytes=56 Sequence=2 ttl=254 time=30 ms
    Reply from 30.30.30.30: bytes=56 Sequence=3 ttl=254 time=30 ms
    Reply from 30.30.30.30: bytes=56 Sequence=4 ttl=254 time=40 ms
    Reply from 30.30.30.30: bytes=56 Sequence=5 ttl=254 time=30 ms

  --- 30.30.30.30 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 30/34/40 ms

在实际交换机或者路由器内如何使用抓包工具 抓取接口处数据

ScreenShot_2026-09-27_051626_778.png

]]>
<![CDATA[【HCIP】路由策略与路由控制]]> https://www.xiongan.host/index.php/archives/203/ 2023-05-06T20:24:50+08:00 2023-05-06T20:24:50+08:00 admin https://www.xiongan.host 路由策略与路由控制

实验组网

1682218215575

每台设备都创建了Loopback0,地址为10.123.x.x/32(x为设备号)

在R2、R4上测试ip连通性

1682218707426

1682218720689

配置OSPF、IS-IS

R1、R2、R3使用Loopback0接口地址作为Router ID,在互联接口、Loopback0接口上激活OSPF。

//R1
[R1]ospf 1 router-id 10.123.1.1
[R1-ospf-1] area 0
[R1-ospf-1-area-0.0.0.0] network 10.123.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0] network 10.123.12.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0] quit
[R1-ospf-1] quit

1682219138575

//R2
[R2]ospf 1 router-id 10.123.2.2
[R2-ospf-1] area 0.0.0.0
[R2-ospf-1-area-0.0.0.0] network 10.123.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0] network 10.123.12.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0] network 10.123.23.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0] quit
[R2-ospf-1] quit

1682219234462

//R3
[R3]ospf 1 router-id 10.123.3.3
[R3-ospf-1] area 0.0.0.0
[R3-ospf-1-area-0.0.0.0] network 10.123.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0] network 10.123.23.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0] quit
[R3-ospf-1] quit

1682219275126

在R2上检查OSPF邻居概要信息

1682219311591

R3、R4上配置IS-IS,区域为49.0001,系统ID采用0000.0000.000x格式(x为设备编号),两台设备都为Level-1路由器,在互联接口、R4的Loopback0接口上激活IS-IS。

//R3
[R3]isis 1
[R3-isis-1] is-level level-1
[R3-isis-1] network-entity 49.0001.0000.0000.0003.00
[R3-isis-1] quit
[R3]interface GigabitEthernet0/0/1
[R3-GigabitEthernet0/0/1] isis enable 1
[R3-GigabitEthernet0/0/1] quit

1682219708071

//R4
[R4]isis 1
[R4-isis-1] is-level level-1
[R4-isis-1] network-entity 49.0001.0000.0000.0004.00
[R4-isis-1] quit
[R4]interface GigabitEthernet0/0/0
[R4-GigabitEthernet0/0/0] isis enable 1
[R4-GigabitEthernet0/0/0] quit
[R4]interface LoopBack 0
[R4-LoopBack0] isis enable 1
[R4-LoopBack0] quit

1682219778719

在R3上检查IS-IS邻居状态

1682219823838

在R1上引入直连路由

创建IP前缀列表1,匹配Loopback1接口路由(A业务网段)

[R1]ip ip-prefix 1 index 10 permit 172.16.1.0 24 greater-equal 24 less-equal 24

创建IP前缀列表2,匹配Loopback2接口路由(B业务网段)

[R1]ip ip-prefix 2 index 10 permit 172.16.2.0 24 greater-equal 24 less-equal 24

1682220874885

创建Route-Policy hcip,并创建节点10、20,分别调用IP前缀列表1、2,打上路由标记

[R1]route-policy hcip permit node 10
[R1-route-policy] if-match ip-prefix 1
[R1-route-policy] apply tag 10
[R1-route-policy] quit
[R1]route-policy hcip permit node 20
[R1-route-policy] if-match ip-prefix 2
[R1-route-policy] apply tag 20 
[R1-route-policy] quit

1682220900637

在R1的OSPF中引入直连路由,调用Route-Policy hcip

[R1]ospf 1
[R1-ospf-1] import-route direct route-policy hcip

1682220936669

在R1上查看OSPF LSDB

1682220968693

Loopback1、2接口路由已经被成功引入OSPF中

在R1上查看OSPF LSDB中AS-external LSA 172.16.1.0、172.16.2.0的相关信息

1682221042318

在R2上配置过滤策略

在R2上配置Filter-Policy对接收的OSPF路由进行过滤,只接收B业务网段的路由。

查看配置Filter-Policy前的OSPF路由表

1682221201853

查看配置Filter-Policy前的IP路由表中的OSPF路由

1682221298477

配置基础ACL

[R2]acl number 2000
[R2-acl-basic-2000] rule 5 deny source 172.16.1.0 0.0.0.255
[R2-acl-basic-2000] rule 10 permit

1682221695477

在OSPF中部署入方向的Filter-Policy,调用ACL 2000

[R2]ospf 1
[R2-ospf-1] filter-policy 2000 import

1682221843867

查看配置Filter-Policy后的OSPF路由表

1682221875196

查看配置Filter-Policy后的IP路由表中的OSPF路由

1682222005316

在IP路由表中路由172.16.2.0/24已经不存在,但是在OSPF路由表中依旧存在。这验证了对于OSPF,Filter-Policy只是限制路由加入IP路由表,不影响本地的LSDB以及LSA的传递。

在R3上查看IP路由表中的OSPF路由

1682222044354

R3的IP路由表中OSPF外部路由172.16.1.0/24、172.16.2.0/24依旧存在

在R3上将OSPF路由引入到IS-IS

在R3上将OSPF路由引入到IS-IS中,通过Route-Policy匹配路由标记,只引入A业务网段的OSPF外部路由。

创建Route-Policy hcip

[R3]route-policy hcip permit node 10
[R3-route-policy] if-match tag 10
[R3-route-policy] quit

1682222232010

在IS-IS中引入OSPF路由,调用Route-Policy hcip只引入A业务网段的OSPF外部路由

[R3]isis 1
[R3-isis-1] import-route ospf 1 level-1 route-policy hcip

1682222248020

查看R3的IS-IS路由表

1682222273164

Level-1的路由重分发表中只有172.16.1.0/24。

]]>