Configuration Guide
BGP Configuration Guide
24 min
bgp basic configuration bgp basic configuration introduction introduction bgp (border gateway protocol) is a distance vector routing protocol that facilitates routing reachability and selection of the best routes between autonomous systems (ases) to manage the ever expanding networks more effectively, networks are divided into different autonomous systems in 1982, exterior gateway protocol (egp) was used to dynamically exchange routing information between ases however, egp was designed with simplicity and only announced reachable network routes without route selection or loop avoidance mechanisms it quickly became insufficient to meet the needs of network management this led to the development of bgp, which allows for route selection, loop prevention, efficient route propagation, and management of a large number of routes basic concepts basic concepts autonomous system (as) autonomous system (as) an autonomous system (as) refers to an ip network under the control of a single administrative entity with a common routing policy each as in a bgp network is assigned a unique as number, which is used to distinguish different ases as numbers come in 2 byte and 4 byte formats, with the range of 2 byte as numbers being 1 to 65535, and 4 byte as numbers ranging from 1 to 4294967295 devices that support 4 byte as numbers can be compatible with devices that support 2 byte as numbers bgp classification bgp classification bgp is categorized into exterior bgp (ebgp) and interior bgp (ibgp) based on its operational context ibgp (internal bgp) ibgp operates within the same as to prevent loops within the as, bgp devices do not advertise routes learned from ibgp peers to other ibgp peers full connections are established with all ibgp peers when deploying ibgp, route reflectors (rrs) can be introduced to simplify full connection configurations all leaf devices establish bgp peer relationships only with the rr the rr discovers and accepts bgp connections initiated by vteps, forming a client list, and reflects routes received from a vtep to all other vteps rrs can be deployed on spine devices, leaf devices, or as standalone devices ebgp (exterior bgp) ebgp operates between different ases to prevent loops between ases, bgp devices discard routes received from ebgp peers that contain the local as number when deploying ebgp, rrs are not needed bgp automatically sends evpn messages received from ebgp neighbors to other ebgp and ibgp neighbors, effectively making the spine device function as a rr in most cases, devices within a network have different as numbers, making ebgp a common choice in sonic if redundant leafs are used with the same asn, ibgp can be used roles in bgp message exchange roles in bgp message exchange in bgp message exchange, there are two roles speaker and peer speaker the device that sends bgp messages is referred to as a bgp speaker it receives or generates new message information and advertises it to other bgp speakers peer speakers that exchange messages with each other are referred to as peers several related peers can form a peer group router id router id the router id is a 32 bit value used to identify a bgp device it is typically represented in the form of an ipv4 address and is carried in the open message sent during bgp session establishment when establishing a bgp session between peers, each bgp device must have a unique router id without a unique router id, bgp connections between peers cannot be established bgp configuration bgp configuration configure tasks instructions index bgp basic functions enable bgp required enabling bgp neighbors configure router id required configuring router id configure bgp neighbors optional configuring bgp neighbor configure bfd integration with bgp optional display and maintenance enabling bgp neighbors enabling bgp neighbors operation command description enter the system configuration view configure terminal enter the bgp view router bgp asn enable bgp session for a specific neighbor no neighbor { ipaddr | hostname } shutdown by default, bgp sessions are in the enabled state enable all bgp session no bgp shutdown configuring router id configuring router id the router id uniquely identifies a device within the entire autonomous system by default, the ip address of the loopback interface is used as the router id operation command description enter the system configuration view configure terminal enter the bgp view router bgp asn configure router id bgp router id ip addr configuring bgp neighbor configuring bgp neighbor operation command description enter the system configuration view configure terminal enter the bgp view router bgp asn add bgp neighbor neighbor neighbor ip remote as asn configuring bfd integration with bgp configuring bfd integration with bgp operation command description enter the system configuration view configure terminal enter the bgp view router bgp asn configure bfd integration with bgp neighbor { ipaddr | hostname } bfd display and maintenance display and maintenance operation command description display detailed information of bgp neighbor show ip bgp neighbors {ipaddr|hostname} \[option] ipaddr specifies the ip address of the neighbor hostname specifies the hostname of the neighbor options for displaying specific information include routes displays routes learned from the neighbor advertised routes displays routes advertised to the neighbor received routes displays routes received from the neighbor prefix counts displays detailed prefix count information filtered routes displays filtered routes received from the neighbor bestpath routes displays routes selected based on the best path received displays received information from the neighbor flap statistics displays flap statistics of routes learned from the neighbor dampened routes displays dampened routes received from the neighbor json displays information in json format display bgp neighbor network information show ip bgp \[ a b c d/m | a b c d ] display bgp neighbor summary information show ip bgp summary \[ established | failed | json ] established displays a summary of established bgp neighbors failed displays a summary of failed bgp neighbors json displays the summary information in json format configuration example configuration example network requirements hosts in different network segments are connected through three devices, all of which run the bgp protocol it is required to configure ibgp and ebgp neighbors so that pc1 under device a and pc2 under device c can interoperate procedure 1 take device a as an example to configure the ip address of each interface \# create vlans and add member interfaces sonic(config)# vlan 100 sonic(config)# interface ethernet 1 sonic(config if 1)# switchport access vlan 100 sonic(config)# interface ethernet 2 sonic(config if 2)# switchport access vlan 100 \# configuring ip addresses for interfaces sonic(config)# interface vlan 100 sonic(config vlanif 100)# ip address 10 10 0 2/24 sonic(config vlanif 100)# exit sonic(config)# interface ethernet 4 sonic(config if 4)# ip address 10 0 0 1/30 sonic(config if 4)# exit config routerinterface loopback 0 sonic(config loif 0)# ip address 10 1 15 10/32 2 configure ibgp connection \# device a sonic(config)# router bgp 65001 sonic(config router)# bgp router id 10 1 15 10 sonic(config router)# no bgp ibgp requires policy sonic(config router)# neighbor 10 0 0 2 remote as 65001 sonic(config router)# neighbor 10 0 0 2 bfd sonic(config router)# neighbor 10 0 0 2 description deviceb \# declare the directly connected route on device a sonic(config router)# address family ipv4 unicast sonic(config router af)# redistribute connected \# device b sonic(config)# router bgp 65001 sonic(config router)# bgp router id 10 1 15 20 sonic(config router)# no bgp ibgp requires policy sonic(config router)# neighbor 10 0 0 1 remote as 65001 sonic(config router)# neighbor 10 0 0 1 bfd sonic(config router)# neighbor 10 0 0 1 description devicea 3 configure ebgp connection \# device b sonic(config)# router bgp 65001 sonic(config router)# no bgp ebgp requires policy sonic(config router)# neighbor 30 0 0 1 remote as 65003 sonic(config router)# neighbor 30 0 0 1 bfd sonic(config router)# neighbor 30 0 0 1 description devicec \# device c sonic(config)# router bgp 65003 sonic(config router)# bgp router id 10 1 15 30 sonic(config router)# no bgp ebgp requires policy sonic(config router)# no bgp ibgp requires policy sonic(config router)# neighbor 30 0 0 2 remote as 65001 sonic(config router)# neighbor 30 0 0 2 bfd sonic(config router)# neighbor 30 0 0 2 description deviceb \# declare a directly connected route on device c sonic(config router)# address family ipv4 unicast sonic(config router af)# redistribute connected verify configuration 1 take device b as an example to check whether the bgp connection is established successfully sonic# show ip bgp summary ipv4 unicast summary bgp router identifier 10 1 15 20, local as number 65001 vrf id 0 bgp table version 1474 rib entries 37, using 7104 bytes of memory peers 4, using 85 kib of memory peer groups 6, using 384 bytes of memory neighbor v as msgrcvd msgsent tblver inq outq up/down state/pfxrcd pfxsnt 10 0 0 1 4 65001 30274 3672 0 0 0 01 16 37 17 22 30 0 0 1 4 65003 29184 3712 0 0 0 01 00 07 16 22 2 pc1 and pc2 can ping each other bgp route policy configuration bgp route policy configuration introduction introduction in bgp networks, route policy is a crucial approach that allows flexible control over the propagation and reception of routes by modifying their attributes it involves the following steps define a set of matching rules to identify the characteristics of the routes for which the route policy will be applied these characteristics can include destination addresses, originating router addresses, and more create specific policies based on the matching rules, which may involve modifying route attributes or restricting the route propagation apply the defined policies to various stages of route handling, such as route advertisement, reception, and introduction, to effectively control the behavior of routes by implementing route policies, network administrators can fine tune the behavior of bgp routes according to their specific requirements, ultimately optimizing network performance and reliability configuration example configuration example network requirements device a and device b are connected via bgp set the routing policy to be applied when introducing directly connected routes, so that directly connected routes in the 192 168 1 1/24 and 192 168 2 1/24 segments are visible and routes in the 192 168 10 1/24 segment are blocked procedure 1 configuring device a \# configure the interface ip address sonic(config)# interface vlan 100 sonic(config vlanif 100)# ip address 192 168 1 1/24 sonic(config vlanif 100)# exit sonic(config)# interface vlan 200 sonic(config vlanif 200)# ip address 192 168 2 1/24 sonic(config vlanif 200)# exit sonic(config)# interface vlan 300 sonic(config vlanif 300)# ip address 192 168 10 1/24 sonic(config vlanif 300)# exit sonic(config)# interface ethernet 5 sonic(config if 5)# ip address 30 0 0 2/30 \# establishing a bgp connection sonic(config)# router bgp 65001 sonic(config router)# bgp router id 10 1 15 10 sonic(config router)# no bgp ebgp requires policy sonic(config router)# neighbor 30 0 0 1 remote as 65003 sonic(config router)# neighbor 30 0 0 1 bfd sonic(config router)# neighbor 30 0 0 1 description deviceb \# configuring routing policies sonic(config)# ip prefix list test permit 192 168 10 1/24 sonic(config)# route map connect filter deny 30000 sonic(config route map)# match ip address prefix list test \# introduce directly connected routes in bgp neighbors and apply routing policies for filtering sonic(config)# router bgp 65001 sonic(config router)# address family ipv4 unicast sonic(config router af)# redistribute connected sonic(config router af)# redistribute kernel route map connect filter 2 configuring device b \# omit ip address configuration \# establishing a bgp connection sonic(config)# router bgp 65003 sonic(config router)# bgp router id 10 1 15 20 sonic(config router)# no bgp ebgp requires policy sonic(config router)# neighbor 30 0 0 2 remote as 65001 sonic(config router)# neighbor 30 0 0 2 bfd sonic(config router)# neighbor 30 0 0 2 description devicea verify configuration view the routing table on device b sonic# show ip route codes k kernel route, c connected, s static, r rip, o ospf, i is is, b bgp, e eigrp, n nhrp, t table, v vnc, v vnc direct, a babel, d sharp, f pbr, f openfabric, \> selected route, fib route, q queued, r rejected, b backup b> 192 168 1 1/24 \[20/0] via 30 0 0 2, ethernet 5, weight 1, 01 41 43 b> 192 168 2 1/24 \[20/0] via 30 0 0 2, ethernet 5, weight 1, 01 41 43 c> 30 0 0 1/30 is directly connected, ethernet 5, 1d00h59m
