Sub topic 12
Interior and exterior routing, and where BGP fits
This chapter assumes you know IPv4 addressing and CIDR notation, the difference between a router, a switch and a host, and the basics of static routes, administrative distance and link-state protocols such as OSPF. It explains why routing is split into interior and exterior parts, how BGP differs from the protocols covered earlier, and which problems you will meet when you first connect a network to the outside world.
Why routing is split in two
A routing protocol such as OSPF has every router in an area build the same map of the network. That works for a campus or a company. It cannot work for the whole internet, for three reasons.
- Scale. The global IPv4 table holds roughly a million prefixes. A link-state flood from every router in the world would never settle.
- Ownership. Each network has its own policy. A company may refuse to carry traffic for a competitor, or may prefer a cheaper provider over a faster one. A shortest-path metric cannot express that.
- Trust. You can trust the routers you run. You cannot assume that another operator's routers are correct or well intentioned.
The solution is to divide the internet into autonomous systems (AS). An autonomous system is a set of networks and routers under one administrative control that presents a single routing policy to the outside. Each AS is identified by an AS number (ASN). Public ASNs are assigned by regional internet registries. Private ASNs (64512 to 65534 for 16-bit numbers, and 4200000000 to 4294967294 for 32-bit numbers) are for internal use and lab work.
Routing inside an AS is handled by an interior gateway protocol (IGP). Routing between autonomous systems is handled by an exterior gateway protocol (EGP). Today the only EGP in use is BGP, the Border Gateway Protocol.
| Property | IGP (OSPF, IS-IS, EIGRP, RIP) | EGP (BGP) |
|---|---|---|
| Scope | Inside one AS | Between autonomous systems |
| Main goal | Find the best technical path | Apply policy and keep reachability |
| Typical metric | Cost, hop count or delay | Path attributes, then AS-path length |
| Neighbor discovery | Automatic, by multicast hello | Manual, you configure each peer |
| Transport | Own IP protocol, or IP protocol 89 for OSPF | TCP port 179 |
| Convergence | Seconds or less | Seconds to minutes |
| Table size | Hundreds to thousands of routes | Up to a full internet table |
How the two fit together
An IGP and BGP do different jobs, and a real network usually runs both.
- The IGP carries the routes needed inside the AS: loopbacks, link subnets and internal server networks. It lets every router reach every other router quickly.
- BGP carries the routes that cross the AS boundary: the prefixes you announce to the world and the prefixes you learn from your providers.
A BGP session between routers in different autonomous systems is external BGP (eBGP). A session between routers in the same AS is internal BGP (iBGP). iBGP exists so that routers inside the AS learn what the border routers learned from outside. It is not a replacement for the IGP. The IGP still provides the paths that let two iBGP peers reach each other.
BGP is a path-vector protocol
Earlier chapters compared distance-vector and link-state protocols. BGP is a third kind, a path-vector protocol. Each route advertisement carries the full list of autonomous systems the route has crossed, called the AS path.
The AS path does two jobs.
- Loop prevention. If a router sees its own ASN in the AS path of an incoming route, it discards that route. No hop-count limit is needed.
- A coarse metric. All else being equal, a shorter AS path is preferred.
BGP does not look for the fastest path. It looks for the path your policy prefers. Among the attributes it compares, in simplified order, are:
- Highest local preference (a value you set to say which exit you like best, shared inside your AS).
- Shortest AS path.
- Lowest origin type.
- Lowest MED (a hint that a neighbor AS sends about its preferred entry point).
- Prefer eBGP over iBGP routes.
- Lowest IGP cost to the next hop.
- Tie-breakers such as the lowest router ID.
Vendors add steps, such as Cisco's weight, so check your platform's documentation. The point is that you can steer traffic with policy by setting local preference, without changing any link cost.
Administrative distance and BGP
Administrative distance, covered earlier, decides between route sources for the same prefix. The Cisco IOS defaults for the sources in this chapter are:
| Route source | Default administrative distance |
|---|---|
| Connected | 0 |
| Static | 1 |
| eBGP | 20 |
| OSPF | 110 |
| RIP | 120 |
| iBGP | 200 |
Two consequences follow. An eBGP route beats an OSPF route for the same prefix, which is rarely what you want for internal prefixes. And iBGP at 200 loses to nearly everything, so a prefix learned by both OSPF and iBGP is used from OSPF. This is deliberate. Inside the AS the IGP should win for internal routes.
A minimal eBGP configuration
The example below configures R1 in AS 65001 to peer with R2 in AS 65002 and to announce one prefix. The addresses are from documentation and private ranges.
! Cisco IOS on R1 (AS 65001)
router bgp 65001
bgp router-id 1.1.1.1
neighbor 192.0.2.2 remote-as 65002
network 10.1.0.0 mask 255.255.0.0
! A route to the announced prefix must exist in the routing table,
! otherwise BGP will not advertise it
ip route 10.1.0.0 255.255.0.0 Null0Three details matter here.
- The
neighborline is the whole peering definition. BGP never discovers peers on its own. - The
networkstatement does not enable BGP on an interface, unlike in OSPF. It tells BGP to announce this exact prefix, and only if an identical route is already in the routing table. The static route toNull0is a common way to provide it, and it also acts as a safety net against loops for traffic to unused addresses within the block. - A default configuration with a real provider also needs inbound and outbound filters. Without them you may announce prefixes you do not own.
To check the session and what was learned, use these commands:
show ip bgp summary
show ip bgp
show ip bgp 203.0.113.0/24
show ip route bgpIn show ip bgp summary, a number in the last column means the session is established and gives the count of prefixes received. A word such as Idle or Active means it is not.
Where static routes still fit
BGP does not remove the need for static routes. Three common uses remain at the edge.
- A default route toward a single provider. A small site with one uplink often needs only a static default route. Running BGP gives it nothing.
- Anchoring announced prefixes. The
Null0route above is an example. - Backup and floating routes. A floating static route with a high administrative distance can back up a BGP-learned route if the session is lost.
A site with two providers is the classic case for BGP. It lets the site announce its own address block through both and recover automatically if one fails. A site with one provider rarely needs it.
Common errors and gotchas
- Session stuck in Active or Idle. Usually the peer address is unreachable, TCP port 179 is filtered, the remote ASN is wrong, or the peer has no matching
neighborline for you. - Prefix not announced. The
networkmask does not exactly match a route in the routing table, so BGP has nothing to advertise. - eBGP peers more than one hop apart. By default eBGP packets have a TTL of 1, so peering with a non-adjacent router fails unless you set a multihop option.
- iBGP routes with an unreachable next hop. iBGP does not change the next hop by default. If the IGP does not carry the external link subnet, internal routers learn a prefix they cannot use. A fix is
neighbor ... next-hop-selfon the border router. - iBGP split horizon. A router does not pass a route learned from one iBGP peer to another iBGP peer. In a large AS this forces either a full mesh of iBGP sessions, or route reflectors that relax the rule.
- Accidental transit. Without filters, a customer that peers with two providers may advertise one provider's routes to the other and carry traffic between them. Always filter what you send.
- Redistributing BGP into an IGP. Dumping a full internet table into OSPF overloads it. Use a default route instead, and redistribute only small, filtered sets.
Summary of the decision
Use an IGP when you control every router and want fast, automatic best-path calculation. Use BGP when you cross an administrative boundary and need policy, or when you are multihomed. Use static routes where the topology is simple and does not change.
Exercise
Your company has AS 65001 and one border router with two upstream providers. The border router learns 198.51.100.0/24 from both eBGP sessions, and internal routers learn it through iBGP. (a) Which attribute would you set to make Provider A the preferred exit for all routers in your AS? (b) Internal routers show the prefix in the BGP table but not in the routing table. What is the most likely cause, and what is the fix?
Show answer
(a) Set a higher local preference on routes learned from Provider A, for example with a route map applied inbound on that session. Local preference is shared across iBGP, so every internal router follows the same choice. (b) The next hop of the iBGP route is still the provider's address on the external link, and the internal routers cannot reach it through the IGP, so BGP marks the route unusable. Fix it by configuring next-hop-self on the border router's iBGP neighbors, or by carrying the external link subnet in the IGP.
Exercise
A router has OSPF and iBGP both offering 10.20.0.0/16. Which route enters the routing table with default administrative distances, and why? What would change if the iBGP route came from an eBGP session instead?
Show answer
The OSPF route wins, because OSPF has administrative distance 110 and iBGP has 200, and the lower distance is preferred. If the route were learned by eBGP (distance 20), the BGP route would win over OSPF.