bgp命令 set metric-type internal 理解以及试验

来源:互联网 发布:剑三捏脸数据萝莉可爱 编辑:程序博客网 时间:2024/04/27 14:11

 

 

 

 

如图 1 2 3 4 6 7为alive路由器,我们模拟1 2 6为as1   3 4 7为as2。进行简单的负载均衡multihome试验

 

R1

router ospf 1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 1.1.2.0 0.0.0.255 area 0
network 10.1.1.1 0.0.0.0 area 0
!
router bgp 1
no synchronization
bgp log-neighbor-changes
network 100.1.1.1 mask 255.255.255.255
network 200.1.1.1 mask 255.255.255.255
network 200.2.2.2 mask 255.255.255.255
neighbor 10.2.2.2 remote-as 1
neighbor 10.2.2.2 update-source Loopback1
neighbor 10.6.6.6 remote-as 1
neighbor 10.6.6.6 update-source Loopback1
maximum-paths ibgp 2                                              ibgp负载均衡。
no auto-summary

R2:

router ospf 1
log-adjacency-changes
network 1.1.2.0 0.0.0.255 area 0
network 3.3.0.0 0.0.0.255 area 0
network 10.2.2.2 0.0.0.0 area 0
!
router bgp 1
no synchronization
bgp log-neighbor-changes
network 100.0.0.0
network 200.0.0.0 mask 255.0.0.0
neighbor 3.3.0.2 remote-as 1
neighbor 10.1.1.1 remote-as 1
neighbor 10.1.1.1 update-source Loopback1
neighbor 10.1.1.1 next-hop-self
neighbor 10.3.3.3 remote-as 2
neighbor 10.3.3.3 ebgp-multihop 2
neighbor 10.3.3.3 update-source Loopback1
neighbor 10.3.3.3 prefix-list default in
neighbor 10.3.3.3 prefix-list out out

no auto-summary
!

ps:我们将isp给的默认路由引入,将自己的汇总路由 发给isp 注意 这是与isp对接一般的做法


ip http server
no ip http secure-server
ip route 10.3.3.3 255.255.255.255 3.3.2.2
ip route 100.0.0.0 255.0.0.0 Null0
ip route 200.0.0.0 255.0.0.0 Null0
!
!
!
!
ip prefix-list default seq 5 permit 0.0.0.0/0
!
ip prefix-list out seq 5 permit 100.0.0.0/8
ip prefix-list out seq 10 permit 200.0.0.0/8

R3

router ospf 1
log-adjacency-changes
network 4.4.1.0 0.0.0.255 area 0
network 5.5.1.0 0.0.0.255 area 0
network 10.3.3.3 0.0.0.0 area 0
!
router bgp 2
no synchronization
bgp log-neighbor-changes
neighbor 10.2.2.2 remote-as 1
neighbor 10.2.2.2 ebgp-multihop 2
neighbor 10.2.2.2 update-source Loopback1
neighbor 10.2.2.2 default-originate
neighbor 10.2.2.2 prefix-list in in
neighbor 10.4.4.4 remote-as 2
neighbor 10.4.4.4 update-source Loopback1
neighbor 10.4.4.4 next-hop-self
neighbor 10.7.7.7 remote-as 2
neighbor 10.7.7.7 update-source Loopback1
no auto-summary
!
ip http server
no ip http secure-server
ip route 10.2.2.2 255.255.255.255 3.3.2.1
!
!
!
!
ip prefix-list in seq 5 permit 100.0.0.0/8
ip prefix-list in seq 10 permit 200.0.0.0/8

ps :isp接受客户的汇总路由,发布汇总路由给客户

 

 

R4

router ospf 1
log-adjacency-changes
network 4.4.3.0 0.0.0.255 area 0
network 5.5.1.0 0.0.0.255 area 0
network 10.4.4.4 0.0.0.0 area 0
!
router bgp 2
no synchronization
bgp log-neighbor-changes
network 100.1.2.1 mask 255.255.255.255
network 200.1.2.1 mask 255.255.255.255
neighbor cisco peer-group
neighbor cisco remote-as 2
neighbor cisco update-source Loopback1
neighbor 10.3.3.3 peer-group cisco
neighbor 10.7.7.7 peer-group cisco

no auto-summary
!

R6

router ospf 1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 3.3.0.0 0.0.0.255 area 0
network 3.3.3.0 0.0.0.255 area 0
network 10.6.6.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp log-neighbor-changes
network 100.0.0.0
network 200.0.0.0 mask 255.0.0.0
neighbor 3.3.0.1 remote-as 1
neighbor 10.1.1.1 remote-as 1
neighbor 10.1.1.1 update-source Loopback1
neighbor 10.1.1.1 next-hop-self
neighbor 10.7.7.7 remote-as 2
neighbor 10.7.7.7 ebgp-multihop 2
neighbor 10.7.7.7 update-source Loopback1
neighbor 10.7.7.7 prefix-list in in
neighbor 10.7.7.7 prefix-list out out

no auto-summary
!
ip http server
no ip http secure-server
ip route 10.7.7.7 255.255.255.255 3.3.3.2
ip route 100.0.0.0 255.0.0.0 Null0
ip route 200.0.0.0 255.0.0.0 Null0

!
!
!
!
ip prefix-list in seq 5 permit 0.0.0.0/0
!
ip prefix-list out seq 5 permit 100.0.0.0/8
ip prefix-list out seq 10 permit 200.0.0.0/8
!

R7

router ospf 1
log-adjacency-changes
network 4.4.1.0 0.0.0.255 area 0
network 4.4.3.0 0.0.0.255 area 0
network 10.7.7.7 0.0.0.0 area 0
!
router bgp 2
no synchronization
bgp log-neighbor-changes
neighbor 10.3.3.3 remote-as 2
neighbor 10.3.3.3 update-source Loopback1
neighbor 10.4.4.4 remote-as 2
neighbor 10.4.4.4 update-source Loopback1
neighbor 10.4.4.4 next-hop-self
neighbor 10.6.6.6 remote-as 1
neighbor 10.6.6.6 ebgp-multihop 2
neighbor 10.6.6.6 update-source Loopback1
neighbor 10.6.6.6 default-originate
neighbor 10.6.6.6 prefix-list in in
no auto-summary
!
ip http server
no ip http secure-server
ip route 10.6.6.6 255.255.255.255 3.3.3.1
!        
!
!
!
ip prefix-list in seq 5 permit 100.0.0.0/8
ip prefix-list in seq 10 permit 200.0.0.0/8
!

 

=================================================================

以上配置为multihome实验1配置 目前状态为负载均衡状态。

我们需要将as1的 100.0.0.0 地址的metric 搞成1000

然后将它传给as2.在这里我们要记住 从一个as传到另一个as的时候 update报文将med值干掉。所以需要加set metric-type internal

好了,首先我们将100.0.0.0 地址的metric 搞成1000

再R2上进行如下操作

router-map add-metric permit 10

set metric 1000

router bgp 1

net 100.0.0.0   mask 255.0.0.0 route-map add-metric

exit

好了 我们来看下R2的路由表

R2#show ip bgp
BGP table version is 10, local router ID is 10.2.2.2
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
* i0.0.0.0          10.7.7.7                 0    100      0 2 i
*>                  10.3.3.3                 0             0 2 i
* i100.0.0.0        3.3.0.2                  0    100      0 i
*>                  0.0.0.0               1000         32768 i

*>i100.1.1.1/32     10.1.1.1                 0    100      0 i
* i200.0.0.0/8      3.3.0.2                  0    100      0 i
*>                  0.0.0.0                  0         32768 i
*>i200.1.1.1/32     10.1.1.1                 0    100      0 i

再看as1的ibgp学到没 看下R1

R1#show ip bgp
BGP table version is 15, local router ID is 200.1.1.1
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
* i0.0.0.0          10.6.6.6                 0    100      0 2 i
*>i                 10.2.2.2                 0    100      0 2 i
*>i100.0.0.0        10.6.6.6                 0    100      0 i
* i                 10.2.2.2              1000    100      0 i
*> 100.1.1.1/32     0.0.0.0                  0         32768 i
* i200.0.0.0/8      10.6.6.6                 0    100      0 i
*>i                 10.2.2.2                 0    100      0 i
*> 200.1.1.1/32     0.0.0.0                  0         32768 i

好了我们将它传给as2

我们在R2上加如下配置

ip prefix-list out seq 5 permit 100.0.0.0/8

route-map trans permit 10
match ip address prefix-list out
set metric-type internal
exit

route-map trans permit 20

router bgp 1
nei 10.3.3.3 route-map trans out
exit

好了 我们再来看as2的R3 med值学过来了没有

R3#show ip bgp
BGP table version is 5, local router ID is 10.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
* i100.0.0.0        10.6.6.6                 0    100      0 1 i
*>                  10.2.2.2              1000             0 1 i
* i200.0.0.0/8      10.6.6.6                 0    100      0 1 i
*>                  10.2.2.2                 0             0 1 i
*>i200.1.2.1/32     10.4.4.4                 0    100      0 i

搞定了。

简单总结下:

关键点:知道bgp宣告给ebgp路由时候将med属性致零

一开始看了命令手册 说的并不易懂,后来通过讨论,发现其实这条命令就是为了让update报文再宣告给ebgp时候使匹配的prefix条目带上metric值 然后传到ebgp端,很好理解的一个东东搞了好长时间。

(责任编辑:admin)