#lab BGP1# 基本配置
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110 //AS内部使用OSPF路由协议
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 12.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1 //BGP的routerID
bgp log-neighbor-changes
neighbor J peer-group //BGP需要指邻居
neighbor J remote-as 1 //邻居的AS号
neighbor J update-source Loopback0 //更新源,如果不指定默认是包发送端口的IP
neighbor 2.2.2.2 peer-group J //调用上述建邻居模板
neighbor 3.3.3.3 peer-group J //调用模板
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 24.1.1.2 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 2.2.2.2
log-adjacency-changes
network 2.2.2.0 0.0.0.255 area 0
network 12.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 next-hop-self //保证下一跳可达,主要做在AS边界路由器上
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 24.1.1.4 remote-as 4 //EBGP邻居,直连接口建邻居,如果是用环回口,必须修改多跳和update source
no auto-summary
!
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface Serial1/0
ip address 35.1.1.3 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.3 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 3.3.3.3
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 next-hop-self
neighbor 2.2.2.2 remote-as 1
neighbor 2.2.2.2 update-source Loopback0
neighbor 2.2.2.2 next-hop-self
neighbor 5.5.5.5 remote-as 5 //EBGP邻居
neighbor 5.5.5.5 ebgp-multihop 2 //修改多跳
neighbor 5.5.5.5 update-source Loopback0 //用环回口建邻居
no auto-summary
!
ip route 5.5.5.5 255.255.255.255 Serial1/0 //环回口建邻居,必须保证有路由
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router bgp 4
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
network 4.4.4.0 mask 255.255.255.0 //通告路由
neighbor 24.1.1.2 remote-as 1
no auto-summary
!
R5-
interface Loopback0
ip address 5.5.5.5 255.255.255.0
!
interface Serial1/0
ip address 35.1.1.5 255.255.255.0
serial restart-delay 0
!
router bgp 5
no synchronization
bgp log-neighbor-changes
network 5.5.5.0 mask 255.255.255.0 //通告路由
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 ebgp-multihop 2
neighbor 3.3.3.3 update-source Loopback0
no auto-summary
!
ip route 3.3.3.3 255.255.255.255 Serial1/0 //因为用环回口建邻居,必须保证有路由
实验结果:
show 命令,只有通告的路由才在吗?
#lab BGP2# 下一跳是MA网络
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.1 255.255.255.0
duplex auto
speed auto
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
router rip
version 2
network 1.0.0.0
network 134.1.0.0
no auto-summary
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0 //通告路由
neighbor 12.1.1.1 remote-as 1
no auto-summary
!
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.3 255.255.255.0
duplex auto
speed auto
!
router rip
version 2
network 3.0.0.0
network 134.1.0.0
no auto-summary
!
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 134.1.1.4 remote-as 4
no auto-summary
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.4 255.255.255.0
duplex auto
speed auto
!
router bgp 4
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 134.1.1.3 remote-as 1
no auto-summary
!
实验结果:
#lab BGP3# 路由聚合方法一
实验拓扑:
配置:
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.1 255.255.255.0
duplex auto
speed auto
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
router rip
version 2
network 1.0.0.0
network 134.1.0.0
no auto-summary
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
redistribute rip
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
neighbor 12.1.1.2 soft-reconfiguration inbound //用来查看从邻居12.1.1.2收到路由
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback16
ip address 200.1.16.2 255.255.255.0
!
interface Loopback17
ip address 200.1.17.2 255.255.255.0
!
interface Loopback18
ip address 200.1.18.2 255.255.255.0
!
interface Loopback19
ip address 200.1.19.2 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 200.1.16.0 mask 255.255.252.0 //将手工写的聚合路由通告出来
neighbor 12.1.1.1 remote-as 1
no auto-summary
!
ip route 200.1.16.0 255.255.252.0 Null0 //现在本地写一条指向空接口的聚合路由
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.3 255.255.255.0
duplex auto
speed auto
!
router rip
version 2
network 3.0.0.0
network 134.1.0.0
no auto-summary
!
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 134.1.1.4 remote-as 4
no auto-summary
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.4 255.255.255.0
duplex auto
speed auto
!
router bgp 4
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 134.1.1.3 remote-as 1
no auto-summary
!
实验结果:
#lab BGP4# 路由汇聚方法二
实验拓扑:
配置:
R1,R3,R4配置同上
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback16
ip address 200.1.16.2 255.255.255.0
!
interface Loopback17
ip address 200.1.17.2 255.255.255.0
!
interface Loopback18
ip address 200.1.18.2 255.255.255.0
!
interface Loopback19
ip address 200.1.19.2 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 200.1.16.0
network 200.1.17.0
network 200.1.18.0
network 200.1.19.0 //通告出明细路由
aggregate-address 200.1.16.0 255.255.252.0 summary-only //路由聚合,summary-only是不传明细路由
neighbor 12.1.1.1 remote-as 1
no auto-summary
!
实验结果:
#lab BGP5# 路由汇聚扩展一抑制某些路由
实验拓扑:
配置:
R1,R3,R4配置同上
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback16
ip address 200.1.16.2 255.255.255.0
!
interface Loopback17
ip address 200.1.17.2 255.255.255.0
!
interface Loopback18
ip address 200.1.18.2 255.255.255.0
!
interface Loopback19
ip address 200.1.19.2 255.255.255.0
!
interface FastEthernet0/0
no ip address
shutdown
duplex auto
speed auto
!
interface FastEthernet0/1
no ip address
shutdown
duplex auto
speed auto
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 200.1.16.0
network 200.1.17.0
network 200.1.18.0
network 200.1.19.0
aggregate-address 200.1.16.0 255.255.252.0 suppress-map SUP //抑制route map中匹配的路由
neighbor 12.1.1.1 remote-as 1
no auto-summary
!
ip prefix-list 1 seq 5 permit 200.1.16.0/23 ge 24 le 24 //抓路由
!
route-map SUP permit 10
match ip address prefix-list 1
!
实验结果:
#lab BGP6# 路由聚合扩展二聚合路由和明细路由不在一个路由器,防止聚合路由传回需要做水平分割
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface FastEthernet0/0
ip address 134.1.1.1 255.255.255.0
duplex auto
speed auto
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
router rip
version 2
network 1.0.0.0
network 134.1.0.0
no auto-summary
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
aggregate-address 200.1.16.0 255.255.252.0 as-set summary-only //在路由传播入方向做聚合,还原聚合路由的AS号属性
redistribute rip
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
neighbor 12.1.1.2 soft-reconfiguration inbound
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback16
ip address 200.1.16.2 255.255.255.0
!
interface Loopback17
ip address 200.1.17.2 255.255.255.0
!
interface Loopback18
ip address 200.1.18.2 255.255.255.0
!
interface Loopback19
ip address 200.1.19.2 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 200.1.16.0
network 200.1.17.0
network 200.1.18.0
network 200.1.19.0
neighbor 12.1.1.1 remote-as 1
neighbor 12.1.1.1 soft-reconfiguration inbound
no auto-summary
!
R3,R4配置同上
实验结果:
#lab BGP7# BGP选路策略1.较大的weight-使用route map的方式
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback9
ip address 9.9.9.9 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 24.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 9.9.9.0 mask 255.255.255.0
neighbor 12.1.1.1 remote-as 1
neighbor 24.1.1.4 remote-as 1
no auto-summary
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.3 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 13.1.1.3 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 3.3.3.3
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 route-map W in //使用route map,做在入方向
neighbor 4.4.4.4 remote-as 1
neighbor 4.4.4.4 update-source Loopback0
no auto-summary
!
ip prefix-list 2 seq 5 permit 2.2.2.0/24 //抓路由
!
route-map W permit 10 //route map做策略
match ip address prefix-list 2
set weight 3 //设定weight值为3
!
route-map W permit 20
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.4 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 24.1.1.2 remote-as 2
no auto-summary
!
实验结果:
#lab BGP8# BGP选路策略2.本地优先级-使用route map方式
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 3.3.3.3 route-map L out //在出方向上应用route map
neighbor 12.1.1.2 remote-as 2
no auto-summary
!
access-list 2 permit 2.2.2.0 //抓路由
!
route-map L permit 10
match ip address 2
set local-preference 123 //设置local preference的值
!
route-map L permit 20
!
R2,R4配置同上
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.3 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 13.1.1.3 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 3.3.3.3
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 4.4.4.4 remote-as 1
neighbor 4.4.4.4 update-source Loopback0
no auto-summary
实验结果:
#lab BGP9#BGP选路策略4.AS path-方法一,应用于出方向
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback9
ip address 9.9.9.9 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 24.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 9.9.9.0 mask 255.255.255.0
neighbor 12.1.1.1 remote-as 1
neighbor 24.1.1.4 remote-as 1
neighbor 24.1.1.4 route-map AS out //在出方向应用 route map
no auto-summary
!
ip prefix-list 2 seq 5 permit 2.2.2.0/24
!
route-map AS permit 10
match ip address prefix-list 2
set as-path prepend 6 7 8 //增加AS path的值
!
route-map AS permit 20
!
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.3 255.255.255.0
duplex auto
speed auto
!
interface Serial1/0
ip address 35.1.1.3 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.3 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 3.3.3.3
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 4.4.4.4 remote-as 1
neighbor 4.4.4.4 update-source Loopback0
neighbor 35.1.1.5 remote-as 5
no auto-summary
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.4 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 24.1.1.2 remote-as 2
no auto-summary
!
R5-
interface Loopback0
ip address 5.5.5.5 255.255.255.0
!
interface Serial0/0
ip address 35.1.1.5 255.255.255.0
serial restart-delay 0
!
router bgp 5
no synchronization
bgp log-neighbor-changes
neighbor 35.1.1.3 remote-as 1
no auto-summary
!
实验结果:
#lab BGP10# BGP选路策略4.AS path-方法二应用到入方向
实验拓扑:
配置:
R1,R3,R5配置同上
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback9
ip address 9.9.9.9 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 24.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 9.9.9.0 mask 255.255.255.0
neighbor 12.1.1.1 remote-as 1
neighbor 24.1.1.4 remote-as 1
no auto-summary
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.4 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 24.1.1.2 remote-as 2
neighbor 24.1.1.2 route-map AS in //在入方向做route map,如果做在R3的入方向?
no auto-summary
!
ip prefix-list 2 seq 5 permit 2.2.2.0/24
!
route-map AS permit 10
match ip address prefix-list 2
set as-path prepend 7 8 9
!
route-map AS permit 20
!
实验结果:
#lab BGP11# BGP选路策略6.MED
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
neighbor 12.1.1.2 route-map MED out //出方向应用 route map
no auto-summary
!
route-map MED permit 10 //匹配所有路由,即R1通告给R2的所有路由
set metric 8
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback9
ip address 9.9.9.9 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 24.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 9.9.9.0 mask 255.255.255.0
neighbor 12.1.1.1 remote-as 1
neighbor 24.1.1.4 remote-as 1
no auto-summary
!
R3,R5同上
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.4 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 24.1.1.2 remote-as 2
no auto-summary
!
实验结果:
#lab BGP12# 路由反射器
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
no auto-summary
!
R2-
interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Loopback9
ip address 9.9.9.9 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.2 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 24.1.1.2 255.255.255.0
serial restart-delay 0
!
router bgp 2
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
network 9.9.9.0 mask 255.255.255.0
neighbor 12.1.1.1 remote-as 1
neighbor 24.1.1.4 remote-as 1 //有错?不应该和R4建邻居
no auto-summary
!
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface Loopback8
ip address 8.8.8.8 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.3 255.255.255.0
duplex auto
speed auto
!
interface Serial1/0
ip address 35.1.1.3 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.3 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 3.3.3.3
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
network 8.8.8.0 mask 255.255.255.0
neighbor 1.1.1.1 remote-as 1
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 route-reflector-client //设置邻居为RR客户端
neighbor 4.4.4.4 remote-as 1
neighbor 4.4.4.4 update-source Loopback0
neighbor 4.4.4.4 route-reflector-client //设置邻居为RR客户端
neighbor 35.1.1.5 remote-as 5
no auto-summary
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.4 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 1
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
neighbor 3.3.3.3 remote-as 1
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 24.1.1.2 remote-as 2 //有错?
no auto-summary
!
R5配置同上
实验结果:
#lab BGP13#联邦
实验拓扑:
配置:
R1-
interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial1/0
ip address 12.1.1.1 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.1 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 1.1.1.1
log-adjacency-changes
network 1.1.1.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
!
router bgp 64512 //小AS号
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
bgp confederation identifier 1 //大AS号,小AS所在的大AS
neighbor 3.3.3.3 remote-as 64512
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 12.1.1.2 remote-as 2
no auto-summary
!
R2,R5配置同上
R3-
interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface Loopback8
ip address 8.8.8.8 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.3 255.255.255.0
duplex auto
speed auto
!
interface Serial1/0
ip address 35.1.1.3 255.255.255.0
serial restart-delay 0
!
interface Serial1/1
ip address 13.1.1.3 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 3.3.3.3
log-adjacency-changes
network 3.3.3.0 0.0.0.255 area 0
network 13.1.1.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 64512
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
bgp confederation identifier 1
bgp confederation peers 64513 //小AS边界的路由器上要互指peer
neighbor 1.1.1.1 remote-as 64512
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 next-hop-self
neighbor 4.4.4.4 remote-as 64513
neighbor 4.4.4.4 ebgp-multihop 2
neighbor 4.4.4.4 update-source Loopback0
no auto-summary
!
R4-
interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface FastEthernet0/0
ip address 34.1.1.4 255.255.255.0
duplex auto
speed auto
!
interface Serial1/1
ip address 24.1.1.4 255.255.255.0
serial restart-delay 0
!
router ospf 110
router-id 4.4.4.4
log-adjacency-changes
network 4.4.4.0 0.0.0.255 area 0
network 34.1.1.0 0.0.0.255 area 0
!
router bgp 64513
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
bgp confederation identifier 1
bgp confederation peers 64512
neighbor 3.3.3.3 remote-as 64512
neighbor 3.3.3.3 ebgp-multihop 2
neighbor 3.3.3.3 update-source Loopback0
no auto-summary
!
实验结果: