实验拓扑:

R1与R2之间是EBGP
R1与R3之间是EBGP
R2与R3之间是IBGP
 

 

 

然后做如下配置
在R1上通告1.1.1.0 网络
R1:
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial0/0
ip address 172.16.12.1 255.255.255.0
clock rate 64000
!

 
interface Serial0/1
ip address 172.16.13.1 255.255.255.0
clock rate 64000
!
router bgp 1
network 1.1.1.0 mask 255.255.255.0
neighbor 172.16.12.2 remote-as 2
neighbor 172.16.13.3 remote-as 2
!
R2:
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface FastEthernet0/0
ip address 172.16.23.2 255.255.255.0
duplex auto
speed auto
!
interface Serial0/0
ip address 172.16.12.2 255.255.255.0
clock rate 2000000
!
router bgp 2
neighbor 172.16.12.1 remote-as 1
neighbor 172.16.23.3 remote-as 2

 

R3:

interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface FastEthernet0/0
ip address 172.16.23.3 255.255.255.0
duplex auto
speed auto
!
interface Serial0/0
ip address 172.16.13.3 255.255.255.0
clock rate 2000000
!
router bgp 2
neighbor 172.16.13.1 remote-as 1
neighbor 172.16.23.2 remote-as 2

 
实验验证
在R2上查看BGP路由表,注意show ip bgp结果,
【问题1】通过R2到R1的1.1.1.0 网络为什么选择172.16.12.1?
R2#show ip bgp
BGP table version is 2, local router ID is 2.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
* i1.1.1.0/24 172.16.13.1 0 100 0 1 i
*> 172.16.12.1 0 0 1 i

 
【答案1】原因是172.16.13.1 不可达,如下面命令所示

 
R2#show ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 2
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Advertised to update-groups:
2
1
172.16.13.1 (inaccessible) from 172.16.23.3 (3.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
1
172.16.12.1 from 172.16.12.1 (1.1.1.1)
Origin IGP, metric 0, localpref 100, valid, external, best

 
【问题2】如何配置,才能让172.16.13.1 可达?
【答案2】按照下面配置
R2:
R2(config)#router bgp 2
R2(config-router)# neighbor 172.16.23.3 next-hop-self

 
R3(config)#router b 2
R3(config-router)# neighbor 172.16.23.2 next-hop-self

此时再查看BGP路由

 
R2#clear ip bgp * soft
R2#show ip bgp
BGP table version is 2, local router ID is 2.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
* i1.1.1.0/24 172.16.23.3 0 100 0 1 i
*> 172.16.12.1 0 0 1 i
R2#show ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 2
Paths: (2 available, best #2, table Default-IP-Routing-Table)
Advertised to update-groups:
2
1
172.16.23.3 from 172.16.23.3 (3.3.3.3)
Origin IGP, metric 0, localpref 100, valid, internal
1
172.16.12.1 from 172.16.12.1 (1.1.1.1)
Origin IGP, metric 0, localpref 100, valid, external, best

 
【问题4】此时为什么还是选择172.16.23.3 ?
【答案4】原因是 EBGP优于IBGP

 
【实验2】在R2上,如何修改AS-Path ,使到达1.1.1.0 网络的选择172.16.12.1

 
R2(config)# ip prefix-list 1 permit 1.1.1.0/24
R2(config)# route-map as
R2(config-route-map)# match ip address prefix-list 1
R2(config-route-map)# set as-path prepend 65000 65001
R2(config-route-map)# router bgp 2
R2(config-router)# neighbor 172.16.12.1 route-map as in
R2(config-router)#end
R2#clear ip bgp * soft
R2#show ip b
BGP table version is 3, local router ID is 2.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
*>i1.1.1.0/24 172.16.23.3 0 100 0 1 i  变成了上面这条路由
* 172.16.12.1 0 0 65000 65001 1 i

 

 
此时在R2上查看到R3的路由已经没有了
R2# show ip bgp neighbors 172.16.23.3 advertised-routes

 
Total number of prefixes 0
在R3上查看bgp路由,也只剩余1条
R3#show ip bgp
BGP table version is 2, 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
*> 1.1.1.0/24 172.16.13.1 0 0 1 i
R3#