Cisco OSPF結合前綴列表進行路由過濾實驗
一、實驗拓撲:
二、配置實驗1:前綴列表過濾路由:
1、基本的配置:
R1:
interface Loopback0
ip address 1.1.1.1 255.255.255.255
interface FastEthernet0/0
ip address 192.168.1.1 255.255.255.0
duplex auto
speed auto
router ospf 10
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.1 0.0.0.0 area 1
network 192.168.1.0 0.0.0.255 area 0
R2:
interface Loopback0
ip address 2.2.2.2 255.255.255.255
interface Loopback1
ip address 3.3.3.3 255.255.255.255
interface Loopback2
ip address 4.4.4.4 255.255.255.255
interface FastEthernet0/0
ip address 192.168.1.2 255.255.255.0
duplex auto
speed auto
router ospf 10
router-id 3.3.3.3
log-adjacency-changes
network 2.2.2.2 0.0.0.0 area 2
network 3.3.3.3 0.0.0.0 area 0
network 4.4.4.4 0.0.0.0 area 4
network 192.168.1.0 0.0.0.255 area 0
2、測試R1路由表:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/2] via 192.168.1.2, 00:00:13, FastEthernet0/0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/2] via 192.168.1.2, 00:00:13, FastEthernet0/0
4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/2] via 192.168.1.2, 00:00:13, FastEthernet0/0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
3、測試通過在R1上部署前綴列表,讓R1只能學習到4.4.4.4的地址:
ip prefix-list filter-ospf seq 5 deny 2.2.2.2/32
ip prefix-list filter-ospf seq 10 deny 3.3.3.3/32
ip prefix-list filter-ospf seq 15 permit 0.0.0.0/0 le 32 //配置允許所有的路由匹配通過
router ospf 10
distribute-list prefix filter-ospf in
4、再次測試R1路由表:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/2] via 192.168.1.2, 00:00:05, FastEthernet0/0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
三、配置實驗2:前綴列表鏈路分流:
1、在R1和R2之間增加一條鏈路,採用前綴列表分流。
R1:
interface Loopback0
ip address 1.1.1.1 255.255.255.255
interface Ethernet0/0
ip address 192.168.1.1 255.255.255.252
interface Ethernet0/1
ip address 192.168.1.5 255.255.255.252
router ospf 10
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.1 0.0.0.0 area 1
network 192.168.1.0 0.0.0.3 area 0
network 192.168.1.4 0.0.0.3 area 0
R2:
interface Loopback0
ip address 2.2.2.2 255.255.255.255
interface Loopback1
ip address 3.3.3.3 255.255.255.255
interface Loopback2
ip address 4.4.4.4 255.255.255.255
interface Ethernet0/0
ip address 192.168.1.2 255.255.255.252
interface Ethernet0/1
ip address 192.168.1.6 255.255.255.252
router ospf 10
router-id 3.3.3.3
log-adjacency-changes
network 2.2.2.2 0.0.0.0 area 2
network 3.3.3.3 0.0.0.0 area 0
network 4.4.4.4 0.0.0.0 area 4
network 192.168.1.0 0.0.0.3 area 0
network 192.168.1.4 0.0.0.3 area 0
2、查看R1路由表:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/11] via 192.168.1.6, 00:00:07, Ethernet0/1
[110/11] via 192.168.1.2, 00:00:07, Ethernet0/0
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/11] via 192.168.1.6, 00:00:07, Ethernet0/1
[110/11] via 192.168.1.2, 00:00:07, Ethernet0/0
4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/11] via 192.168.1.6, 00:00:11, Ethernet0/1
[110/11] via 192.168.1.2, 00:00:11, Ethernet0/0
192.168.1.0/30 is subnetted, 2 subnets
C 192.168.1.0 is directly connected, Ethernet0/0
C 192.168.1.4 is directly connected, Ethernet0/1
3、在R1上配置前綴列表進行鏈路分流:
ip prefix-list filter1 seq 5 deny 3.3.3.3/32
ip prefix-list filter1 seq 10 deny 4.4.4.4/32
ip prefix-list filter1 seq 15 permit 0.0.0.0/0 le 32
ip prefix-list filter2 seq 5 deny 2.2.2.2/32
ip prefix-list filter2 seq 10 deny 3.3.3.3/32
ip prefix-list filter2 seq 15 permit 0.0.0.0/0 le 32
router ospf 10
distribute-list prefix filter1 in Ethernet0/0
distribute-list prefix filter2 in Ethernet0/1
4、查看配置了前綴列表後的路由表:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
1.0.0.0/32 is subnetted, 1 subnets
C 1.1.1.1 is directly connected, Loopback0
2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/11] via 192.168.1.2, 00:00:06, Ethernet0/0
4.0.0.0/32 is subnetted, 1 subnets
O IA 4.4.4.4 [110/11] via 192.168.1.6, 00:00:06, Ethernet0/1
192.168.1.0/30 is subnetted, 2 subnets
C 192.168.1.0 is directly connected, Ethernet0/0
C 192.168.1.4 is directly connected, Ethernet0/1 //實現分流
四、配置實驗3:前綴列表過濾路由作用於路由重分發:
1、OSPF與EIGRP路由重分發使用前綴列表控制路由:
R1:
interface Serial0/0
ip address 172.16.1.1 255.255.255.252
serial restart-delay 0
router ospf 10
router-id 1.1.1.1
log-adjacency-changes
network 172.16.1.0 0.0.0.3 area 0
R2:
interface Loopback0
ip address 2.2.2.2 255.255.255.0
interface Serial0/0
ip address 172.16.1.2 255.255.255.252
serial restart-delay 0
interface Serial0/1
ip address 198.16.1.1 255.255.255.252
serial restart-delay 0
router eigrp 10
network 198.16.1.0 0.0.0.3
router ospf 10
router-id 2.2.2.2
log-adjacency-changes
redistribute eigrp 10 subnets
network 2.2.2.0 0.0.0.255 area 1
network 172.16.1.0 0.0.0.3 area 0
R3:
interface Loopback0
ip address 3.3.3.3 255.255.255.0
interface Loopback1
ip address 4.4.4.4 255.255.255.0
interface Serial0/1
ip address 198.16.1.2 255.255.255.252
serial restart-delay 0
router eigrp 10
network 3.3.3.0 0.0.0.255
network 4.4.4.0 0.0.0.255
network 198.16.1.0 0.0.0.3
no auto-summary
2、查看R1的路由表:
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/65] via 172.16.1.2, 00:00:04, Serial0/0
3.0.0.0/24 is subnetted, 1 subnets
O E2 3.3.3.0 [110/20] via 172.16.1.2, 00:00:04, Serial0/0
4.0.0.0/24 is subnetted, 1 subnets
O E2 4.4.4.0 [110/20] via 172.16.1.2, 00:00:04, Serial0/0
//從外部網絡學習到了3.3.3.0/24、4.4.4.0/24、198.16.1.0/30。
172.16.0.0/30 is subnetted, 1 subnets
C 172.16.1.0 is directly connected, Serial0/0
198.16.1.0/30 is subnetted, 1 subnets
O E2 198.16.1.0 [110/20] via 172.16.1.2, 00:00:04, Serial0/0
//學到了全路由
3、在R2上佈置前綴列表,讓R1只能從外部網絡學習到4.4.4.4/24
R2(config)#ip prefix-list filter seq 5 permit 4.4.4.0/24
R2(config)#router ospf 10
R2(config-router)#distribute-list prefix filter out eigrp 10 //允許EIGRP路由4.4.4.4被放入OSPF路由表
4、測試R1的網絡路由表:發現只有4.4.4.0的路由被學習到。
R1#show ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
2.0.0.0/32 is subnetted, 1 subnets
O IA 2.2.2.2 [110/65] via 172.16.1.2, 00:02:56, Serial0/0
4.0.0.0/24 is subnetted, 1 subnets
O E2 4.4.4.0 [110/20] via 172.16.1.2, 00:02:56, Serial0/0
172.16.0.0/30 is subnetted, 1 subnets
C 172.16.1.0 is directly connected, Serial0/0