主要实验两条命令:

1、advertise-map non-exist- map 

 2、advertise-map exist-map 

 

实验 一:项目背景:

AS300 拥有一块地址块:172.16.0.0/16

AS200向AS300申请一个地址 段,172.16.1.0/24.

实验要求 :

1、R2不向R1通告172.16.1.0网络 ,外界要访问 这个网络需要走R3这条路线。

2、R3会向R2通告一条默认路由,但使用团体属性no-export,禁止这条默认路由通告给AS100.

3、如果 ,R2--R3这条链路故障,R2将通告172.16.1.0/24给AS100,以使外界 能通过R1访问AS200.

advertise-map non-exist-map应用情景 :当R3通告过来的默认路由172.16.0.0存在R2的BGP表中时,R2不向AS100通告172.16.1.0/24路由,因为希望 外界访问172.16.1.0这个网络时走R3路线。

而如果 通往R3的链路失效,则向AS100通告172.16.1.0路由。

 

实验 配置如下:

 

 
  
  1. R1: 
  2. router bgp 100 
  3.  no synchronization 
  4.  bgp router-id 1.1.1.1 
  5.  bgp log-neighbor-changes 
  6.  neighbor 12.1.1.2 remote-as 200 
  7.  no auto-summary 

 

 
  
  1. R2: 
  2.  
  3. interface Loopback0 
  4.  ip address 172.16.1.1 255.255.255.0 
  5. interface Serial0/0 
  6.  ip address 12.1.1.2 255.255.255.0 
  7.  serial restart-delay 0 
  8. interface Serial0/1 
  9.  ip address 23.1.1.2 255.255.255.0 
  10.  serial restart-delay 0 
  11. router bgp 200 
  12.  no synchronization 
  13.  bgp router-id 2.2.2.2 
  14.  bgp log-neighbor-changes 
  15.  network 172.16.1.0 mask 255.255.255.0 
  16.  neighbor 12.1.1.1 remote-as 100 
  17.  neighbor 12.1.1.1 send-community 
  18.  neighbor 12.1.1.1 advertise-map can-go-out non-exist-map if-no-exist 

  19.  
  20.  
  21.  
  22.  
  23.  neighbor 23.1.1.3 remote-as 300 
  24.  neighbor 23.1.1.3 route-map set-comm in 
  25.  
  26.  no auto-summary 
  27.  ip bgp-community new-format ip community-list 1 permit 100:300
  28.  
  29. ip prefix-list if-no-prefix seq 5 permit 172.16.0.0/16 
  30. ip prefix-list out-prefix seq 5 permit 172.16.1.0/24 
  31. route-map can-go-out permit 0 
  32.  match ip address prefix-list out-prefix 
  33. route-map set-comm permit 10 
  34.  set community 100:300 additive 
  35. route-map if-no-exist permit 10 
  36.  match ip address prefix-list if-no-prefix 
  37.  match community 1 

 

 

 

命令以及功能 解析:

1、neighbor 12.1.1.1 advertise-map can-go-out non-exist-map if-no-exist 

 

 

如果if-no-exist中捕抓到的路由(172.16.0.0/16)存在“show ip bgp ”中,则不通告can-go-out中的路由

如果 if-no-exist中捕抓到的路由(172.16.0.0/16)不存在“show ip bgp ”中,则通告can-go-out中的路

由。

这条命令实现了,当R2到R3的链路失效时,那么在R2的BGP表中,将不再存在172.16.0.0这个条目,这个时候R2

将向R1通告172.16.1.0/24这条路由了。

non-exist-map应该 理解 为“不再存在时”。不再存在时就通告。

2、

neighbor 23.1.1.3 route-map set-comm in

route-map set-comm permit 10 

 

set community 100:300 additive 

这几条命令对R3通告过来路由设置 团体值,之后 会通告给R1.值100表示是由AS100通告,值设置 为300则能比较

明晰的表示 这条路由是来自于AS300的。实验中我们要明确 这是AS300的路由,所以才设置 了这个团体值。

3、ip bgp-community new-format

BGP的团体属性有两种格式:

1)十进制格式,在1~4294967200之间

2)AA:NN格式,AA表示AS号,范围 是1~65535.NN取值范围1~65440.

cisco路由器默认是旧的格式 ,也就是1)格式 。如果要使用新的格式 ,则需要“ip bgp-community

new-format”这条命令。

 

 

4、

ip community-list 1 permit 100:300

route-map if-no-exist permit 10 match ip address prefix-list if-no-prefix match community 1

团体属性列表,匹配来自于R3的路由条目172.16.0.0/16.
 
 

 

 
  
  1. R3: 
  2.  
  3. router bgp 300 
  4.  no synchronization 
  5.  bgp router-id 3.3.3.3 
  6.  bgp log-neighbor-changes 
  7.  network 172.16.0.0 
  8.  neighbor 23.1.1.2 remote-as 200 
  9.  neighbor 23.1.1.2 send-community 
  10.  neighbor 23.1.1.2 route-map set-comm out 
  11.  no auto-summary 
  12. ip http server 
  13. no ip http secure-server 
  14. ip route 172.16.0.0 255.255.0.0 Null0 
  15.  
  16. route-map set-comm permit 10 
  17.  set community no-export 
  18. //只通告给AS200,不通告给AS100.

 

实验二:advertist-map exist-map实例。

 

如图所示,在AS100内部 运行ospf作为IGP,内网有一段私有地址块192.168.1.0/24.

要求 :

1、不能向外界通告私有地址 块192.168.1.0/24.

2、在R2上对私有地址进行NAT转换。

3、通告转换后的地址 给AS200.

advertise-map exist-map应用情景:如果内部私有地址存在,则通告转换后的地址 ,如果内部私有地址 块因

为某些原因不存在 了,则也没必要通告202.1.1.0这个转换后的地址 了。 

基本的配置如下:

 

 
  
  1. R1: 
  2.  
  3. router ospf 100 
  4.  log-adjacency-changes 
  5.  network 0.0.0.0 255.255.255.255 area 0 
  6.  
  7. R3: 
  8. router ospf 100 
  9.  log-adjacency-changes 
  10.  network 0.0.0.0 255.255.255.255 area 0 

 

 

 
  
  1. R2: 
  2.  
  3. router ospf 100 
  4.  log-adjacency-changes 
  5.  network 0.0.0.0 255.255.255.255 area 0 
  6. router bgp 100 
  7.  no synchronization 
  8.  bgp router-id 2.2.2.2 
  9.  bgp log-neighbor-changes 
  10.  redistribute ospf 100 
  11.  neighbor 24.1.1.4 remote-as 100 
  12.  no auto-summary 

 

 
  
  1. R4: 
  2.  
  3. router ospf 100 
  4.  log-adjacency-changes 
  5.  network 24.1.1.4 0.0.0.0 area 0 
  6. router bgp 100 
  7.  no synchronization 
  8.  bgp router-id 4.4.4.4 
  9.  bgp log-neighbor-changes 
  10.  neighbor 24.1.1.2 remote-as 100 
  11.  neighbor 24.1.1.2 next-hop-self 
  12.  neighbor 45.1.1.5 remote-as 200 
  13.  no auto-summary 

 

 
  
  1. R5: 
  2.  
  3. router bgp 200 
  4.  no synchronization 
  5.  bgp router-id 5.5.5.5 
  6.  bgp log-neighbor-changes 
  7.  neighbor 45.1.1.4 remote-as 100 
  8.  no auto-summary 

 

这时查看 R5的路由表:

 

 

 

 

第一步:控制 私有地址 不向外通告。

 

 
  
  1. R4: 
  2. ip prefix-list block seq 5 deny 192.168.1.0/24 
  3. ip prefix-list block seq 20 permit 0.0.0.0/0 le 32 
  4. router bgp 100 
  5.  neighbor 45.1.1.5 prefix-list block out 
  6.  
  7.  

 

 

 

第二步:做NAT转换

 

 
  
  1. R2: 
  2.  
  3. ip nat pool cisco 202.1.1.1 202.1.1.100 prefix-length 24 
  4. ip nat inside source list 1 pool cisco 
  5.  
  6. interface FastEthernet0/0 
  7.  ip address 192.168.1.2 255.255.255.0 
  8.  ip nat inside 
  9.  
  10. interface Serial1/0 
  11.  ip address 24.1.1.2 255.255.255.0 
  12.  ip nat outside 

 

 
  
  1. R4: 
  2.  
  3. router bgp  100 
  4. redistribute  static 

 

 

第三步:advertise-map exist-map配置

 

 
  
  1. R4: 
  2.  
  3. router bgp 100 
  4.  neighbor 45.1.1.5 advertise-map after-nat exist-map private 
  5.  
  6.  
  7. ip route 202.1.1.0 255.255.255.0 24.1.1.2 
  8.  
  9.  
  10. ip prefix-list after-nat seq 5 permit 202.1.1.0/24 
  11. ip prefix-list private seq 5 permit 192.168.1.0/24 
  12.  
  13.  
  14. route-map after-nat permit 10 
  15.  match ip address prefix-list after-nat 
  16. route-map private permit 10 
  17.  match ip address prefix-list private 

 

查看 实验 效果 :在R2上关闭f0/0接口。然后再看:

 

 

因为R4的bgp表中已经没有了192.168.1.0/24这条路由,所以R4也不会再向R5通告202.1.1.0/24这条路由了。

 

 

 

                                                        参考 《BGP设计与实现》