What Is BGP? How the Border Gateway Protocol Works
BGP (Border Gateway Protocol) exchanges IP reachability information between routers and selects routes according to policy. It connects autonomous systems across the internet and distributes external routes within a network. Its decisions depend on route attributes and operator policy, rather than measured latency or link bandwidth.
What routers exchange
A BGP announcement pairs a destination prefix with attributes describing how it can be reached. It does not assign addresses, create a physical connection, or prove permission to originate a prefix. RFC 4271 defines the base BGP-4 protocol.
The ASN guide explains the autonomous system identifiers used in announcements. BGP uses those identifiers; it does not issue them.
IPv4 unicast is one address family. Multiprotocol BGP, defined in RFC 4760, adds support for other families, including IPv6. Peers negotiate supported families, so a working IPv4 session does not by itself establish that IPv6 routes are being exchanged.
eBGP and iBGP have different jobs
| Session type | Where it runs | Role |
|---|---|---|
| External BGP, or eBGP | Between different autonomous systems | Exchange routes with transit providers, peers, or customers |
| Internal BGP, or iBGP | Between routers in the same autonomous system | Distribute BGP routes across the operator’s network |
iBGP does not replace the underlying connectivity needed to reach a BGP next hop. An interior routing protocol or static routes commonly provide that reachability.
In ordinary iBGP, a route learned from one iBGP neighbor is not advertised to another iBGP neighbor. A full mesh addresses that constraint in small networks. Larger networks commonly use route reflectors, described in RFC 4456, to distribute routes without every router peering directly with every other router. Route reflection also affects which paths each router can see.
Open the eBGP/iBGP diagram as SVG.
How a BGP session comes up
BGP uses TCP, normally with destination port 179. The peers establish the transport connection, exchange OPEN messages, and reach the Established state before exchanging routes.
| Core message | Purpose |
|---|---|
| OPEN | Exchange session parameters and capabilities |
| KEEPALIVE | Maintain the session without carrying route updates |
| UPDATE | Advertise routes, change attributes, or withdraw routes |
| NOTIFICATION | Report a protocol error and close the session |
The session state machine includes Idle, Connect, Active, OpenSent, OpenConfirm, and Established. Active means the router is trying to establish transport connectivity; it does not mean the peering is working.
Route exchange is incremental after the initial exchange. A withdrawal removes a previously advertised path; a replacement path may then become usable. Detection timers, processing, and policy affect convergence, so BGP failover is not instantaneous.
From an UPDATE to packet forwarding
A route can be received without being accepted, selected, installed, or exported. Treat these as separate checkpoints:
Open the route-processing diagram as SVG.
The BGP table can hold several paths for one prefix. A BGP best path still competes with other route sources for installation in the routing table. Export policy separately determines what each neighbor receives.
Best-path comparison is for the same prefix. Packet forwarding uses the longest matching installed prefix. A /24 and a covering /23 are separate destinations in the routing table; a higher preference on the /23 does not override longest-prefix matching. The CIDR chart shows those prefix boundaries.
Attributes that influence routing policy
These are common inputs, not a universal ordered algorithm. Vendors expose additional controls and tie-breakers; Cisco’s best-path documentation describes one implementation.
| Attribute | Operational use | Limit to remember |
|---|---|---|
| LOCAL_PREF | Prefer an exit within your AS; higher values are preferred | Normally distributed through iBGP, not sent to ordinary eBGP neighbors |
| AS_PATH | Record AS-level propagation and detect loops | Shorter paths are not necessarily faster or preferred by policy |
| NEXT_HOP | Identify the next-hop address for the route | It must be reachable for the path to be usable |
| MED | Suggest a preferred entry when adjacent networks have multiple connections | Lower is normally preferred; comparison scope depends on implementation and configuration |
| Communities | Attach labels that routing policy can match | A label has an effect only where a policy interprets it |
RFC 1997 defines the original communities attribute. Providers publish community meanings for actions such as regional export control or prepending. Confirm the provider’s documented semantics and whether communities are preserved before relying on them.
Example: policy can prefer a longer AS path
An operator receives two eligible paths to the same prefix:
| Path | Destination | AS_PATH | LOCAL_PREF |
|---|---|---|---|
| A | 192.0.2.0/24 | 64497 64496 | 100 |
| B | 192.0.2.0/24 | 64498 64499 64496 | 200 |
Assume both next hops are reachable, higher-priority selection inputs are equal, and the implementation considers LOCAL_PREF before AS-path length. Path B wins because its local preference is higher, despite its longer AS path.
These are illustrative documentation addresses and ASNs. Setting LOCAL_PREF chooses your network’s outbound preference; it does not instruct remote networks to send inbound traffic through the same provider. The example demonstrates policy selection, not a latency prediction.
Import and export policies define the boundary
Write an explicit policy for every external session. Import policy decides which routes to accept and how to classify them. Export policy decides which routes a neighbor is allowed to learn.
RFC 8212 specifies default rejection for eBGP route exchange without the corresponding policies. Confirm implementation behavior: an established session may exchange no usable routes until policy is configured.
RFC 7454 describes operational protections, including prefix, AS-path, and next-hop filtering and maximum-prefix limits. Permit only the intended prefixes and lengths on export. A network connected to two transit providers should not accidentally advertise one provider’s routes to the other and become unintended transit. Monitor prefix counts and understand whether a configured limit warns, rejects routes, or shuts down the session.
Origin validation adds another check. RPKI route origin validation compares the announced prefix, length, and origin ASN with covering authorizations. A valid origin does not validate the full AS path or prove that the route was exported appropriately; origin-valid routes can still be leaked.
Check the route, not just the session
In FRRouting, these read-only commands separate session status from route selection and export:
show bgp ipv4 unicast summary
show bgp ipv4 unicast 192.0.2.0/24
show bgp ipv4 unicast neighbors 198.51.100.1 advertised-routes
show ip route 192.0.2.0/24Run them in FRR’s vtysh shell, substituting your actual prefix and neighbor. The addresses above are examples, not live targets.
| Symptom | Check next |
|---|---|
| Session stays Idle or Active | Neighbor addressing, TCP reachability, remote ASN, and session authentication |
| Established, but no accepted prefixes | Negotiated address family, import policy, and whether the peer exports the expected routes |
| Prefix is in BGP but not used | Next-hop reachability, the selected BGP path, and routing-table competition |
| Route is selected locally but absent remotely | Per-neighbor export policy, upstream filters, and the observed origin |
| Route is visible but the service fails | Forwarding state, return route, ACLs, MTU, and service health |
Use WHOIS and RDAP to check registry records separately from the live announcement. A looking glass shows one network’s view; verify from relevant external networks and test actual traffic in both directions.
For a newly moved block, the post-transfer checklist connects these routing checks with registry and authorization changes. Obtaining space through IPv4 services and making it reachable are separate operational steps.