实验指南
初始配置
Wills
conf t
host Wills
int l 0
ip ad 1.1.1.1 255.255.255.255
int s2/0
encap f
no arp f
no frame inver
no shut
int s2/0.1 p
ip ad 10.1.1.1 255.255.255.0
frame int 102
int s2/0.2 p
ip ad 10.1.2.1 255.255.255.0
frame inter 103
conf t
host Wills
int l 0
ip ad 1.1.1.1 255.255.255.255
int s2/0
encap f
no arp f
no frame inver
no shut
int s2/0.1 p
ip ad 10.1.1.1 255.255.255.0
frame int 102
int s2/0.2 p
ip ad 10.1.2.1 255.255.255.0
frame inter 103
router rip
ver 2
no au
net 10.00.0.0
net 1.0.0.0
net 62.0.0.0
router bgp 2001
no au
no sy
bgp router-id 1.1.1.1
nei 2.2.2.2 remote 645
nei 2.2.2.2 up l 0
nei 2.2.2.2 e 255
nei 3.3.3.3 remote 645
nei 3.3.3.3 up l 0
nei 3.3.3.3 e 255
end
ver 2
no au
net 10.00.0.0
net 1.0.0.0
net 62.0.0.0
router bgp 2001
no au
no sy
bgp router-id 1.1.1.1
nei 2.2.2.2 remote 645
nei 2.2.2.2 up l 0
nei 2.2.2.2 e 255
nei 3.3.3.3 remote 645
nei 3.3.3.3 up l 0
nei 3.3.3.3 e 255
end
Amold
conf t
host Amold
int l 0
ip ad 2.2.2.2 255.255.255.255
int s2/0
encap f
no arp f
no frame inver
no shut
int s2/0.1 p
ip ad 10.1.1.2 255.255.255.0
frame int 201
int s2/1
ip ad 10.2.2.1 255.255.255.0
encap f
no arp f
no frame inver
frame map ip 10.2.2.3 216 b
frame map ip 10.2.2.2 216 b
no shut
router rip
ver 2
no au
net 2.0.0.0
net 10.0.0.0
router bgp 645
no au
no sy
bgp router-id 2.2.2.2
nei 1.1.1.1 remote 2001
nei 1.1.1.1 up l 0
nei 1.1.1.1 e 255
nei 6.6.6.6 remote 645
nei 6.6.6.6 up l 0
end
Kimberly
conf t
host Kimberly
int l 0
ip ad 3.3.3.3 255.255.255.255
int s 2/0
encap f
no arp f
no frame inver
no shut
int s2/0.1 p
ip ad 10.1.2.2 255.255.255.0
frame int 301
int s2/1
ip ad 10.2.2.2 255.255.255.0
encap f
no arp f
no frame inver
frame map ip 10.2.2.1 316 b
frame map ip 10.2.2.3 316 b
no shut
router rip
ver 2
no au
net 3.0.0.0
net 10.0.0.0
router bgp 645
no au
no sy
bgp router-id 3.3.3.3
nei 1.1.1.1 remote 2001
nei 1.1.1.1 up l 0
nei 1.1.1.1 e 255
nei 6.6.6.6 remote 645
nei 6.6.6.6 up l 0
end
Router6
conf t
host Router6
int l 0
ip ad 6.6.6.6 255.255.255.255
int 1
ip ad 189.168.82.1 255.255.254.0
int l2
ip ad 189.168.84.1 255.255.254.0
int l3
ip ad 189.168.86.1 255.255.254.0
int l4
ip ad 189.168.88.1 255.255.254.0
int s2/1
ip ad 10.2.2.3 255.255.255.0
encap f
no arp f
no frame inver
frame map ip 10.2.2.1 612 b
frame map ip 10.2.2.2 613 b
no shut
router rip
ver 2
net 6.0.0.0
net 10.0.0.0
router bgp 645
bgp router-id 6.6.6.6
no au
no sy
nei 2.2.2.2 remote 645
nei 2.2.2.2 up l 0
nei 3.3.3.3 remote 645
nei 3.3.3.3 up l 0
nei 2.2.2.2 route-reflector-client
nei 3.3.3.3 route-reflector-client
net 189.168.82.0 mask 255.255.254.0
net 189.168.84.0 mask 255.255.254.0
net 189.168.86.0 mask 255.255.254.0
net 189.168.88.0 mask 255.255.254.0
end
int l2
ip ad 189.168.84.1 255.255.254.0
int l3
ip ad 189.168.86.1 255.255.254.0
int l4
ip ad 189.168.88.1 255.255.254.0
int s2/1
ip ad 10.2.2.3 255.255.255.0
encap f
no arp f
no frame inver
frame map ip 10.2.2.1 612 b
frame map ip 10.2.2.2 613 b
no shut
router rip
ver 2
net 6.0.0.0
net 10.0.0.0
router bgp 645
bgp router-id 6.6.6.6
no au
no sy
nei 2.2.2.2 remote 645
nei 2.2.2.2 up l 0
nei 3.3.3.3 remote 645
nei 3.3.3.3 up l 0
nei 2.2.2.2 route-reflector-client
nei 3.3.3.3 route-reflector-client
net 189.168.82.0 mask 255.255.254.0
net 189.168.84.0 mask 255.255.254.0
net 189.168.86.0 mask 255.255.254.0
net 189.168.88.0 mask 255.255.254.0
end
1,修改origin来影响BGP路径选择
Wills#sh ip route bgp | include 189
189.168.0.0/23 is subnetted, 17 subnets
B 189.168.84.0 [20/0] via 2.2.2.2, 01:44:47
B 189.168.86.0 [20/0] via 2.2.2.2, 01:44:47
B 189.168.82.0 [20/0] via 2.2.2.2, 01:44:47
B 189.168.88.0 [20/0] via 2.2.2.2, 01:44:47
从Wills的路由表状态可以看出,到达189.168.0.0/16网段是从Amold学到,若想从Kimberly学到,有几种方法,先讲根据origin来影响
Wills
access-list 1 permit 189.168.0.0 0.0.255.255
route-map ORIGIN permit 10
match ip ad 1
set origin incomplete
router bgp 2001
nei 2.2.2.2 route-map ORIGIN incomplete
end
这时,Wills上路由表的状态
Wills(config-router)#do sh ip route bgp | include 189
189.168.0.0/23 is subnetted, 17 subnets
B 189.168.84.0 [20/0] via 3.3.3.3, 00:00:07
B 189.168.86.0 [20/0] via 3.3.3.3, 00:00:07
B 189.168.82.0 [20/0] via 3.3.3.3, 00:00:07
B 189.168.88.0 [20/0] via 3.3.3.3, 00:00:07
很明显,从Wills到189.168.0.0/16网段,要走路由器Kimberly。
Wills上BGP表状态
Wills(config-router)#do sh ip bgp | include 189
BGP table version is 63, local router ID is 1.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
*> 189.168.82.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
*> 189.168.84.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
*> 189.168.86.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
*> 189.168.88.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
从邻居2.2.2.2学到的BGP条目的origin为incomplete,所以Origin Codes 标识为“?”根据BGP路径优先的选择进程,Wills将从Kimberly到达189.168.0.0/16网段
*> 189.168.82.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
*> 189.168.84.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
*> 189.168.86.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
*> 189.168.88.0/23 3.3.3.3 0 645 i
* 2.2.2.2 0 645 ?
从邻居2.2.2.2学到的BGP条目的origin为incomplete,所以Origin Codes 标识为“?”根据BGP路径优先的选择进程,Wills将从Kimberly到达189.168.0.0/16网段
2,使用AS path属性影响BGP路径选择
上例中,我们通过BGP的origin属性来影响BGP路径选择,本例讲到达189.168.0.0/16网段是从Amold学到,若想从Kimberly学到的第二种方法
Wills
access-list 2 permit 189.168.0.0 0.0.255.255
route-map ASPATH permit 10
match ip ad 2
set as-path prepend last-as 2
或者 set as-path prepend 123 1234
router bgp 2001
nei 2.2.2.2 route-map ASPATH in
end
第一个set命令是收到路由条目所经过的最后一个AS显示的次数,第二个set命令是加入预先设定的AS值。因为BGP路径选择时会比较AS path,BGP会选择经过AS path少的路径
access-list 2 permit 189.168.0.0 0.0.255.255
route-map ASPATH permit 10
match ip ad 2
set as-path prepend last-as 2
或者 set as-path prepend 123 1234
router bgp 2001
nei 2.2.2.2 route-map ASPATH in
end
第一个set命令是收到路由条目所经过的最后一个AS显示的次数,第二个set命令是加入预先设定的AS值。因为BGP路径选择时会比较AS path,BGP会选择经过AS path少的路径
Wills上BGP表的状态
Wills#sh ip bgp
BGP table version is 46, local router ID is 1.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
Wills#sh ip bgp
BGP table version is 46, local router ID is 1.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
* 189.168.82.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.84.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.86.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.88.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.82.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.84.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.86.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
* 189.168.88.0/23 2.2.2.2 0 123 1234 645 645 645 i
*> 3.3.3.3 0 645 i
CISCO IOS提供了一条隐藏的命令,可以使得BGPpath选择时忽略AS path的长短
Wills
router bgp 2001
bgp bestpath as-path ignore
end
Wills
router bgp 2001
bgp bestpath as-path ignore
end
这时,在Wills上BGP表的状态
Wills#sh ip bgp
BGP table version is 46, local router ID is 1.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
* 189.168.82.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
* 189.168.84.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
* 189.168.86.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
* 189.168.88.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
这里可以看出,配置bgp bestpath as-path ignore后,将不再比较AS path的值。通过routerID去选择路径了。
* 189.168.82.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
* 189.168.84.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
* 189.168.86.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
* 189.168.88.0/23 3.3.3.3 0 645 i
*> 2.2.2.2 0 123 1234 645 645 645 i
这里可以看出,配置bgp bestpath as-path ignore后,将不再比较AS path的值。通过routerID去选择路径了。
3,使用AS path属性过滤BGP路由
使用AS path属性过滤掉从Amold上发送的经过AS645的路由条目,要使用正则表达式
使用AS path属性过滤掉从Amold上发送的经过AS645的路由条目,要使用正则表达式
Wills
ip as-path access-list 1 deny _645_
ip as-path access-list 1 permit .*
route-map FILTER permit 10
match as-path 1
router bgp 2001
nei 2.2.2.2 route-map FILTER in
end
这时Wills上BGP表的状态
Wills(config-router)#do sh ip bgp | include 189
*> 189.168.82.0/23 3.3.3.3 0 645 i
*> 189.168.84.0/23 3.3.3.3 0 645 i
*> 189.168.86.0/23 3.3.3.3 0 645 i
*> 189.168.88.0/23 3.3.3.3 0 645 i
说明从Amold上发送的路由条目已经被过滤了
还可以使用filter-list 进行AS path过滤,建立as-path列表的步骤一样,不过就是不用建立route-map了
Wills
router bgp 2001
nei 2.2.2.2 filter-list 1 in
end
Wills(config-router)#do sh ip bgp | include 189
*> 189.168.82.0/23 3.3.3.3 0 645 i
*> 189.168.84.0/23 3.3.3.3 0 645 i
*> 189.168.86.0/23 3.3.3.3 0 645 i
*> 189.168.88.0/23 3.3.3.3 0 645 i
说明从Amold上发送的路由条目已经被过滤了
还可以使用filter-list 进行AS path过滤,建立as-path列表的步骤一样,不过就是不用建立route-map了
Wills
router bgp 2001
nei 2.2.2.2 filter-list 1 in
end
用这个方法要比使用route-map简便许多,也同时能起到过滤AS path的作用
PS:正则表达式比较麻烦,需要多多练习
4,使用MED属性选择BGP最佳路径
默认情况下Wills要189.168.0.0/16网段要走Amold,下面通过修改Amold和Kimberly的mertic值来改变Wills到达189.168.0.0/16网段要走的路径
Amold
access-list 1 permit 189.168.0.0 0.0.255.255
route-map METRIC permit 10
match ip ad 1
set metric 100
route-map METRIC permit 20
router bgp 645
nei 1.1.1.1 route-map METRIC out
end
把从Amold发出的189.168.0.0/16网段的metric设为100(默认为0),这时Wills的BGP表状态
Wills(config-router)#do sh ip bgp
BGP table version is 63, local router ID is 1.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
*> 189.168.82.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
*> 189.168.84.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
*> 189.168.86.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
*> 189.168.88.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
很明显,Wills将选择metric小的路径到达目的网段
*> 189.168.82.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
*> 189.168.84.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
*> 189.168.86.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
*> 189.168.88.0/23 3.3.3.3 0 645 i
* 2.2.2.2 100 0 645 i
很明显,Wills将选择metric小的路径到达目的网段
<注>本例中没有提到的一种情况就是,BGP默认并不比较通过多个AS到达目的网段的metric值,也就是说,如果Amold和Kimberly不在同一个AS中时,BGP并不比较这两个AS的mertric值。这样就有可能到达目的网段并不是走最佳路径,CISCO IOS提供了一条命令可以比较多个AS的metric值,以达到最佳路径的目的
router bgp
bgp always-compare-med
这样可以比较多个AS的metric值了
5,通过修改local_pref来选择网络出口
Wills
acccess-list 1 permit 189.168.0.0 0.0.255.255
route-map LOCAL_PREF permit 10
match ip ad 1
set local-preference 1000
router bgp 2001
nei 3.3.3.3 route-map LOCAL_PREF in
end
Wills
acccess-list 1 permit 189.168.0.0 0.0.255.255
route-map LOCAL_PREF permit 10
match ip ad 1
set local-preference 1000
router bgp 2001
nei 3.3.3.3 route-map LOCAL_PREF in
end
Wills上BGP表的状态
Wills(config-router)#do sh ip bgp
BGP table version is 46, local router ID is 1.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
Wills(config-router)#do sh ip bgp
BGP table version is 46, local router ID is 1.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
* 189.168.82.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
* 189.168.84.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
* 189.168.86.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
* 189.168.88.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
因为Wills到Kimberly的local_pref高,所以BGP选择Kimberly到达目的网段
* 189.168.82.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
* 189.168.84.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
* 189.168.86.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
* 189.168.88.0/23 2.2.2.2 0 645 i
*> 3.3.3.3 1000 0 645 i
因为Wills到Kimberly的local_pref高,所以BGP选择Kimberly到达目的网段