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 true 78,172 22637362637363,99 56790843870958,256 2057179349168 left #4283c7 2 1 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left 1 14 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type bgp default setting bgp default setting table 2 bgp default setting table 2 bgp default setting true 323,283 left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type shutdown bgp session shutdown bgp session table 3 shutdown bgp session table 3 shutdown bgp session true 233,177 94649165302351,195 05350834697649 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type modify as number modify as number table 4 modify as number table 4 modify as number true 265,178 22804532577902,162 77195467422098 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type 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 true 250,181,175 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure bgp neighbor configure bgp neighbor table 6 configure bgp neighbor table 6 configure bgp neighbor true 250,183,173 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type 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 true 159,269 58663366336634,177 41336633663366 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type 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 true 250,178,178 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type 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 true 170,132 6082949308756,303 39170506912444 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure peer group configure peer group table 10 configure peer group table 10 configure peer group true 167,259 26338028169016,179 73661971830984 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type 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 true 183,236 0217391304348,186 9782608695652 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type announce bgp route announce bgp route table 12 announce bgp route table 12 announce bgp route true 229,210 89603960396042,166 10396039603958 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type introduce other protocol routes introduce other protocol routes table 13 table 13 introduce introduce other protocol routes true 169,276 5698198198198,160 43018018018017 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type 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 true 239,183 5,183 5 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type 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 true 254,176,176 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type configure bgp neighbor password configure bgp neighbor password table 16 configure bgp neighbor password table 16 configure bgp neighbor password true 232,187,187 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type display and maintenance display and maintenance bgp configuration display bgp configuration display table 1 bgp configuration display table 1 bgp configuration display true 113,139 24427480916032,353 7557251908397 left #4283c7 unhandled content type left #4283c7 unhandled content type left #4283c7 unhandled content type left unhandled content type left unhandled content type left unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left #d8e5f5 unhandled content type left unhandled content type left unhandled content type left unhandled content type 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
