BGP (Border Gateway Protocol)
Objective
This document explains how to configure Border Gateway Protocol (BGP) on [device or platform name]. BGP is the protocol that enables the global routing system by exchanging routing information between autonomous systems (AS), ensuring reliable path selection, policy control, and inter-domain routing on the internet.
Prerequisites
Hardware:
Switches or routers that support VLANs
(e.g., edgecore, ufispace)
Software:
Network operating systems that support VLAN configuration
(e.g., SONiC-OS-4.4.0-Enterprise_Base, SONiC-OS-4.4.2-Enterprise_Base)
Access:
Administrative or privileged CLI access
Network:
Established IP connectivity between BGP neighbors.
Public or private AS numbers, IP addresses for peerings, and agreed routing policies.
Topology Diagram
Example:
Two routers configured as BGP neighbors exchanging route information.
Basic Configuration Steps
1. Define Local and Remote AS
Identify your local Autonomous System (AS) number and the AS number of your BGP neighbor.
Syntax:
sonic# configure terminal
sonic(config)# router bgp <as_number>
sonic(config-router-bgp)# router-id <router_id>
Example:
sonic(config)# router bgp 65100
sonic(config-router-bgp)# router-id 11.11.11.11
2. Configure BGP Neighbors
Set up BGP neighbor relationships by specifying the neighbor’s IP address and remote AS.
Syntax:
sonic# configure terminal
sonic(config-router-bgp)# neighbor <neighbor_ip>
sonic(config-router-bgp-neighbor)# remote-as <neighbor_as>
sonic(config-router-bgp-neighbor)# address-family <afisafi>
sonic(config-router-bgp-neighbor-af)# activate
Example:
sonic(config-router-bgp)# neighbor 10.0.0.1
sonic(config-router-bgp-neighbor)# remote-as 65200
sonic(config-router-bgp-neighbor)# address-family ipv4 unicast
sonic(config-router-bgp-neighbor-af)# activate
3. Advertise Networks
Specify which local networks you want to advertise into the BGP table.
Syntax:
sonic# configure terminal
sonic(config)# router bgp <as_number>
sonic(config-router-bgp)# address-family ipv4 unicast
sonic(config-router-bgp-af)# network <local_network>
Example:
sonic# configure terminal
sonic(config)# router bgp 65100
sonic(config-router-bgp)# address-family ipv4 unicast
sonic(config-router-bgp-af)# network 11.11.11.11/32
4. Apply BGP Policies (Optional)
Configure route-maps, prefix-lists, or filters to control route advertisement and acceptance.
Syntax:
sonic# configure terminal
sonic(config)# ip prefix-list <NAME> seq <nummber> <action> <network>
sonic(config)# route-map <NAME> <action> <seq>
sonic(config-route-map)# match ip address prefix-list <ip_prefixlist>
sonic(config-route-map)# exit
sonic(config)# router bgp <as_number>
sonic(config-router-bgp)# neighbor <ip>
sonic(config-router-bgp-neighbor)# address-family <afi_safi>
sonic(config-router-bgp-neighbor-af)# route-map <NAME> <in/out>
Example:
sonic# configure terminal
sonic(config)# ip prefix-list ALLOW seq 10 permit 192.168.1.1/24
sonic(config)# route-map ALLOW_LOCAL_NET permit 10
sonic(config-route-map)# match ip address prefix-list ALLOW
sonic(config-route-map)# exit
sonic(config)# router bgp 65100
sonic(config-router-bgp)# neighbor 10.0.0.1
sonic(config-router-bgp-neighbor)# address-family ipv4 unicast
sonic(config-router-bgp-neighbor-af)# route-map ALLOW_LOCAL_NET in
Example Configuration (DUT_1 and DUT_2)
DUT_1
configure terminal
ip prefix-list ALLOW seq 10 permit 192.168.1.1/24
! route-map ALLOW_LOCAL_NET permit 10
match ip address prefix-list ALLOW
! router bgp 65100
router-id 11.11.11.11
log-neighbor-changes
timers 60 180
!
address-family ipv4 unicast
maximum-paths 1
maximum-paths ibgp 1
network 11.11.11.11/32
!
neighbor 10.0.0.1
remote-as 65200
!
address-family ipv4 unicast
activate
route-map ALLOW_LOCAL_NET in
DUT_2
configure terminal
ip prefix-list ALLOW seq 10 permit 192.168.1.1/24
! route-map ALLOW_LOCAL_NET permit 10
match ip address prefix-list ALLOW
! router bgp 65200
router-id 22.22.22.22
log-neighbor-changes
timers 60 180
!
address-family ipv4 unicast
maximum-paths 1
maximum-paths ibgp 1
network 22.22.22.22/32
!
neighbor 10.0.0.2
remote-as 65100
!
address-family ipv4 unicast
activate
route-map ALLOW_LOCAL_NET in
Verification
show bgp summary #shows bgp neighbors
show bgp ipv4 unicast summary #show bgp neighbor status
Troubleshooting Tips
Ensure AS numbers and neighbor IPs are correct.
Check if TCP port 179 is reachable between peers.
Review BGP timers and capabilities (e.g., multi-hop if needed).
Use debug bgp or logs to trace session establishment issues.