BGP选路策略——MED
 
 
 
MED   Multi-Exit Discriminator<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

特点:

·当两个AS之间存在多条路径的时候才使用

·告诉自己的EBGP邻居如何进入本AS。Local prefrerence决定如何出去,MED决定EBGP邻居如何进来

·只能传递一个AS。

·默认值=0,MED值越小越好

 

Show ip bgp 中显示的Metric值就是MED

 

    默认不比较从不同AS传来路由的MED。如果要比较不同AS传来的MED值,要用下面的命令

R2(config-router)#bgp always-compare-med

 

 

实验需求:R3通过R1访问172.16.1.0,通过R4访问192.168.1.0

 

需求分析:要让R3在通过比较MED值时作出选择,同时看R1和R4传给它路由的metric,选择小的出去。本例中让R1的172.16.1.0网段的metritc<192.168.1.0网段,让R4的192.168.1.0网段的metric<172.16.1.0网段

 

R2(config)#access-list 1 permit 172.16.1.0 <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0.0.0.0

R2(config)#access-list 2 permit 192.168.1.0 0.0.0.0

R2(config)#route-map R-1

R2(config-route-map)#match ip add 1

R2(config-route-map)#set metric 100

R2(config-route-map)#exit

R2(config)#route-map R-1 20

R2(config-route-map)#match ip add 2

R2(config-route-map)#set metric 200

R2(config-route-map)#exit

R2(config)#route-map R-1 30

R2(config)#router bgp 2

R2(config-router)#neighbor 12.1.1.1 route-map R-1 out

R2(config)#route-map R-4

R2(config-route-map)#match ip add 1

R2(config-route-map)#set metric 200

R2(config-route-map)#exit

R2(config)#route-map R-4 20

R2(config-route-map)#match ip add 2

R2(config-route-map)#set metric 100

R2(config-route-map)#exit

R2(config)#route-map R-4 30

R2(config-route-map)#exit

R2(config-router)#neighbor 24.1.1.4 route-map R-4 out

R2#clear ip bgp * soft
 

R3#sh ip bgp
BGP table version is 22, local router ID is 3.3.3.3
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 10.1.1.0/24      0.0.0.0                  0         32768 i
*>i172.16.1.0/24    13.1.1.1               100    100      0 2 i
* i                 34.1.1.4               200    100      0 2 i
* i192.168.1.0      13.1.1.1               200    100      0 2 i
*>i                 34.1.1.4               100    100      0 2 i

 

========================验证======================

在R1,R4上分别启用debug ip packet,然后在R3上ping 172.16.1.1 source 10.1.1.1

Ping 192.168.1.1 source 10.1.1.1,观察R1,R4上的变化。

 

R3#ping 172.16.1.1 source 10.1.1.1

 

此时在R1上会出现回显,而R4上没有任何动静也不会有,呵呵

 

R3#ping 192.168.1.1 source 10.1.1.1

 

此时在R4上会出现回显,而R1上没有任何动静。

 

算了,还是要traceroute做一下吧:

 

R3#traceroute 172.16.1.1 source 10.1.1.1

 

Type escape sequence to abort.

Tracing the route to 172.16.1.1

 

  1 13.1.1.1 92 msec 88 msec 76 msec

  2 12.1.1.2 92 msec 100 msec *

R3#traceroute 192.168.1.1 source 10.1.1.1

 

Type escape sequence to abort.

Tracing the route to 192.168.1.1

 

  1 34.1.1.4 76 msec 76 msec 60 msec

  2 24.1.1.2 84 msec 60 msec *