BGP Configuration Guide
Introduction
Section titled “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
Section titled “Basic Concepts”Autonomous Systems
Section titled “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
Section titled “BGP Classification”BGP is divided into EBGP (External/Exterior BGP) and IBGP (Internal/Interior BGP) according to the mode of operation.
- 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 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
Section titled “Roles in BGP Packet Interaction”There are two roles in BGP packet interaction, Speaker and Peer.
- 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: Speaker who exchange packets with each other are called peers. A number of related peers can form a Peer Group.
Router ID
Section titled “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
Section titled “BGP Configuration”Prerequisite: Configure the interface IP so that the network layer of adjacent nodes is reachable.
Table 1 Overview of BGP Configuration Tasks
| Configuration Tasks | Description | Refer to | |
|---|---|---|---|
| Basic functions | Shutdown BGP session | Optional | Shutdown BGP session |
| Modify AS number | Optional | Modify AS number | |
| Set Router ID | Optional | Set Router ID | |
| Configure BGP neighbors | Optional | Configure BGP neighbors | |
| Enable AS-Path Relax | Optional | Enable AS-Path Relax | |
| Enable BFD with BGP Linkage | Optional | Enable BFD with BGP Linkage | |
| Disable the binding routing policy switch for EBGP sessions | Optional | Disable the binding routing policy switch for EBGP sessions | |
| Configure peer group | Optional | Configure peer group | |
| Configure BGP session source address | Optional | Configure BGP session source address | |
| Announce BGP route | Optional | Announce BGP route | |
| Introduce other protocol routes | Optional | Introduce other protocol routes | |
| Configure route reflector | Optional | Configure route reflector | |
| Configure graceful-restart | Optional | Configure graceful-restart | |
| Configure BGP neighbor password | Optional | Configure BGP neighbor password |
BGP Default Setting
Section titled “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
Section titled “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
Section titled “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
Section titled “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
| 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
Section titled “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
Section titled “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 closed, only one of these routes will be selected for distribution.
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
Section titled “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
| 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
Section titled “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
| 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
Section titled “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
Section titled “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
| 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
Section titled “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
Section titled “Introduce other protocol routes”Table 13
| 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
Section titled “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
| 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
Section titled “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
| 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
Section titled “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
Section titled “Display and Maintenance”BGP Configuration Display
Section titled “BGP Configuration Display”Table 17 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
Section titled “Typical Configuration Example”EBGP Configuration Scenarios
Section titled “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 terminalsonic(config)# interface ethernet 0/15sonic(config-if-0/15)# ip address 10.0.0.1/24sonic# configure terminalsonic(config)# interface ethernet 0/14sonic(config-if-0/14)# ip address 20.0.0.1/24sonic# configure terminalsonic(config)# interface loopback 0sonic(config-loif-0)# ip address 10.1.0.221/32sonic(config-route-map)# exitsonic(config)# router bgp 65001sonic(config-router)# bgp router-id 10.1.0.221sonic(config-router)# no bgp ebgp-requires-policysonic(config-router)# neighbor 20.0.0.2 remote-as 65002sonic(config-router)# address-family ipv4sonic(config-router-af)# redistribute connectedSwitchB
sonic# configure terminalsonic(config)# interface ethernet 0/14sonic(config-if-0/14)# ip address 20.0.0.2/24sonic# configure terminalsonic(config)# interface ethernet 0/13sonic(config-if-0/13)# ip address 30.0.0.2/24sonic# configure terminalsonic(config)# interface loopback 0sonic(config-loif-0)# ip address 10.1.0.222/32sonic(config-route-map)# exitsonic(config)# router bgp 65002sonic(config-router)# bgp router-id 10.1.0.222sonic(config-router)# no bgp ebgp-requires-policysonic(config-router)# neighbor 20.0.0.1 remote-as 65001sonic(config-router)# neighbor 30.0.0.1 remote-as 65003sonic(config-router)# address-family ipv4sonic(config-router-af)# redistribute connectedSwitchC
sonic# configure terminalsonic(config)# interface ethernet 0/15sonic(config-if-0/15)# ip address 40.0.0.1/24sonic# configure terminalsonic(config)# interface ethernet 0/13sonic(config-if-0/13)# ip address 30.0.0.1/24sonic# configure terminalsonic(config)# interface loopback 0sonic(config-loif-0)# ip address 10.1.0.223/32sonic(config-route-map)# exitsonic(config)# router bgp 65003sonic(config-router)# bgp router-id 10.1.0.223sonic(config-router)# no bgp ebgp-requires-policysonic(config-router)# neighbor 30.0.0.2 remote-as 65002sonic(config-router)# address-family ipv4sonic(config-router-af)# redistribute connectedPC
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 summaryVerify connectivity using the ping command. PC0 and PC1 can ping each other.