Border Gateway Protocol becomes easier to understand when you separate three ideas: how routers form BGP sessions, how routes move between autonomous systems, and how BGP selects a preferred path. This guide explains these BGP basics for CCNP students through a practical Cisco IOS lab.
Before studying BGP, you should be comfortable with IP routing, subnetting and basic Cisco IOS verification. Students who need that foundation can begin with the CCNA course, while engineers preparing for enterprise-level routing can explore the CCNP Enterprise course.
What Is BGP and Why Is It Used?
BGP is a path-vector routing protocol used to exchange network reachability information between autonomous systems. Unlike an interior gateway protocol such as OSPF, BGP is designed for policy control, Internet-scale routing and selecting paths based on attributes rather than bandwidth alone.
An autonomous system, or AS, is a group of networks managed under a common routing policy. Each public AS uses a registered Autonomous System Number, while private labs commonly use AS numbers from the private ranges, including 64512–65534.
BGP uses TCP port 179. Because TCP provides reliable delivery, BGP does not need to implement its own acknowledgement and retransmission system for routing updates.
Diagram in words
Imagine three enterprise routers arranged from left to right:
LAN-A -- R1 (AS 65001) -- R2 (AS 65002) -- R3 (AS 65002) -- LAN-B
eBGP session iBGP sessionR1 and R2 belong to different autonomous systems, so they use eBGP. R2 and R3 belong to the same autonomous system, so they use iBGP.
What Is the Difference Between eBGP and iBGP?
eBGP exchanges routes between different autonomous systems, while iBGP distributes BGP routes inside the same autonomous system. They use the same BGP protocol but apply different rules to next hops, AS paths, session design and route advertisement.
| Feature | eBGP | iBGP |
|---|---|---|
| Peer autonomous system | Different AS | Same AS |
| Common purpose | Exchange routes between organisations or providers | Carry external routes through one AS |
| Default Cisco administrative distance | 20 | 200 |
| AS_PATH update | Adds the local AS when advertising | Does not add the local AS |
| Default next-hop behaviour | Changes next hop when advertising | Usually preserves the existing next hop |
| Default peer reachability | Commonly directly connected | Can use loopbacks and multihop IP reachability |
| Advertisement rule | Can advertise eligible routes to other peers | Does not advertise an iBGP-learned route to another iBGP peer |
Administrative distance is used when the router compares routes learned from different routing sources for installation in the routing table. It is not a BGP attribute and does not decide which of several BGP paths becomes the BGP best path.
Why does iBGP need a full mesh?
An iBGP router does not advertise a route learned from one iBGP neighbor to another iBGP neighbor. This loop-prevention rule means that a traditional iBGP design requires every BGP router in the AS to peer with every other BGP router.
A full mesh becomes difficult to maintain as the number of routers grows. Larger networks therefore use route reflectors or, less commonly, BGP confederations to reduce the number of sessions.
How Does a BGP Neighbor Session Form?
Two BGP routers must have IP connectivity, matching neighbor definitions and compatible AS settings before they can exchange routes. The routers then move through the BGP finite-state machine until the session reaches the Established state.
| State | Meaning |
|---|---|
| Idle | BGP is waiting to start or has encountered a configuration problem |
| Connect | The router is waiting for the TCP connection to complete |
| Active | The TCP connection failed and BGP is trying again |
| OpenSent | A BGP OPEN message has been sent |
| OpenConfirm | The router is waiting for a KEEPALIVE message |
| Established | The peers can exchange BGP routes |
The Active state does not mean that the session is working. A neighbor repeatedly moving between Idle, Connect and Active usually indicates an IP reachability, TCP port 179, source address or AS number problem.
Which BGP Attributes Should CCNP Students Know?
BGP attributes describe characteristics of a route and allow administrators to implement routing policy. The most important attributes for CCNP-level study are WEIGHT, LOCAL_PREF, AS_PATH, ORIGIN, MED and NEXT_HOP.
| Attribute | Scope and purpose | Preferred value |
|---|---|---|
| WEIGHT | Cisco-specific value local to one router; not advertised | Highest |
| LOCAL_PREF | Shared within an AS; selects the preferred outbound exit | Highest |
| AS_PATH | Lists autonomous systems crossed by the route | Shortest |
| ORIGIN | Shows how the prefix entered BGP: IGP, EGP or incomplete | IGP over EGP over incomplete |
| MED | Suggests a preferred entry point into an AS | Lowest |
| NEXT_HOP | Identifies the next-hop address used to reach the prefix | Must be reachable |
| COMMUNITY | Tag attached to routes for policy decisions | Depends on policy |
WEIGHT and LOCAL_PREF
WEIGHT affects only the Cisco router on which it is configured. LOCAL_PREF is normally the better choice when every BGP router in an AS should prefer the same outbound path.
For example, an enterprise with two Internet connections can assign LOCAL_PREF 200 to routes received from the primary provider and leave the secondary routes at the default value of 100.
AS_PATH
Each eBGP router adds its AS number to the AS_PATH before advertising a route. BGP uses the path to help prevent loops: if a router receives a route containing its own AS number, it normally rejects that route.
AS-path prepending deliberately repeats an AS number to make a path appear longer. It can influence how remote networks enter your AS, but it is only a signal; remote administrators may apply policies that override AS_PATH length.
NEXT_HOP
A valid BGP path is not usable unless its next hop can be resolved through the routing table. This is a frequent iBGP troubleshooting issue because an iBGP advertisement normally preserves the next hop learned from eBGP.
The next-hop-self command tells an iBGP router to advertise itself as the next hop. Internal routers must then have an IGP or static route to that router's peering address, commonly a loopback.
MED
The Multi-Exit Discriminator suggests which link a neighboring AS should use to enter your network. Lower values are preferred, and MEDs are normally compared only for paths received from the same neighboring AS unless the BGP configuration changes that behaviour.
How Does BGP Select the Best Path?
BGP evaluates attributes in a defined order until one path is preferred over the alternatives. On Cisco IOS and IOS XE, students should understand the main decision points while remembering that software features and explicit best-path commands can modify the process.
A practical simplified Cisco selection order is:
- Prefer the path with the highest WEIGHT.
- Prefer the path with the highest LOCAL_PREF.
- Prefer a path originated locally by the router.
- Prefer the shortest AS_PATH.
- Prefer the lowest ORIGIN type: IGP, then EGP, then incomplete.
- Prefer the lowest MED when the paths are eligible for MED comparison.
- Prefer an eBGP path over an iBGP path.
- Prefer the path with the lowest IGP metric to the BGP next hop.
- Apply later tie-breakers, such as path age, router ID and neighbor address.
The exact decision should be checked on the platform being used. Commands such as show ip bgp <prefix> reveal the available paths, selected best path and relevant attributes.
Worked path-selection example
Suppose R3 learns 203.0.113.0/24 through two edge routers:
| Path | LOCAL_PREF | AS_PATH | MED |
|---|---|---|---|
| Edge A | 200 | 65100 65200 | 100 |
| Edge B | 100 | 65300 | 0 |
Edge A wins even though it has a longer AS_PATH and higher MED. LOCAL_PREF is evaluated before AS_PATH and MED, so BGP stops at that decision point.
If both paths had LOCAL_PREF 100, Edge B would win because its AS_PATH is shorter. MED would not be reached as a deciding step.
How Do You Configure an eBGP and iBGP Lab?
The following lab creates an eBGP session between R1 and R2 and an iBGP session between R2 and R3. Loopbacks are used for iBGP because they remain available as long as the router has a working path to the loopback address.
Addressing plan
| Router | Interface or network | Address | AS |
|---|---|---|---|
| R1 | Link to R2 | 10.0.12.1/30 | 65001 |
| R1 | Advertised LAN | 172.16.10.0/24 | 65001 |
| R2 | Link to R1 | 10.0.12.2/30 | 65002 |
| R2 | Link to R3 | 10.0.23.2/30 | 65002 |
| R2 | Loopback0 | 2.2.2.2/32 | 65002 |
| R3 | Link to R2 | 10.0.23.3/30 | 65002 |
| R3 | Loopback0 | 3.3.3.3/32 | 65002 |
| R3 | Advertised LAN | 192.168.30.0/24 | 65002 |
R1 configuration
interface GigabitEthernet0/0
ip address 10.0.12.1 255.255.255.252
no shutdown
!
interface Loopback10
ip address 172.16.10.1 255.255.255.0
!
router bgp 65001
neighbor 10.0.12.2 remote-as 65002
network 172.16.10.0 mask 255.255.255.0The BGP network command does not create a route. An exact route for 172.16.10.0/24 must already exist in the routing table, which it does here because Loopback10 is directly connected.
R2 configuration
interface GigabitEthernet0/0
ip address 10.0.12.2 255.255.255.252
no shutdown
!
interface GigabitEthernet0/1
ip address 10.0.23.2 255.255.255.252
no shutdown
!
interface Loopback0
ip address 2.2.2.2 255.255.255.255
!
ip route 3.3.3.3 255.255.255.255 10.0.23.3
!
router bgp 65002
neighbor 10.0.12.1 remote-as 65001
neighbor 3.3.3.3 remote-as 65002
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-selfR3 configuration
interface GigabitEthernet0/1
ip address 10.0.23.3 255.255.255.252
no shutdown
!
interface Loopback0
ip address 3.3.3.3 255.255.255.255
!
interface Loopback30
ip address 192.168.30.1 255.255.255.0
!
ip route 2.2.2.2 255.255.255.255 10.0.23.2
!
router bgp 65002
neighbor 2.2.2.2 remote-as 65002
neighbor 2.2.2.2 update-source Loopback0
network 192.168.30.0 mask 255.255.255.0In production, an IGP such as OSPF would normally provide loopback and next-hop reachability inside AS 65002. Static routes keep this small lab focused on BGP behaviour.
How Do You Verify the BGP Routes?
Start with the session summary, then inspect individual prefixes and confirm next-hop reachability. A session can be Established while a route is still missing because of an incorrect network statement, route policy or unreachable next hop.
R3# show ip bgp summary
BGP router identifier 3.3.3.3, local AS number 65002
Neighbor V AS MsgRcvd MsgSent Up/Down State/PfxRcd
2.2.2.2 4 65002 28 30 00:18:42 1A number in the final column means the session is Established and shows the number of received prefixes. Text such as Idle or Active indicates that the session is not established.
R3 should learn R1's LAN through iBGP:
R3# show ip bgp 172.16.10.0
BGP routing table entry for 172.16.10.0/24
Paths: (1 available, best #1)
65001
2.2.2.2 from 2.2.2.2
Origin IGP, localpref 100, valid, internal, bestThe AS_PATH contains 65001, the route is marked internal because it came through iBGP, and the next hop is R2's loopback because R2 used next-hop-self.
Use these additional checks:
show ip bgp
show ip bgp neighbors
show ip route 2.2.2.2
show ip route bgp
show ip bgp 172.16.10.0
ping 2.2.2.2 source 3.3.3.3How Do You Troubleshoot Common BGP Problems?
Troubleshoot BGP from the bottom up: verify interfaces and IP routing, test TCP reachability, check neighbor parameters, and then inspect route attributes and policies. Avoid changing attributes before confirming that the peer session and next hop are working.
1. The neighbor remains Active
Check basic reachability and the configured AS numbers:
show ip interface brief
show ip bgp summary
show running-config | section router bgp
ping 10.0.12.2
show access-listsConfirm that an ACL or firewall is not blocking TCP port 179. For loopback-based peering, test with the correct source address and verify update-source Loopback0 on both routers.
2. The session is Established but no prefixes arrive
Verify that the advertised prefix exists exactly in the local routing table:
show ip route 172.16.10.0 255.255.255.0
show ip bgp neighbors 10.0.12.2 advertised-routes
show ip bgp neighbors 10.0.12.2 received-routesAlso inspect prefix lists, route maps and address-family activation. Some Cisco configurations use explicit address-family mode, where the neighbor must be activated under address-family ipv4 unicast.
3. The prefix appears in BGP but not in the routing table
Check whether the BGP next hop is reachable and whether another route source has a more preferred route:
show ip bgp 172.16.10.0
show ip route 2.2.2.2
show ip route 172.16.10.0
show ip bgp rib-failureThe show ip bgp rib-failure command is available on many Cisco IOS and IOS XE platforms and can explain why a BGP best path was not installed in the routing table.
4. An iBGP router does not pass a route to another iBGP router
This is expected behaviour under the iBGP advertisement rule. Build a full mesh for a small network or configure a route reflector for a scalable design; do not try to solve the issue by randomly redistributing BGP routes.
5. The wrong exit path is selected
Display every path and compare attributes in selection order:
show ip bgp 203.0.113.0
show ip bgp neighbors 203.0.113.1 routes
show route-map
show ip prefix-listUse LOCAL_PREF to control the preferred exit for the complete AS. Use WEIGHT only when the decision should apply to one Cisco router, and document any MED or AS-path-prepending policy.
What Should You Remember About BGP Basics?
BGP forms TCP-based neighbor relationships and uses attributes to apply routing policy. eBGP exchanges routes between autonomous systems, while iBGP distributes those routes internally without advertising an iBGP-learned route to another iBGP peer by default.
Key points are:
- Verify IP reachability before troubleshooting BGP policy.
- Remember that the
networkcommand requires an exact route in the routing table. - Make the BGP next hop reachable through an IGP or static route.
- Use
next-hop-selfwhere an edge next hop should be changed for internal peers. - Read path attributes in the same order used by the best-path process.
- Use route reflectors when a full iBGP mesh is not practical.
- Apply prefix filtering and routing policy deliberately rather than accepting or advertising every route by default.
To practise BGP, route policies, OSPF, troubleshooting and enterprise network design in guided labs, enquire about schedules and batch details for the CCNP Enterprise course.
Reviewed by Network Rhinos networking trainers.
Related reading: MPLS Explained: Labels, LSPs and Service Provider Use
