How to Configure BGP (Border Gateway Protocol)

How to Configure BGP (Border Gateway Protocol)

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 

Picture 
 

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. 

 

 

 

 

    • Related Articles

    • How to configure BGP

      BGP (Border Gateway Protocol) Objective BGP (Border Gateway Protocol) is the protocol that enables the global routing system of the internet. It manages how packets get routed from network to network by exchanging routing and reachability information ...
    • How to Configure eBGP and iBGP with Peer-Groups

      BGP (Border Gateway Protocol) with peer-group configurations Objective This document explains how to configure eBGP (External BGP) and iBGP (Internal BGP) using peer-groups on routers. Peer-groups help simplify BGP configuration by grouping neighbors ...
    • How to configure subinterface

      Sub-Interface: Sub interfaces divide the parent interface into two or more virtual interfaces on which you can assign unique Layer 3 parameters such as IP addresses and dynamic routing protocols. The IP address for each sub interface should be in a ...
    • How to Configure Basic VRF Management

      VRF Management Objective This document explains how to configure Basic VRF (Virtual Routing and Forwarding) Management on SONiC-OS-4.4.2-Enterprise_Base. Management VRF provides a separate routing table specifically for out-of-band management ...
    • How to Configure ACL (Access Control List)

      ACL (Access Control List) Objective This document explains how to configure Access Control Lists (ACLs) on broadcom sonic. ACLs consist of one or more access control entries (ACEs) that define rules to permit or deny network traffic based on ...