A-A+

Cisco OSPF结合前缀列表进行路由过滤、分流和重分发实验

2015年11月18日 站长资讯 暂无评论

今天进行的是采用cisco路由器进行组网,采用OSPF(开放式最短路径优先)协议结合前缀列表,以达到路由过滤、前缀列表链路分流、前缀列表过滤路由作用于路由重分发的目的。下面是三个实验的拓扑图和配置命令:

一、实验拓扑:

二、配置实验1:前缀列表过滤路由:

1、基本的配置:

  1. R1:  
  2.   
  3. interface Loopback0  
  4.   
  5.  ip address 1.1.1.1 255.255.255.255  
  6.   
  7. interface FastEthernet0/0  
  8.   
  9.  ip address 192.168.1.1 255.255.255.0  
  10.   
  11.  duplex auto  
  12.   
  13.  speed auto  
  14.   
  15. router ospf 10  
  16.   
  17.  router-id 1.1.1.1  
  18.   
  19.  log-adjacency-changes  
  20.   
  21.  network 1.1.1.1 0.0.0.0 area 1  
  22.   
  23.  network 192.168.1.0 0.0.0.255 area 0  
  24.   
  25.    
  26.   
  27. R2:  
  28.   
  29. interface Loopback0  
  30.   
  31.  ip address 2.2.2.2 255.255.255.255  
  32.   
  33. interface Loopback1  
  34.   
  35.  ip address 3.3.3.3 255.255.255.255  
  36.   
  37. interface Loopback2  
  38.   
  39.  ip address 4.4.4.4 255.255.255.255         
  40.   
  41. interface FastEthernet0/0  
  42.   
  43.  ip address 192.168.1.2 255.255.255.0  
  44.   
  45.  duplex auto  
  46.   
  47.  speed auto  
  48.   
  49. router ospf 10  
  50.   
  51.  router-id 3.3.3.3  
  52.   
  53.  log-adjacency-changes  
  54.   
  55.  network 2.2.2.2 0.0.0.0 area 2  
  56.   
  57.  network 3.3.3.3 0.0.0.0 area 0  
  58.   
  59.  network 4.4.4.4 0.0.0.0 area 4  
  60.   
  61.  network 192.168.1.0 0.0.0.255 area 0  

2、测试R1路由表:

  1. R1#show ip route  
  2.   
  3. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP  
  4.   
  5.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  6.   
  7.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2  
  8.   
  9.        E1 - OSPF external type 1, E2 - OSPF external type 2  
  10.   
  11.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2  
  12.   
  13.        ia - IS-IS inter area, * - candidate default, U - per-user static route  
  14.   
  15.        o - ODR, P - periodic downloaded static route  
  16.   
  17. Gateway of last resort is not set  
  18.   
  19.      1.0.0.0/32 is subnetted, 1 subnets  
  20.   
  21. C       1.1.1.1 is directly connected, Loopback0  
  22.   
  23.      2.0.0.0/32 is subnetted, 1 subnets  
  24.   
  25. O IA    2.2.2.2 [110/2] via 192.168.1.2, 00:00:13, FastEthernet0/0  
  26.   
  27.      3.0.0.0/32 is subnetted, 1 subnets  
  28.   
  29. O       3.3.3.3 [110/2] via 192.168.1.2, 00:00:13, FastEthernet0/0  
  30.   
  31.      4.0.0.0/32 is subnetted, 1 subnets  
  32.   
  33. O IA    4.4.4.4 [110/2] via 192.168.1.2, 00:00:13, FastEthernet0/0  
  34.   
  35. C    192.168.1.0/24 is directly connected, FastEthernet0/0  

3、测试通过在R1上部署前缀列表,让R1只能学习到4.4.4.4的地址:

  1. ip prefix-list filter-ospf seq 5 deny 2.2.2.2/32  
  2.   
  3. ip prefix-list filter-ospf seq 10 deny 3.3.3.3/32  
  4.   
  5. ip prefix-list filter-ospf seq 15 permit 0.0.0.0/0 le 32    //配置允许所有的路由匹配通过  
  6.   
  7. router ospf 10  
  8.   
  9. distribute-list prefix filter-ospf in  

4、再次测试R1路由表:

  1. R1#show ip route  
  2.   
  3. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP  
  4.   
  5.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  6.   
  7.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2  
  8.   
  9.        E1 - OSPF external type 1, E2 - OSPF external type 2  
  10.   
  11.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2  
  12.   
  13.        ia - IS-IS inter area, * - candidate default, U - per-user static route  
  14.   
  15.        o - ODR, P - periodic downloaded static route  
  16.   
  17. Gateway of last resort is not set  
  18.   
  19.      1.0.0.0/32 is subnetted, 1 subnets  
  20.   
  21. C       1.1.1.1 is directly connected, Loopback0  
  22.   
  23.      4.0.0.0/32 is subnetted, 1 subnets  
  24.   
  25. O IA    4.4.4.4 [110/2] via 192.168.1.2, 00:00:05, FastEthernet0/0  
  26.   
  27. C    192.168.1.0/24 is directly connected, FastEthernet0/0  

三、配置实验2:前缀列表链路分流:

1、在R1和R2之间增加一条链路,采用前缀列表分流。

  1. R1:  
  2.   
  3. interface Loopback0  
  4.   
  5.  ip address 1.1.1.1 255.255.255.255  
  6.   
  7. interface Ethernet0/0  
  8.   
  9.  ip address 192.168.1.1 255.255.255.252  
  10.   
  11. interface Ethernet0/1  
  12.   
  13.  ip address 192.168.1.5 255.255.255.252  
  14.   
  15. router ospf 10  
  16.   
  17.  router-id 1.1.1.1  
  18.   
  19.  log-adjacency-changes  
  20.   
  21.  network 1.1.1.1 0.0.0.0 area 1  
  22.   
  23.  network 192.168.1.0 0.0.0.3 area 0  
  24.   
  25.  network 192.168.1.4 0.0.0.3 area 0  
  26.   
  27.    
  28.   
  29. R2:  
  30.   
  31. interface Loopback0  
  32.   
  33.  ip address 2.2.2.2 255.255.255.255  
  34.   
  35. interface Loopback1  
  36.   
  37.  ip address 3.3.3.3 255.255.255.255  
  38.   
  39. interface Loopback2  
  40.   
  41.  ip address 4.4.4.4 255.255.255.255         
  42.   
  43. interface Ethernet0/0  
  44.   
  45.  ip address 192.168.1.2 255.255.255.252  
  46.   
  47. interface Ethernet0/1  
  48.   
  49.  ip address 192.168.1.6 255.255.255.252  
  50.   
  51. router ospf 10  
  52.   
  53.  router-id 3.3.3.3  
  54.   
  55.  log-adjacency-changes  
  56.   
  57.  network 2.2.2.2 0.0.0.0 area 2  
  58.   
  59.  network 3.3.3.3 0.0.0.0 area 0  
  60.   
  61.  network 4.4.4.4 0.0.0.0 area 4  
  62.   
  63.  network 192.168.1.0 0.0.0.3 area 0  
  64.   
  65.  network 192.168.1.4 0.0.0.3 area 0  

2、查看R1路由表:

  1. R1#show ip route  
  2.   
  3. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP  
  4.   
  5.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  6.   
  7.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2  
  8.   
  9.        E1 - OSPF external type 1, E2 - OSPF external type 2  
  10.   
  11.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2  
  12.   
  13.        ia - IS-IS inter area, * - candidate default, U - per-user static route  
  14.   
  15.        o - ODR, P - periodic downloaded static route  
  16.   
  17. Gateway of last resort is not set  
  18.   
  19.      1.0.0.0/32 is subnetted, 1 subnets  
  20.   
  21. C       1.1.1.1 is directly connected, Loopback0  
  22.   
  23.      2.0.0.0/32 is subnetted, 1 subnets  
  24.   
  25. O IA    2.2.2.2 [110/11] via 192.168.1.6, 00:00:07, Ethernet0/1  
  26.   
  27.                 [110/11] via 192.168.1.2, 00:00:07, Ethernet0/0  
  28.   
  29.      3.0.0.0/32 is subnetted, 1 subnets  
  30.   
  31. O       3.3.3.3 [110/11] via 192.168.1.6, 00:00:07, Ethernet0/1  
  32.   
  33.                 [110/11] via 192.168.1.2, 00:00:07, Ethernet0/0  
  34.   
  35.      4.0.0.0/32 is subnetted, 1 subnets  
  36.   
  37. O IA    4.4.4.4 [110/11] via 192.168.1.6, 00:00:11, Ethernet0/1  
  38.   
  39.                 [110/11] via 192.168.1.2, 00:00:11, Ethernet0/0  
  40.   
  41.      192.168.1.0/30 is subnetted, 2 subnets  
  42.   
  43. C       192.168.1.0 is directly connected, Ethernet0/0  
  44.   
  45. C       192.168.1.4 is directly connected, Ethernet0/1  

3、在R1上配置前缀列表进行链路分流:

  1. ip prefix-list filter1 seq 5 deny 3.3.3.3/32  
  2.   
  3. ip prefix-list filter1 seq 10 deny 4.4.4.4/32  
  4.   
  5. ip prefix-list filter1 seq 15 permit 0.0.0.0/0 le 32  
  6.   
  7. ip prefix-list filter2 seq 5 deny 2.2.2.2/32  
  8.   
  9. ip prefix-list filter2 seq 10 deny 3.3.3.3/32  
  10.   
  11. ip prefix-list filter2 seq 15 permit 0.0.0.0/0 le 32  
  12.   
  13.  router ospf 10  
  14.   
  15.  distribute-list prefix filter1 in Ethernet0/0  
  16.   
  17.  distribute-list prefix filter2 in Ethernet0/1  

4、查看配置了前缀列表后的路由表:

  1. R1#show ip route  
  2.   
  3. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP  
  4.   
  5.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  6.   
  7.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2  
  8.   
  9.        E1 - OSPF external type 1, E2 - OSPF external type 2  
  10.   
  11.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2  
  12.   
  13.        ia - IS-IS inter area, * - candidate default, U - per-user static route  
  14.   
  15.        o - ODR, P - periodic downloaded static route  
  16.   
  17. Gateway of last resort is not set  
  18.   
  19.      1.0.0.0/32 is subnetted, 1 subnets  
  20.   
  21. C       1.1.1.1 is directly connected, Loopback0  
  22.   
  23.      2.0.0.0/32 is subnetted, 1 subnets  
  24.   
  25. O IA    2.2.2.2 [110/11] via 192.168.1.2, 00:00:06, Ethernet0/0  
  26.   
  27.      4.0.0.0/32 is subnetted, 1 subnets  
  28.   
  29. O IA    4.4.4.4 [110/11] via 192.168.1.6, 00:00:06, Ethernet0/1  
  30.   
  31.      192.168.1.0/30 is subnetted, 2 subnets  
  32.   
  33. C       192.168.1.0 is directly connected, Ethernet0/0  
  34.   
  35. C       192.168.1.4 is directly connected, Ethernet0/1      //实现分流  

四、配置实验3:前缀列表过滤路由作用于路由重分发:

1、OSPF与EIGRP路由重分发使用前缀列表控制路由:

  1. R1:  
  2.   
  3. interface Serial0/0  
  4.   
  5.  ip address 172.16.1.1 255.255.255.252  
  6. http://www.xiaoxiongboke.com   
  7.   
  8.  serial restart-delay 0  
  9.   
  10. router ospf 10  
  11.   
  12.  router-id 1.1.1.1  
  13.   
  14.  log-adjacency-changes  
  15.   
  16.  network 172.16.1.0 0.0.0.3 area 0  
  17.   
  18.    
  19.   
  20. R2:  
  21.   
  22. interface Loopback0  
  23.   
  24.  ip address 2.2.2.2 255.255.255.0  
  25.   
  26. interface Serial0/0  
  27.   
  28.  ip address 172.16.1.2 255.255.255.252  
  29.   
  30.  serial restart-delay 0  
  31.   
  32. interface Serial0/1  
  33.   
  34.  ip address 198.16.1.1 255.255.255.252  
  35.   
  36.  serial restart-delay 0  
  37.   
  38. router eigrp 10  
  39.   
  40.  network 198.16.1.0 0.0.0.3  
  41.   
  42. router ospf 10  
  43.   
  44.  router-id 2.2.2.2  
  45.   
  46.  log-adjacency-changes  
  47.   
  48.  redistribute eigrp 10 subnets  
  49.   
  50.  network 2.2.2.0 0.0.0.255 area 1  
  51.   
  52.  network 172.16.1.0 0.0.0.3 area 0  
  53.   
  54.    
  55.   
  56. R3:  
  57.   
  58. interface Loopback0  
  59.   
  60.  ip address 3.3.3.3 255.255.255.0  
  61.   
  62. interface Loopback1  
  63.   
  64.  ip address 4.4.4.4 255.255.255.0  
  65.   
  66. interface Serial0/1  
  67.   
  68.  ip address 198.16.1.2 255.255.255.252  
  69.   
  70.  serial restart-delay 0  
  71.   
  72. router eigrp 10  
  73.   
  74.  network 3.3.3.0 0.0.0.255  
  75.   
  76.  network 4.4.4.0 0.0.0.255  
  77.   
  78.  network 198.16.1.0 0.0.0.3  
  79.   
  80.  no auto-summary  

2、查看R1的路由表:

  1. R1#show ip route  
  2.   
  3. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP  
  4.   
  5.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  6.   
  7.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2  
  8.   
  9.        E1 - OSPF external type 1, E2 - OSPF external type 2  
  10.   
  11.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2  
  12.   
  13.        ia - IS-IS inter area, * - candidate default, U - per-user static route  
  14.   
  15.        o - ODR, P - periodic downloaded static route  
  16.   
  17.    
  18.   
  19. Gateway of last resort is not set  
  20.   
  21.      2.0.0.0/32 is subnetted, 1 subnets  
  22.   
  23. O IA    2.2.2.2 [110/65] via 172.16.1.2, 00:00:04, Serial0/0  
  24.   
  25.      3.0.0.0/24 is subnetted, 1 subnets  
  26.   
  27. O E2    3.3.3.0 [110/20] via 172.16.1.2, 00:00:04, Serial0/0  
  28.   
  29.      4.0.0.0/24 is subnetted, 1 subnets  
  30.   
  31. O E2    4.4.4.0 [110/20] via 172.16.1.2, 00:00:04, Serial0/0  
  32.   
  33. //从外部网络学习到了3.3.3.0/24、4.4.4.0/24、198.16.1.0/30。  
  34.   
  35.      172.16.0.0/30 is subnetted, 1 subnets          
  36.   
  37. C       172.16.1.0 is directly connected, Serial0/0  
  38.   
  39.      198.16.1.0/30 is subnetted, 1 subnets  
  40.   
  41. O E2    198.16.1.0 [110/20] via 172.16.1.2, 00:00:04, Serial0/0  
  42.   
  43. //学到了全路由  

3、在R2上布置前缀列表,让R1只能从外部网络学习到4.4.4.4/24

  1. R2(config)#ip prefix-list filter seq 5 permit 4.4.4.0/24  
  2.   
  3. R2(config)#router ospf 10  
  4.   
  5. R2(config-router)#distribute-list prefix filter out eigrp 10   //允许EIGRP路由4.4.4.4被放入OSPF路由表  

4、测试R1的网络路由表:发现只有4.4.4.0的路由被学习到。

  1. R1#show ip route  
  2.   
  3. Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP  
  4.   
  5.        D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area  
  6.   
  7.        N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2  
  8.   
  9.        E1 - OSPF external type 1, E2 - OSPF external type 2  
  10.   
  11.        i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2  
  12.   
  13.        ia - IS-IS inter area, * - candidate default, U - per-user static route  
  14.   
  15.        o - ODR, P - periodic downloaded static route  
  16.   
  17. Gateway of last resort is not set  
  18.   
  19.      2.0.0.0/32 is subnetted, 1 subnets  
  20.   
  21. O IA    2.2.2.2 [110/65] via 172.16.1.2, 00:02:56, Serial0/0  
  22.   
  23.      4.0.0.0/24 is subnetted, 1 subnets  
  24.   
  25. O E2    4.4.4.0 [110/20] via 172.16.1.2, 00:02:56, Serial0/0  
  26.   
  27.      172.16.0.0/30 is subnetted, 1 subnets  
  28.   
  29. C       172.16.1.0 is directly connected, Serial0/0  
标签:

给我留言