说明
前面了解了BGP基础概念,下面搭建简单的BGP实验场景,基于遇到的测试用例记录BGP不同测试场景下的配置方法。在FRR源码中 tests/topotests 目录下存在很多经典的场景配置,对路由网络有一定了解可以直接参考topotests下配置即可。本文主要记录学习BGP时从刚开始接触到慢慢了解的过程,后续会持续补充遇到的各种场景配置。
BGP相关命令都是基于FRR,基础网络配置使用系统命令,数据面也涉及VPP相关命令。
测试拓扑:
BGP基础
查询命令
#已有配置
do show running-config
#BGP邻居详细信息
do show bgp neighbors
#BGP概要信息
do show bgp summary
#BGP ipv4/6所有地址族
do show bgp ipv4 all
do show bgp ipv6 all
#BGP基于vrf的router信息
do show bgp vrfs
#BGP所有vrf信息
do show bgp vrf all
#内核路由表,包括vrf
do show ip route vrf all
创建IBGP邻居
BGP创建邻居前提要求,配置的neighbor IP L3互通。
R1
router bgp 1000
neighbor 192.168.55.105 remote-as 1000
或者
neighbor 192.168.55.105 remote-as internal
R2
router bgp 1000
neighbor 192.168.55.103 remote-as 1000
或者
neighbor 192.168.55.103 remote-as internal
创建EBGP邻居
创建EBGP邻居,需要配置ebgp-multihop才能配置成功。
R1
router bgp 56
neighbor 192.168.55.105 remote-as 65
neighbor 192.168.55.105 ebgp-multihop 255
R2
router bgp 65
neighbor 192.168.55.103 remote-as 56
neighbor 192.168.55.103 ebgp-multihop 255
创建BGP邻居-IPV6
R1和R2分别在2个虚拟机上,虚拟机的enp1s0是虚拟网卡,通过宿主机上br进行了桥接。要创建IPV6 BGP邻居也是要保证IPV6 L3通,所以虚拟机网桥virbr1要先支持IPV6转发。
宿主机
sysctl net.ipv6.conf.virbr1.disable_ipv6=0
ip addr add 2001:db8:55::1/64 dev virbr1
R1
interface enp1s0
ip address 192.168.55.103/24
ipv6 address 2001:db8:55::103/64
router bgp 1000
neighbor 2001:db8:55::105 remote-as 1000
R2
interface enp1s0
ip address 192.168.55.105/24
ipv6 address 2001:db8:55::105/64
router bgp 1000
neighbor 2001:db8:55::103 remote-as 1000
引入BGP路由
前提:BGP邻居已建立
想要引入IPV6 路由,邻居双方需要都在address-family ipv6 unicast下激活邻居,IPV4 单播AF下是默认激活的,所以不需要配置。
R1
router bgp 1000
neighbor 2001:db8:55::105 remote-as 1000
!
address-family ipv4 unicast
network 1.1.1.1/32
exit-address-family
!
address-family ipv6 unicast
network 1000:5:102::/64
neighbor 2001:db8:55::105 activate
exit-address-family
exit
R2
router bgp 1000
neighbor 2001:db8:55::103 remote-as 1000
!
address-family ipv6 unicast
neighbor 2001:db8:55::103 activate
exit-address-family
exit
路由映射表 route-map
route-map即路由映射表,是由一组match字句和set字句构成,他实际上是访问控制列表的一个超集。主要功能包括路由控制和策略路由等。详细不展开了,请参考 BGP route-map理解
R1
router bgp 1000
neighbor 2001:db8:55::105 remote-as 1000
!
address-family ipv4 unicast
network 1.1.1.1/32 route-map rqw-rm
exit-address-family
exit
!
ip prefix-list rqw-pl seq 100 permit 1.1.1.1/32
!
route-map rqw-rm permit 10
match ip address prefix-list rqw-pl
exit
R2
router bgp 1000
neighbor 2001:db8:55::103 remote-as 1000
exit
路由权重 weight
路由权重的设置只影响本端收到BGP邻居同步过来的路由,常用于本端访问目标网络存在多条路由时的路由选路。详细可以参考BGP-路径属性与选路原则
R1
router bgp 1000
neighbor 192.168.55.105 remote-as 1000
!
address-family ipv6 unicast
network 1001:5::/32
neighbor 192.168.55.105 activate
exit-address-family
exit
R2
router bgp 1000
neighbor 192.168.55.103 remote-as 1000
!
address-family ipv6 unicast
neighbor 192.168.55.103 activate
neighbor 192.168.55.103 weight 6666
exit-address-family
exit
VRF 实例
TODO
BGP拓展
L2VPN EVPN
TODO