H4CK0R Network Security ยท Recon ยท Education

๐ŸŒ Routing, ASNs and BGP

Routing, ASNs and BGP

There is no "the internet". There are tens of thousands of independently operated networks that have agreed to carry each other's traffic, and one protocol โ€” BGP โ€” through which they tell each other what they can reach. Nobody is in charge of the result. Understanding that is the difference between "the internet is down" and "our transit provider is preferring a longer path through an IXP that is dropping our packets".

Autonomous systems

An autonomous system is one network under a single routing policy: an ISP, a university, a bank, a cloud provider, a large CDN. Each is identified by an AS number. ASNs were originally 16-bit; RFC 6793 extended them to 32-bit, so you will see both AS15169-style small numbers and values above 65535. Ranges worth knowing: 64512โ€“65534 and 4200000000โ€“4294967294 are private use (RFC 6996), and 64496โ€“64511 is reserved for documentation (RFC 5398) โ€” which is what the examples below use.

Address space follows a delegation chain: IANA allocates large blocks to the five Regional Internet Registries โ€” ARIN, RIPE NCC, APNIC, LACNIC and AFRINIC โ€” which allocate to ISPs and large end users, who assign to customers. The IANA IPv4 free pool was exhausted in February 2011, and the RIRs have since worked from small final allocations, waiting lists and recovered space, which is why IPv4 addresses now have a resale market and IPv6 deployment finally moved. The registry data is public: look up registration data over RDAP โ†’ or find which AS owns an address โ†’.

IGP versus BGP

Inside one AS, an interior gateway protocol โ€” OSPF (RFC 2328) and IS-IS flood link state between your own routers and compute shortest paths by a metric like link cost, while EIGRP is an advanced distance-vector protocol that uses the DUAL algorithm rather than a link-state database. It optimises for speed and convergence, and it assumes every participant is trusted.

Between autonomous systems, BGP-4 (RFC 4271) does something different. It runs over TCP port 179 between explicitly configured neighbours, and it is a path vector protocol: every announcement carries the full list of AS numbers it has traversed. That AS_PATH prevents loops (a router rejects any route already containing its own ASN) and encodes policy. BGP does not look for the fastest path โ€” it looks for the path your business relationships say to prefer. Two networks in the same city can exchange traffic via a third continent if that is what the policies produce.

How a route is chosen

A router usually hears the same prefix from several neighbours and must pick one to install. Implementations differ in detail, but the decision runs roughly in this order, stopping at the first tie-break that resolves:

StepCriterionWho controls it
1Highest LOCAL_PREFYou โ€” the main lever for "prefer this transit provider"
2Shortest AS_PATHThe sender โ€” the main lever for "make my path look worse"
3Lowest ORIGIN (IGP < EGP < incomplete)The originator
4Lowest MEDThe neighbouring AS, hinting which of its entry points to use
5eBGP preferred over iBGPProtocol rule
6Lowest IGP metric to the next hopYour internal topology ("hot-potato" routing)
7Oldest route, then lowest router IDStability tie-breakers
router> show ip bgp 203.0.113.0/24
   Network            Next Hop        LocPrf  Path
*> 203.0.113.0/24     198.51.100.1       150   64496 64510 i
*  203.0.113.0/24     198.51.100.5       100   64497 64505 64510 i

The *> marks the chosen route: higher local preference, and also a shorter AS path. Prepending your own ASN several times to an announcement is the standard blunt tool for pushing traffic onto the other link โ€” you are deliberately making step 2 go against you.

Prefix length is not on that list, and this is the single most important thing to internalise. The decision process picks the best path for one prefix. Forwarding then uses longest-prefix match: given routes for both 203.0.113.0/24 and 203.0.113.128/25, a packet to 203.0.113.130 follows the /25, whatever the AS paths say. More specific always wins, and it wins in a different table than the one BGP's tie-breakers apply to.

Transit, peering and IXPs

A "tier 1" network is one that reaches the whole default-free zone through settlement-free peering alone, buying transit from nobody. The default-free zone itself is the set of routers that hold a full table โ€” on the order of a million IPv4 prefixes, and growing โ€” with no default route.

Anycast

Anycast is the same prefix announced from many locations at once. Routing does the load balancing for free: every network's own best-path calculation sends packets to whichever instance is nearest to them, so 8.8.8.8 (Google Public DNS) and 1.1.1.1 (Cloudflare's resolver, run with APNIC) answer from a nearby site almost anywhere on earth, from one address. The root DNS servers work the same way: 13 server identities, served from many hundreds of physical instances worldwide.

Anycast suits stateless request/response traffic best, because nothing guarantees that two packets take the same path. In practice routes are stable for long enough that TCP and TLS work fine over anycast โ€” that is how anycast CDNs and DDoS scrubbing operate โ€” but a route change mid-connection resets it, so long-lived sessions are usually handed off to a unicast address.

When routing goes wrong

BGP has no built-in notion of who is allowed to announce a prefix. A neighbour's announcement is accepted because you configured a session with them, not because it was proved correct. Two failure classes follow:

Prefix hijacking โ€” an AS originates a prefix it does not hold. Announcing a copy of someone's /16 competes with the real one and wins only where the path looks better. Announcing a more specific block inside it โ€” a /24 carved out of that /16 โ€” wins everywhere the announcement is accepted, because forwarding uses longest-prefix match and never consults the AS path. Traffic for those addresses is then delivered to the announcing network instead of the real owner. It either disappears (a blackhole, seen by users as a hard outage) or, if the hijacker maintains a working path back to the legitimate network, is inspected or modified and forwarded on, which users may not notice at all. Two well-documented cases: in February 2008 Pakistan Telecom (AS17557) announced 208.65.153.0/24, a more specific of YouTube's 208.65.152.0/22, intending a domestic block; the announcement escaped to a transit provider and took YouTube globally offline for a couple of hours. In April 2018 more-specific announcements covering Amazon Route 53 DNS servers were used to hijack DNS resolution for a cryptocurrency wallet site and serve a phishing page.

Route leaks are usually accidents rather than attacks: a network re-announces routes it learned from one provider or peer to another, in violation of the intended policy (RFC 7908 catalogues the patterns). Suddenly a small regional ISP looks like the shortest path between two continents, and a fraction of the internet's traffic tries to fit through its links. The result is congestion, packet loss and latency rather than interception โ€” and it is far more common than deliberate hijacking.

What encryption does and does not cover here TLS still protects the contents of a hijacked connection, and certificate validation means an attacker cannot simply impersonate an HTTPS site. But routing control leaks metadata (who talks to whom, and how much), enables denial of service, and historically enabled fraudulent certificate issuance by intercepting domain-validation traffic. Public CAs now perform domain validation from multiple network vantage points specifically to make that harder.

The defences

RPKI (RFC 6480) is a public key infrastructure over IP address space. A holder publishes a signed Route Origin Authorisation โ€” a ROA stating "AS 64496 may originate 203.0.113.0/24, with a maximum prefix length of /24". Routers fed by validation software (via the RTR protocol, RFC 8210) then label each announcement with an origin-validation state, defined in RFC 6811:

StateMeaningTypical policy
ValidA ROA covers this prefix, the origin AS matches, and the length is within maxLength.Accept
InvalidA ROA covers the address space but the origin AS is wrong, or the announcement is more specific than maxLength allows.Drop
NotFoundNo ROA exists for this space. Still the state of a large share of the table.Accept

So when the site's BGP and ASN intelligence tool โ†’ reports RPKI invalid, it means the announcement contradicts what the address holder signed. That is exactly the signature a more-specific hijack leaves โ€” but it is far more often a misconfiguration: a ROA created with maxLength /24 while the operator announces /25s, or a prefix moved to a new ASN without updating the ROA. Treat it as "this will be dropped by a growing number of networks, and someone should fix it", then investigate.

RPKI origin validation only proves the first AS in the path is authorised. It says nothing about the rest of the AS_PATH, so it does not stop a leak that keeps the real origin intact. Work on validating the path itself continues โ€” ASPA is in development, and BGPsec (RFC 8205) specifies full path signing but has seen essentially no deployment because of its cost. The other layers in current use:

None of this is exotic to check. Look up your own address with the BGP tool โ†’: it shows the covering prefix, the originating AS and the RPKI state, which is the same view a peer's filters have of you.

Key takeaways
  • The internet is tens of thousands of autonomous systems exchanging reachability over BGP (TCP 179). AS_PATH is a loop-prevention and policy mechanism, not a distance metric.
  • Best-path selection is policy-first: LOCAL_PREF, then AS_PATH length, then origin, MED and IGP cost. Business relationships beat physics.
  • Forwarding uses longest-prefix match, which is why a more-specific announcement outranks the legitimate one regardless of AS path.
  • Transit buys the whole internet; peering only exchanges each side's own and customer routes; IXPs make peering cheap. Anycast gives one address many locations.
  • Route leaks (accidental re-announcement) are more common than hijacks. Both come from BGP's lack of built-in authorisation.
  • RPKI ROAs let a router mark an announcement Valid, Invalid or NotFound. "Invalid" usually means a stale or wrong ROA โ€” but it is the same signal a hijack produces, so it always deserves a look.