Skip to content
Ask AI

BGP Configuration Guide

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.

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 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.

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 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.

Prerequisite: Configure the interface IP so that the network layer of adjacent nodes is reachable.

Table 1 Overview of BGP Configuration Tasks

Configuration TasksDescriptionRefer to
Basic functionsShutdown BGP sessionOptionalShutdown BGP session
Modify AS numberOptionalModify AS number
Set Router IDOptionalSet Router ID
Configure BGP neighborsOptionalConfigure BGP neighbors
Enable AS-Path RelaxOptionalEnable AS-Path Relax
Enable BFD with BGP LinkageOptionalEnable BFD with BGP Linkage
Disable the binding routing policy switch for EBGP sessionsOptionalDisable the binding routing policy switch for EBGP sessions
Configure peer groupOptionalConfigure peer group
Configure BGP session source addressOptionalConfigure BGP session source address
Announce BGP routeOptionalAnnounce BGP route
Introduce other protocol routesOptionalIntroduce other protocol routes
Configure route reflectorOptionalConfigure route reflector
Configure graceful-restartOptionalConfigure graceful-restart
Configure BGP neighbor passwordOptionalConfigure BGP neighbor password

Table 2 BGP Default Setting

ParameterDefault value
BGPdisable
Keepalive message sending interval60 seconds
Neighbor hold time180 seconds
AS Number65100

Table 3 Shutdown BGP session

PurposeCommandsDescription
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} shutdownSupport shutdown by IP address or host name
Shutdown all BGP sessions.bgp shutdown-

Table 4 Modify AS number

PurposeCommandsDescription
Enter global configuration view.configure terminal-
Set the new AS number.router bgp asn-

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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Configure the Router IDbgp router-id ip_addr-

Table 6 Configure BGP neighbor

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Add BGP neighborneighbor neighbor_ip remote-as asnasn: neighbor AS number

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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Enable AS-Path relaxbgp bestpath as-path multipath-relax [as-set|no-as-set]-

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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
BGP session bind BFDneighbor {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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Disable the binding routing policy switch for EBGP sessionsno bgp ebgp-requires-policyBy 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.

Table 10 Configure peer group

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Create peer groupneighbor peer-group peer-group-
Bind BGP neighbors to peer groupsneighbor {A.B.C.D|A::B|String} peer-group peer-group-

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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Configure BGP session source addressneighbor {A.B.C.D|A::B|String} update-source {A.B.C.D|X:X::X:X|String}-

Table 12 Announce BGP route

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Enter BGP IPv4 address cluster viewaddress-family ipv4 unicast-
Announce IPv4 BGP routenetwork A.B.C.D/M [route-map route_map]-
Enter BGP IPv6 address cluster viewaddress-family ipv6 unicast-
Announce IPv6 BGP routenetwork A::B/M [route-map route_map]-

Table 13

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Enter address cluster viewaddress-family [ipv4|ipv6] unicast-
Introduce connected routeredistribute connected [metric metric_value|route-map route_map]-
Introduce kernel routeredistribute kernel [metric metric_value|route-map route_map]-
Introduce ospf routeredistribute ospf [metric metric_value|route-map route_map]-
Introduce isis routeredistribute isis [metric metric_value|route-map route_map]-

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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Enter address cluster viewaddress-family [ipv4|ipv6] unicast-
Configure route reflectorneighbor [A.B.C.D|A::B] route-reflector-client-

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

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Configure BGP graceful-restartbgp graceful-restart-

Table 16 Configure BGP neighbor password

PurposeCommandsDescription
Enter global configuration viewconfigure terminal-
Enter BGP viewrouter bgp asnasn: local AS number
Configure BGP neighbor passwordneighbor {A.B.C.D|A::B} password password-

Table 17 BGP Configuration Display

PurposeCommandsDescription
Show BGP neighbor detailsshow 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 informationshow 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 informationshow ip bgp summary [established|failed|json]established: display only established BGP neighbors.failed: only failed BGP neighbors are displayed.json: display in json format
  1. 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.
  2. Topology

  1. 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.

  1. 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.