10.1.12.0/24
其中交换机1的G1/0/1接口地址为10.1.12.1/24
交换机2的接口G1/0/2的地址为10.1.12.2/24
其他设备类似,互联网段标注在图中;10.1.14.0/24
;交换机1-交换机4-交换机3
;目标业务走向为1-2-3
;1.1.1.1
访问3.3.3.3
的业务切换至1-2-3
的走向;下一次割接时候再将11.11.11.11
访问33.33.33.33
的流量割接至1-2-3的走向。SW1的配置:
#
interface LoopBack0
ip address 1.1.1.1 255.255.255.255
#
interface LoopBack10
ip address 11.11.11.11 255.255.255.255
#
router id 1.1.1.1
ospf 1
import-route direct
area 0.0.0.0
#
interface GigabitEthernet1/0/1
port link-mode route
combo enable fiber
ip address 10.1.12.1 255.255.255.0
ospf network-type p2p
ospf 1 area 0.0.0.0
#
interface GigabitEthernet1/0/2
port link-mode route
combo enable fiber
ip address 10.1.14.1 255.255.255.0
ospf network-type p2p
ospf 1 area 0.0.0.0
SW2的配置
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
router id 2.2.2.2
ospf 1
area 0.0.0.0
#
interface GigabitEthernet1/0/1
port link-mode route
combo enable fiber
ip address 10.1.24.2 255.255.255.0
ospf network-type p2p
ospf 1 area 0.0.0.0
#
interface GigabitEthernet1/0/2
port link-mode route
combo enable fiber
ip address 10.1.12.2 255.255.255.0
ospf network-type p2p
ospf 1 area 0.0.0.0
SW3的配置:
interface LoopBack3
ip address 3.3.3.3 255.255.255.255
#
interface LoopBack10
ip address 33.33.33.33 255.255.255.255
#
router id 3.3.3.3
ospf 1
import-route direct
area 0.0.0.0
#
interface GigabitEthernet1/0/1
port link-mode route
combo enable fiber
ip address 10.1.14.4 255.255.255.0
ospf network-type p2p
ospf 1 area 0.0.0.0
ospf database-filter ase acl 3000
#
interface GigabitEthernet1/0/2
port link-mode route
combo enable fiber
ip address 10.1.24.4 255.255.255.0
ospf network-type p2p
ospf 1 area 0.0.0.0
SW4交换机为二层交换机,保持默认配置即可。
<SW1>dis ip routing-table
Destinations : 21 Routes : 22
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
1.1.1.1/32 Direct 0 0 127.0.0.1 InLoop0
3.3.3.3/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
10.1.12.0/24 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.0/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.12.255/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.14.0/24 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.0/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.14.255/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.24.0/24 O_INTRA 10 2 10.1.12.2 GE1/0/1
10.1.14.4 GE1/0/2
11.11.11.11/32 Direct 0 0 127.0.0.1 InLoop0
33.33.33.33/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
从上面信息可以看到3.3.3.3
和33.33.33.33
的路由,并且下一跳均为10.1.14.4
通过SW4走.
#定于ACL,用于过滤源是33.33.33.33的LSA
acl advanced 3000
rule 5 deny ip source 33.33.33.33 0 destination 255.255.255.255 0
rule 10 permit ip
这里需要注意以下,在过滤LSA的时候,ACL有一些特殊的点:
1. source用来过滤LSA的链路状态ID,destination用来过滤LSA的掩码,配置的掩码应该是连续的(当配置的掩码不连续时该过滤掩码的规则不生效)。
2. 如果在配置该命令前邻居路由器就已经收到了将要进行过滤的LSA,那么配置该命令后,这些LSA仍存在于邻居路由器的LSDB中
[H3C-GigabitEthernet1/0/1]ospf database-filter ase acl 3000
[H3C-GigabitEthernet1/0/1]%Aug 31 15:21:04:656 2023 H3C OSPF/5/OSPF_NBR_CHG_REASON: OSPF 1 Area 0.0.0.0 Router 3.3.3.3(GE1/0/1) CPU usage: 21%, IfMTU: 1500, Neighbor address: 10.1.14.1, NbrID:1.1.1.1 changed from Full to DOWN because database-filter configuration changed or database-filter ACL configuration changed at 2023-08-31 15:21:04:656.
%Aug 31 15:21:04:656 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.14.1(GigabitEthernet1/0/1) changed from FULL to DOWN.
[H3C-GigabitEthernet1/0/1]%Aug 31 15:21:13:471 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.14.1(GigabitEthernet1/0/1) changed from LOADING to FULL.
在接口下通过命令ospf database-filter ase acl 3000
对LSA进行过滤,配置之后发现OSPF邻居Down的提示。如果在现网当中这是一个极其危险的操作,不建议在现网中使用,此方案排除,但是做一下实验还是可以的,那继续分析下吧。
<SW1>dis ip routing-table
Destinations : 21 Routes : 22
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
1.1.1.1/32 Direct 0 0 127.0.0.1 InLoop0
3.3.3.3/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
10.1.12.0/24 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.0/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.12.255/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.14.0/24 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.0/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.14.255/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.24.0/24 O_INTRA 10 2 10.1.12.2 GE1/0/1
10.1.14.4 GE1/0/2
11.11.11.11/32 Direct 0 0 127.0.0.1 InLoop0
33.33.33.33/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
发现33.33.33.33
路由依旧存在,根据上面说到的,LSA的过滤对已经存在的LSA没有效果,此时SW1上是有对应的LSA的,因此我们rest一下SW1的OSPF试一下。
<H3C>reset ospf process
Reset OSPF process? [Y/N]:y
<H3C>%Aug 31 15:47:51:163 2023 H3C OSPF/5/OSPF_NBR_CHG_REASON: OSPF 1 Area 0.0.0.0 Router 1.1.1.1(GE1/0/1) CPU usage: 14%, IfMTU: 1500, Neighbor address: 10.1.12.2, NbrID:2.2.2.2 changed from Full to DOWN because the OSPF process was reset at 2023-08-31 15:47:51:163.
%Aug 31 15:47:51:165 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.12.2(GigabitEthernet1/0/1) changed from FULL to DOWN.
%Aug 31 15:47:51:165 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.14.4(GigabitEthernet1/0/2) changed from FULL to DOWN.
%Aug 31 15:47:53:173 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.14.4(GigabitEthernet1/0/2) changed from LOADING to FULL.
%Aug 31 15:47:53:173 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.12.2(GigabitEthernet1/0/1) changed from LOADING to FULL.
<SW1>disp ip routing-table
Destinations : 21 Routes : 22
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
1.1.1.1/32 Direct 0 0 127.0.0.1 InLoop0
3.3.3.3/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
10.1.12.0/24 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.0/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.12.255/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.14.0/24 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.0/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.14.255/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.24.0/24 O_INTRA 10 2 10.1.12.2 GE1/0/1
10.1.14.4 GE1/0/2
11.11.11.11/32 Direct 0 0 127.0.0.1 InLoop0
33.33.33.33/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
重置了OSPF进程之后发现33.33.33.33
的路由依旧存在,难道没有LSA过滤生效?其实不然,这里的33.33.33.33
的LSA其实是从SW2那边学习过来的,为了避免干扰,我们断开与SW2的接口,然后再重置一下OSPF进程看一下效果。
[SW1]int g 1/0/1
[SW1-GigabitEthernet1/0/1]shu
[SW1-GigabitEthernet1/0/1]%Aug 31 15:48:09:259 2023 H3C OSPF/5/OSPF_NBR_CHG_REASON: OSPF 1 Area 0.0.0.0 Router 1.1.1.1(GE1/0/1) CPU usage: 14%, IfMTU: 1500, Neighbor address: 10.1.12.2, NbrID:2.2.2.2 changed from Full to DOWN because the interface went down or MTU changed at 2023-08-31 15:48:09:259.
%Aug 31 15:48:09:259 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.12.2(GigabitEthernet1/0/1) changed from FULL to DOWN.
%Aug 31 15:48:09:260 2023 H3C IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/1 changed to down.
%Aug 31 15:48:09:260 2023 H3C IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet1/0/1 changed to down.
[SW1-GigabitEthernet1/0/1]qui
<SW1>reset ospf process
Reset OSPF process? [Y/N]:y
<SW1>%Aug 31 15:48:17:516 2023 H3C OSPF/5/OSPF_NBR_CHG_REASON: OSPF 1 Area 0.0.0.0 Router 1.1.1.1(GE1/0/2) CPU usage: 14%, IfMTU: 1500, Neighbor address: 10.1.14.4, NbrID:3.3.3.3 changed from Full to DOWN because the OSPF process was reset at 2023-08-31 15:48:17:516.
%Aug 31 15:48:17:518 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.14.4(GigabitEthernet1/0/2) changed from FULL to DOWN.
%Aug 31 15:48:22:534 2023 H3C OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.14.4(GigabitEthernet1/0/2) changed from LOADING to FULL.
<SW1>disp ip routing-table
Destinations : 16 Routes : 16
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
1.1.1.1/32 Direct 0 0 127.0.0.1 InLoop0
3.3.3.3/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
10.1.14.0/24 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.0/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.14.255/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.24.0/24 O_INTRA 10 2 10.1.14.4 GE1/0/2
11.11.11.11/32 Direct 0 0 127.0.0.1 InLoop0
<SW1>
将SW1与SW2互联的接口断开之后发现33.33.33.33
的路由消失了,也就意味着LSA生效了。思考一下
分析
SW1能从两个地方学到33.33.33.33
的路由,分别是从SW2以及SW3,我们再SW3上做了LSA过滤,因此SW1不能直接从SW3学习到33.33.33.33
的LSA,但是可以从SW2学习到。但是从上面的过程发现,从SW2学习到的33.33.33.33
的LSA的出接口依旧是G1/0/2,并没有切换到G1/0/1。这是什么原因呢?
在OSPF的5类LSA里,携带了ASBR的router ID,那么在ASBR所在区域里可以通过1类的LSA知道ASBR的位置,跨区域的场景需要通过4类LSA来告诉其他区域如何到达ASBR。目前我们属于第一种,同区域内。5类LSA里只携带了外部路由以及ASBR的router ID(即ADV Router)。虽然SW1是通过SW2学习到的LSA,但是在计算路由下一跳的时候还是要看一类的LSA。
下面我们将SW1-SW2的接口打开然后看一下LSDB信息。
[SW1]int g 1/0/1
[SW1-GigabitEthernet1/0/1]undo shu
[SW1-GigabitEthernet1/0/1]%Aug 31 16:07:28:666 2023 SW1 LLDP/6/LLDP_CREATE_NEIGHBOR: Nearest bridge agent neighbor created on port GigabitEthernet1/0/1 (IfIndex 2), neighbor's chassis ID is b0f2-17e0-0200, port ID is GigabitEthernet1/0/2.
%Aug 31 16:07:28:667 2023 SW1 IFNET/3/PHY_UPDOWN: Physical state on the interface GigabitEthernet1/0/1 changed to up.
%Aug 31 16:07:28:667 2023 SW1 IFNET/5/LINK_UPDOWN: Line protocol state on the interface GigabitEthernet1/0/1 changed to up.
%Aug 31 16:07:28:672 2023 SW1 OSPF/5/OSPF_NBR_CHG: OSPF 1 Neighbor 10.1.12.2(GigabitEthernet1/0/1) changed from LOADING to FULL.
[SW1-GigabitEthernet1/0/1]qui
[SW1]
[SW1]
[SW1]disp ip rou
[SW1]disp ip routing-table
Destinations : 21 Routes : 21
Destination/Mask Proto Pre Cost NextHop Interface
0.0.0.0/32 Direct 0 0 127.0.0.1 InLoop0
1.1.1.1/32 Direct 0 0 127.0.0.1 InLoop0
3.3.3.3/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
10.1.12.0/24 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.0/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.12.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.12.255/32 Direct 0 0 10.1.12.1 GE1/0/1
10.1.14.0/24 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.0/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.14.1/32 Direct 0 0 127.0.0.1 InLoop0
10.1.14.255/32 Direct 0 0 10.1.14.1 GE1/0/2
10.1.24.0/24 O_INTRA 10 2 10.1.14.4 GE1/0/2
11.11.11.11/32 Direct 0 0 127.0.0.1 InLoop0
33.33.33.33/32 O_ASE2 150 1 10.1.14.4 GE1/0/2
[SW1]
打开SW1-SW2的接口之后,33.33.33.33
的路由已经学习到,出接口是G1/0/2。
我们看一下这条5类LSA
[SW1]disp ospf lsdb ase 33.33.33.33
OSPF Process 1 with Router ID 1.1.1.1
Link State Database
Type : External
LS ID : 33.33.33.33
Adv Rtr : 3.3.3.3
LS age : 1364
Len : 36
Options : O E
Seq# : 80000003
Checksum : 0xe815
Net mask : 255.255.255.255
MTID 0 Metric : 1
E Type : 2
Forwarding Address: 0.0.0.0
Tag : 1
[SW1]
5类LSA并没有携带下一跳信息,只是携带了外部路由信息(LS ID),掩码信息,以及ASBR的Router ID3.3.3.3
。下一跳是根据一类LSA来查看如何去往3.3.3.3
这一台路由器的。
[SW1]disp ospf lsdb router 1.1.1.1
OSPF Process 1 with Router ID 1.1.1.1
Link State Database
Area: 0.0.0.0
Type : Router
LS ID : 1.1.1.1
Adv Rtr : 1.1.1.1
LS age : 45
Len : 72
Options : ASBR O E
Seq# : 8000000f
Checksum : 0xada6
Link Count: 4
Link ID: 2.2.2.2
Data : 10.1.12.1
Link Type: P-2-P
Metric : 1
Link ID: 3.3.3.3
Data : 10.1.14.1
Link Type: P-2-P
Metric : 1
Link ID: 10.1.12.0
Data : 255.255.255.0
Link Type: StubNet
Metric : 1
Link ID: 10.1.14.0
Data : 255.255.255.0
Link Type: StubNet
Metric : 1
OSPF Process 10 with Router ID 1.1.1.1
Link State Database
Area: 0.0.0.0
[SW1]
上面的信息中Link ID:3.3.3.3
代表的是SW1(1.1.1.1
)这台路由器有一个邻居的routerID为3.3.3.3
并且是通过10.1.14.1(Data : 10.1.14.1
)与之相连。因此在计算路由的时候下一跳应是10.1.14.1
所在的接口。这就是为什么下一跳仍然是G1/0/2的原因。
以上是通过LSA过滤的一些思考,但是此方法并不适应于现网,限制因素太多,比如会导致OSPF邻居诊断,需要清空LSDB等都是高风险的操作。那还有没有其他的办法呢?
在接口下使用LSA过滤的时候: