前几天在NET130看到有位华为工程师为配置思科多出口多宿主BGP而烦恼。根据他的思路,做了一下实验,发现有些地方以前没有留意到的,就把它记录下来,以作参考。
其中要求为:
1、CN2的AS向MetroNetwork(简称MN)发送全部详细路由;ChinaNet(简称CN)向MN发送默认路由。
2、MN内运行OSPF,R5、R6向R7发送全部路由(包括默认路由)。
3、R5、R6上任何链路断开都应自动切换到对方的链路。
4、我自己加的,MN应该为STUB。即:不能为CN、CN2传输数据。
配置思路:
一、由于是典型的多宿主多出口,故BGP是唯一的选择。而由于要求里CN2并不发送默认路由,因此可认为两宿主并没有重复路由;即不需要修改Local-Pref参数。而且由于没有对访问流量的进入进行要求,因此也不需要修改MED和AS-PATH参数。现实中建议对R5、R6进行优先级设置。使得对于CN、CN2能通过不同的ASBR访问。
二、《Internet路由结构》提到过,发布AS内部的路由有两种方式:network显式引入以及redistribute隐式引入。出于对internet路由稳定性负责的考虑,故在R5、R6内对R7的内网段使用ip route静态路由到null0,并使用network命令在bgp中显式引入。
三、多宿主+部分具体路由的结构,使得把R5、R6的BGP重分配到OSPF中成为最佳选择。仅仅重分配会出现问题,后面排障时会提及到。使用重分配有个好处,就是BGP的路由表中消失的路由就不会被引入到OSPF中,使得OSPF可以选择另一条备份链路。
四、通过过滤列表即可实现。考虑到CN、CN2为ISP,应负责限制策略。对入路由,过滤掉非MN产生的路由;对出路由,设置community为local-AS,防止路由被通告到其他AS。
配置文件如下,由于R1和R2,R3和R4,R5和R6配置差别不大,故只写R1、R3、R5、R7的配置。其中网段IP很直观,R1和R2的链路ip为12.0.0.0/24,R3和R5链路IP为35.0.0.0/24。R7的内网口IP为7.0.0.0/24。CN2为AS1、CN为AS2,MN为AS3。
CN2_R1#
interface Loopback0
ip address 1.1.1.1 255.255.255.255
!
interface Serial1/1
description To R5's S1/0,ip 15.0.0.5/24
ip address 15.0.0.1 255.255.255.0
!
interface FastEthernet2/0
ip address 12.0.0.1 255.255.255.0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
network 12.0.0.0 mask 255.255.255.0
neighbor LOCAL_AS peer-group
neighbor LOCAL_AS remote-as 1
neighbor LOCAL_AS update-source Loopback0
neighbor LOCAL_AS next-hop-self
neighbor REMOTE_AS_3 peer-group
neighbor REMOTE_AS_3 remote-as 3
neighbor REMOTE_AS_3 send-community
neighbor REMOTE_AS_3 route-map AS_3_SET_COMM out
neighbor REMOTE_AS_3 filter-list 10 in
neighbor 2.2.2.2 peer-group LOCAL_AS
neighbor 15.0.0.5 peer-group REMOTE_AS_3
no auto-summary
!
ip route 2.2.2.2 255.255.255.255 12.0.0.2
!
ip as-path access-list 10 permit ^3$
!
route-map AS_3_SET_COMM permit 10
set community local-AS
!
ip address 1.1.1.1 255.255.255.255
!
interface Serial1/1
description To R5's S1/0,ip 15.0.0.5/24
ip address 15.0.0.1 255.255.255.0
!
interface FastEthernet2/0
ip address 12.0.0.1 255.255.255.0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
network 12.0.0.0 mask 255.255.255.0
neighbor LOCAL_AS peer-group
neighbor LOCAL_AS remote-as 1
neighbor LOCAL_AS update-source Loopback0
neighbor LOCAL_AS next-hop-self
neighbor REMOTE_AS_3 peer-group
neighbor REMOTE_AS_3 remote-as 3
neighbor REMOTE_AS_3 send-community
neighbor REMOTE_AS_3 route-map AS_3_SET_COMM out
neighbor REMOTE_AS_3 filter-list 10 in
neighbor 2.2.2.2 peer-group LOCAL_AS
neighbor 15.0.0.5 peer-group REMOTE_AS_3
no auto-summary
!
ip route 2.2.2.2 255.255.255.255 12.0.0.2
!
ip as-path access-list 10 permit ^3$
!
route-map AS_3_SET_COMM permit 10
set community local-AS
!
end
ChinaNet_R3#
interface Loopback0
ip address 3.3.3.3 255.255.255.255
!
interface Serial1/1
description To R5's S1/1,ip 35.0.0.5/24
ip address 35.0.0.3 255.255.255.0
!
interface FastEthernet2/0
ip address 34.0.0.3 255.255.255.0
!
router bgp 2
no synchronization
bgp router-id 3.3.3.3
neighbor LOCAL_AS peer-group
neighbor LOCAL_AS remote-as 2
neighbor LOCAL_AS update-source Loopback0
neighbor LOCAL_AS next-hop-self
neighbor REMOTE_AS_3 peer-group
neighbor REMOTE_AS_3 remote-as 3
neighbor REMOTE_AS_3 send-community
neighbor REMOTE_AS_3 default-originate
neighbor REMOTE_AS_3 route-map AS_3_SET_COMM out
neighbor REMOTE_AS_3 filter-list 10 in
neighbor 4.4.4.4 peer-group LOCAL_AS
neighbor 35.0.0.5 peer-group REMOTE_AS_3
no auto-summary
!
ip route 4.4.4.4 255.255.255.255 34.0.0.4
!
ip as-path access-list 10 permit ^3$
!
route-map AS_3_SET_COMM permit 10
set community local-AS
!
end
ip address 3.3.3.3 255.255.255.255
!
interface Serial1/1
description To R5's S1/1,ip 35.0.0.5/24
ip address 35.0.0.3 255.255.255.0
!
interface FastEthernet2/0
ip address 34.0.0.3 255.255.255.0
!
router bgp 2
no synchronization
bgp router-id 3.3.3.3
neighbor LOCAL_AS peer-group
neighbor LOCAL_AS remote-as 2
neighbor LOCAL_AS update-source Loopback0
neighbor LOCAL_AS next-hop-self
neighbor REMOTE_AS_3 peer-group
neighbor REMOTE_AS_3 remote-as 3
neighbor REMOTE_AS_3 send-community
neighbor REMOTE_AS_3 default-originate
neighbor REMOTE_AS_3 route-map AS_3_SET_COMM out
neighbor REMOTE_AS_3 filter-list 10 in
neighbor 4.4.4.4 peer-group LOCAL_AS
neighbor 35.0.0.5 peer-group REMOTE_AS_3
no auto-summary
!
ip route 4.4.4.4 255.255.255.255 34.0.0.4
!
ip as-path access-list 10 permit ^3$
!
route-map AS_3_SET_COMM permit 10
set community local-AS
!
end
LOCAL_R5#
!interface Loopback0
ip address 5.5.5.5 255.255.255.255
!
interface Serial1/0
description To R1's S1/1,ip 15.0.0.1/24
ip address 15.0.0.5 255.255.255.0
!
interface Serial1/1
description To R3's S1/1,ip 35.0.0.3/24
ip address 35.0.0.5 255.255.255.0
!
interface Serial1/2
description To R6's S1/2,ip 56.0.0.6/24
ip address 56.0.0.5 255.255.255.0
!
interface Serial1/3
description To R7's S1/0,ip 57.0.0.7/24
ip address 57.0.0.5 255.255.255.0
!
router ospf 100
router-id 5.5.5.5
redistribute bgp 3 subnets
network 5.5.5.5 0.0.0.0 area 0
network 56.0.0.5 0.0.0.0 area 0
network 57.0.0.5 0.0.0.0 area 0
default-information originate
!
router bgp 3
no synchronization
bgp router-id 5.5.5.5
network 7.0.0.0 mask 255.255.255.0
network 56.0.0.0 mask 255.255.255.0
network 57.0.0.0 mask 255.255.255.0
network 67.0.0.0 mask 255.255.255.0
neighbor LOCAL_AS peer-group
neighbor LOCAL_AS remote-as 3
neighbor LOCAL_AS update-source Loopback0
neighbor LOCAL_AS next-hop-self
neighbor REMOTE_AS_1 peer-group
neighbor REMOTE_AS_1 remote-as 1
neighbor REMOTE_AS_2 peer-group
neighbor REMOTE_AS_2 remote-as 2
neighbor 6.6.6.6 peer-group LOCAL_AS
neighbor 15.0.0.1 peer-group REMOTE_AS_1
neighbor 35.0.0.3 peer-group REMOTE_AS_2
no auto-summary
!
ip address 5.5.5.5 255.255.255.255
!
interface Serial1/0
description To R1's S1/1,ip 15.0.0.1/24
ip address 15.0.0.5 255.255.255.0
!
interface Serial1/1
description To R3's S1/1,ip 35.0.0.3/24
ip address 35.0.0.5 255.255.255.0
!
interface Serial1/2
description To R6's S1/2,ip 56.0.0.6/24
ip address 56.0.0.5 255.255.255.0
!
interface Serial1/3
description To R7's S1/0,ip 57.0.0.7/24
ip address 57.0.0.5 255.255.255.0
!
router ospf 100
router-id 5.5.5.5
redistribute bgp 3 subnets
network 5.5.5.5 0.0.0.0 area 0
network 56.0.0.5 0.0.0.0 area 0
network 57.0.0.5 0.0.0.0 area 0
default-information originate
!
router bgp 3
no synchronization
bgp router-id 5.5.5.5
network 7.0.0.0 mask 255.255.255.0
network 56.0.0.0 mask 255.255.255.0
network 57.0.0.0 mask 255.255.255.0
network 67.0.0.0 mask 255.255.255.0
neighbor LOCAL_AS peer-group
neighbor LOCAL_AS remote-as 3
neighbor LOCAL_AS update-source Loopback0
neighbor LOCAL_AS next-hop-self
neighbor REMOTE_AS_1 peer-group
neighbor REMOTE_AS_1 remote-as 1
neighbor REMOTE_AS_2 peer-group
neighbor REMOTE_AS_2 remote-as 2
neighbor 6.6.6.6 peer-group LOCAL_AS
neighbor 15.0.0.1 peer-group REMOTE_AS_1
neighbor 35.0.0.3 peer-group REMOTE_AS_2
no auto-summary
!
ip route 7.0.0.0 255.255.255.0 NULL0
ip route 56.0.0.0 255.255.255.0 NULL0
ip route 57.0.0.0 255.255.255.0 NULL0
ip route 67.0.0.0 255.255.255.0 NULL0
!
end
end
LOCAL_R7#
!
interface Loopback0
ip address 7.7.7.7 255.255.255.255
!
interface Serial1/0
description To R5's S1/3,ip 57.0.0.5/24
ip address 57.0.0.7 255.255.255.0
!
interface Serial1/1
description To R6's S1/3,ip 67.0.0.6/24
ip address 67.0.0.7 255.255.255.0
!
interface FastEthernet2/0
ip address 7.0.0.7 255.255.255.0
!
router ospf 100
router-id 7.7.7.7
passive-interface FastEthernet2/0
network 7.0.0.7 0.0.0.0 area 0
network 57.0.0.7 0.0.0.0 area 0
network 67.0.0.7 0.0.0.0 area 0
!
end
interface Loopback0
ip address 7.7.7.7 255.255.255.255
!
interface Serial1/0
description To R5's S1/3,ip 57.0.0.5/24
ip address 57.0.0.7 255.255.255.0
!
interface Serial1/1
description To R6's S1/3,ip 67.0.0.6/24
ip address 67.0.0.7 255.255.255.0
!
interface FastEthernet2/0
ip address 7.0.0.7 255.255.255.0
!
router ospf 100
router-id 7.7.7.7
passive-interface FastEthernet2/0
network 7.0.0.7 0.0.0.0 area 0
network 57.0.0.7 0.0.0.0 area 0
network 67.0.0.7 0.0.0.0 area 0
!
end
浅蓝色字体表示OSPF路由条目被显式引入到BGP;红色字体表示ISP入路由策略,限制只让AS-PATH为3(MN)的路由进入;紫色字体表示ISP出路由策略,限制出路由只供对端AS使用;绿色字体表示CN2的详细路由被重分配到MN的ASBR中。
但正如之前说过,单纯的重分配会有问题。主要是因为,即便R5的BGP表内存在默认路由,redistribute也不会将该路由重分配到OSPF内。因此深蓝色字体表示OSPF自身生成default-information并发布到area 0中(其实是整个AS中,不过这里就只有一个area 0)。注意这里不能加always参数。为何?因为这里有一个限制条件:只有能够接收到来自CN默认路由的ASBR才能向OSPF内部发布默认路由。由于BGP收到邻居生成的默认路由(注意R3的neighbor default-originate),show ip route内才会生成B *0.0.0.0的路由;仅当ASBR拥有默认路由,OSPF中的default-information才会生效。若链路出现问题,例如R3和R5之间的链路中断了,BGP刷新并丢弃路由条目B *0.0.0.0后,R5的OSPF就不再发布默认路由,此时R7就可以通过R6所发布的默认路由到达CN了。
该实验还有很多地方不完善,主要是ISP方面没有设置BGP DAMPENING,没有考虑到R5、R6基于目的地负载均衡。我的经验只能写到上述配置,权当经验交流吧。