Configuration Guide
BGP Configuration Guide
28 min
introduction introduction bgp (border gateway protocol) is a distance vector routing protocol that enables route reachability between as (autonomous system) and selects the best route to facilitate the management of the growing network, the network is divided into different autonomous systems in 1982, the exterior gateway protocol (egp) was used to dynamically exchange routing information between as however, egp was designed to be simple, publishing only the routing information that the network could reach, but not optimizing the routes and not taking into account issues such as loop avoidance, which soon became inadequate for the needs of network management this led to the emergence of bgp, which can perform route preference, avoid routing loops, deliver routes more efficiently and maintain large amounts of routing information although bgp is used to pass routing information between as, it is not always necessary to use bgp, for example, on the data center's uplink internet, to avoid the impact of internet mass routing on the data centr's internal network, the switch uses static routes instead of bgp to communicate with the external network basic concepts basic concepts autonomous systems autonomous systems as is an ip network with the same routing policy under the jurisdiction of a single entity each as in a bgp network is assigned a unique as number, which is used to distinguish between different as as numbers are divided into 2 byte as numbers and 4 byte as numbers, with 2 byte as numbers ranging from 1 to 65535 and 4 byte as numbers ranging from 1 to 4294967295 devices that support 4 byte as numbers are compatible with devices that support 2 byte as numbers bgp classification bgp classification bgp is divided into ebgp (external/exterior bgp) and ibgp (internal/interior bgp) according to the mode of operation ibgp ibgp bgp running inside the same as is called ibgp, and to prevent loops within the as, bgp devices do not advertise routes learned from ibgp peers to other ibgp peers, and establish full connectivity with all ibgp peers when deploying ibgp, rr (route reflector) can be introduced to simplify fully connected configuration all leafs establish bgp peer relationships only with the rr, which discovers and receives bgp connections initiated by vteps, forms a client list, and reflects routes received from a vtep to all other vteps; the rr can be deployed in spine, leaf, or standalone device ebgp ebgp bgp running between different as is called ebgp, and to prevent loops between as, when a bgp device receives routes from an ebgp peer, it discards the route with the local as number when deploying ebgp, no rr is required bgp automatically sends evpn packets received from ebgp neighbors to other ebgp and ibgp neighbors, where spine is equivalent to the rr function in general, the asn of each device in the network is different, so ebgp is mostly used in sonic if a redundant leaf is used, the pair of leafs has the same asn and ibgp is used roles in bgp packet interaction roles in bgp packet interaction there are two roles in bgp packet interaction, speaker and peer speaker speaker the switch that sends bgp packets is called a bgp speaker, which receives or generates new packet information and advertises it to other bgp speakers peer peer speaker who exchange packets with each other are called peers a number of related peers can form a peer group router id router id router id is a 32 bit value used to identify a bgp device, usually in the form of ipv4 address, carried in the open packet sent when a bgp session is established when establishing a bgp session between peers, each bgp device must have a unique router id, otherwise no bgp connection can be established between peers bgp configuration bgp configuration prerequisite configure the interface ip so that the network layer of adjacent nodes is reachable table 1 overview of bgp configuration tasks table 1 overview of bgp configuration tasks configuration tasks description refer to basic functions shutdown bgp session optional docid\ fgmmmd8k4gts2hhjo43 u modify as number optional docid\ fgmmmd8k4gts2hhjo43 u set router id optional docid\ fgmmmd8k4gts2hhjo43 u configure bgp neighbors optional docid\ fgmmmd8k4gts2hhjo43 u enable as path relax optional docid\ fgmmmd8k4gts2hhjo43 u enable bfd with bgp linkage optional docid\ fgmmmd8k4gts2hhjo43 u disable the binding routing policy switch for ebgp sessions optional docid\ fgmmmd8k4gts2hhjo43 u configure peer group optional docid\ fgmmmd8k4gts2hhjo43 u configure bgp session source address optional docid\ fgmmmd8k4gts2hhjo43 u announce bgp route optional docid\ fgmmmd8k4gts2hhjo43 u introduce other protocol routes optional docid\ fgmmmd8k4gts2hhjo43 u configure route reflector optional docid\ fgmmmd8k4gts2hhjo43 u configure graceful restart optional docid\ fgmmmd8k4gts2hhjo43 u configure bgp neighbor password optional docid\ fgmmmd8k4gts2hhjo43 u bgp default setting bgp default setting table 2 bgp default setting table 2 bgp default setting parameter default value bgp disable keepalive message sending interval 60 seconds neighbor hold time 180 seconds as number 65100 shutdown bgp session shutdown bgp session table 3 shutdown bgp session table 3 shutdown bgp session purpose commands description enter global configuration view configure terminal enter bgp config view router bgp asn \[ vrf vrf name ] asn local as number shutdown the bgp session of the specified neighbor neighbor { ipaddr | hostname } shutdown support shutdown by ip address or host name shutdown all bgp sessions bgp shutdown modify as number modify as number table 4 modify as number table 4 modify as number purpose commands description enter global configuration view configure terminal set the new as number router bgp asn set router id set router id the router id uniquely identifies a device within the entire autonomous system default use loopback 0 ip as router id table 5 set router id table 5 set router id purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number configure the router id bgp router id ip addr configure bgp neighbor configure bgp neighbor table 6 configure bgp neighbor table 6 configure bgp neighbor purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number add bgp neighbor neighbor neighbor ip remote as asn asn neighbor as number enable as path relax enable as path relax as path relax is a routing level switch that determines the treatment of the same route from different as domains when the switch is on, the next hop of the same route from different as domains will be an ecmp group when the switch is on, the next hop of the same route from different as domains will be an ecmp group when the switch is closed, only one of these routes will be selected for distribution when the switch is closed, only one of these routes will be selected for distribution table 7 enable as path relax table 7 enable as path relax purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number enable as path relax bgp bestpath as path multipath relax \[ as set | no as set ] enable bfd with bgp linkage enable bfd with bgp linkage configuring bgp and bfd (bidirectional forwarding detection) linkage is a key means to improve network convergence speed and reliability when bfd detects a link failure, it can immediately notify bgp to interrupt neighbor relationships and recalculate routes, accelerate route convergence, reduce business interruption time, and have high requirements for network fault perception in environments with unstable link quality, it is recommended to configure bgp and bfd linkage table 8 enable bfd with bgp linkage table 8 enable bfd with bgp linkage purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number bgp session bind bfd neighbor { ipaddr | hostname } bfd disable the binding routing policy switch for ebgp sessions disable the binding routing policy switch for ebgp sessions when configuring an ebgp session, if no routing policy is bound, this switch needs to be turned off table 9 disable the binding routing policy switch for ebgp sessions table 9 disable the binding routing policy switch for ebgp sessions purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number disable the binding routing policy switch for ebgp sessions no bgp ebgp requires policy by default, it is required that there must be a routing policy applied to the ebgp session, and if not, no routing will be accepted or announced configure peer group configure peer group table 10 configure peer group table 10 configure peer group purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number create peer group neighbor peer group peer group bind bgp neighbors to peer groups neighbor { a b c d | a b | string } peer group peer group configure bgp session source address configure bgp session source address when using the loopback interface ip to establish bgp neighbors, it is necessary to specify the bgp session source address table 11 configure bgp session source address table 11 configure bgp session source address purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number configure bgp session source address neighbor { a b c d | a b | string } update source { a b c d | x\ x x x | string } announce bgp route announce bgp route table 12 announce bgp route table 12 announce bgp route purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number enter bgp ipv4 address cluster view address family ipv4 unicast announce ipv4 bgp route network a b c d/m \[ route map route map ] enter bgp ipv6 address cluster view address family ipv6 unicast announce ipv6 bgp route network a b/m \[ route map route map ] introduce other protocol routes introduce other protocol routes table 13 table 13 introduce introduce other protocol routes purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number enter address cluster view address family \[ ipv4|ipv6 ] unicast introduce connected route redistribute connected \[ metric metric value | route map route map ] introduce kernel route redistribute kernel \[ metric metric value | route map route map ] introduce ospf route redistribute ospf \[ metric metric value | route map route map ] introduce isis route redistribute isis \[ metric metric value | route map route map ] configure route reflector configure route reflector in bgp networks, route reflector (rr) is a technique used to simplify ibgp interconnection topology configuring bgp route reflector can simplify the connections between ibgp network devices and reduce the number of ibgp sessions when all devices in the ibgp network need to establish bgp sessions and exchange routing information, a routing reflector is configured so that all devices only establish ibgp neighbors with devices that have configured routing reflectors their respective routing information is published to other devices through the routing reflector, reducing the number of sessions per device and improving network manageability table 14 configure route reflector table 14 configure route reflector purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number enter address cluster view address family \[ ipv4|ipv6 ] unicast configure route reflector neighbor \[ a b c d | a b ] route reflector client configure graceful restart configure graceful restart when the device encounters a bgp container or bgp process restart, in order to maintain uninterrupted traffic forwarding in the data plane, the graceful restart function can be configured to prevent route information from being revoked during the bgp restart phase, thereby avoiding route oscillation and traffic interruption table 15 configure bgp graceful restart table 15 configure bgp graceful restart purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number configure bgp graceful restart bgp graceful restart configure bgp neighbor password configure bgp neighbor password table 16 configure bgp neighbor password table 16 configure bgp neighbor password purpose commands description enter global configuration view configure terminal enter bgp view router bgp asn asn local as number configure bgp neighbor password neighbor { a b c d|a b } password password display and maintenance display and maintenance bgp configuration display bgp configuration display table 1 bgp configuration display table 1 bgp configuration display purpose commands description show bgp neighbor details show ip bgp neighbors { ipaddr | hostname } \[option] ipaddr neighbor ip address hostname the name of the neighbor the options for option are as follows routes display routes learned from neighbors advertised routes show the routes advertised to neighbors received routes show routes received from neighbors prefix counts display detailed prefix count information filtered routes display the filtered routes received from neighbors bestpath routes show the routes selected by best path received shows the information received from the neighbor flap statistics display flap statistics for routes learned from neighbors dampened routes show the fading routes received from neighbors json show in json format display bgp neighbor network information show ip bgp \[ a b c d/m | a b c d ] a b c d/m ipv4 prefix a b c d routes in the bgp routing table display bgp neighbor summary information show ip bgp summary \[ established | failed | json ] established display only established bgp neighbors failed only failed bgp neighbors are displayed json display in json format typical configuration example typical configuration example ebgp configuration scenarios ebgp configuration scenarios networking requirements hosts on different network segments are connected via three switches, all running the bgp protocol it is required to configure ebgp neighbors so that pc1 hanging under switchc and pc0 hanging under switcha can interoperate topology configuration roadmap first check that the status of each interface is up and that the wiring is correct configure the ip address of each interface and the loopback0 ip configure the as number the configuration takes effect after saving and rebooting use the ip address of the direct connection port to establish an ebgp neighbor switcha sonic# configure terminal sonic(config)# interface ethernet 0/15 sonic(config if 0/15)# ip address 10 0 0 1/24 sonic# configure terminal sonic(config)# interface ethernet 0/14 sonic(config if 0/14)# ip address 20 0 0 1/24 sonic# configure terminal sonic(config)# interface loopback 0 sonic(config loif 0)# ip address 10 1 0 221/32 sonic(config route map)# exit sonic(config)# router bgp 65001 sonic(config router)# bgp router id 10 1 0 221 sonic(config router)# no bgp ebgp requires policy sonic(config router)# neighbor 20 0 0 2 remote as 65002 sonic(config router)# address family ipv4 sonic(config router af)# redistribute connected switchb sonic# configure terminal sonic(config)# interface ethernet 0/14 sonic(config if 0/14)# ip address 20 0 0 2/24 sonic# configure terminal sonic(config)# interface ethernet 0/13 sonic(config if 0/13)# ip address 30 0 0 2/24 sonic# configure terminal sonic(config)# interface loopback 0 sonic(config loif 0)# ip address 10 1 0 222/32 sonic(config route map)# exit sonic(config)# router bgp 65002 sonic(config router)# bgp router id 10 1 0 222 sonic(config router)# no bgp ebgp requires policy sonic(config router)# neighbor 20 0 0 1 remote as 65001 sonic(config router)# neighbor 30 0 0 1 remote as 65003 sonic(config router)# address family ipv4 sonic(config router af)# redistribute connected switchc sonic# configure terminal sonic(config)# interface ethernet 0/15 sonic(config if 0/15)# ip address 40 0 0 1/24 sonic# configure terminal sonic(config)# interface ethernet 0/13 sonic(config if 0/13)# ip address 30 0 0 1/24 sonic# configure terminal sonic(config)# interface loopback 0 sonic(config loif 0)# ip address 10 1 0 223/32 sonic(config route map)# exit sonic(config)# router bgp 65003 sonic(config router)# bgp router id 10 1 0 223 sonic(config router)# no bgp ebgp requires policy sonic(config router)# neighbor 30 0 0 2 remote as 65002 sonic(config router)# address family ipv4 sonic(config router af)# redistribute connected pc separate routes are configured on the two pcs, with the destination segment being the ip of the other pc and the next hop being the ip of the opposite end verify the configuration check if the bgp connection is established successfully sonic# show ip bgp summary verify connectivity using the ping command pc0 and pc1 can ping each other
