7

I've been doing small-time freelance IT work (among other things) for about the last decade now. I've set-up or rebuilt more local network arrangements than I can care to count, and more recently I've been studying up on some of the big gaps that remained in my networking knowledge. All-in-all, while I most definitely wouldn't call myself an "expert" I think that at this point I have a decent grasp of how things work inside a network perimeter, and a fair understanding of most networking fundamentals (the layers of the OSI stack, TCP/IP, DNS, MAC addressing & ARP, higher-level protocols, etc.)

However, the other day something occurred to me: "How would I explain to someone how routing a packet on the Internet actually works?" And I realized I'd have trouble answering that question.

Now, I do have at least some understanding of what, for example, Border Gateway Protocol is & does, or what a routing table is, or what Internet infrastructure peering points are. But I'll admit that I don't really understand how those things and others actually determine what a router will actually do with a packet to move it towards its destination IP address.

So, how does a router on the Internet that receives a packet decide which router to forward it to next? And how does that router then know the best router it should forward the packet to? As I said, I have some understanding of elements & concepts related to the Internet routing infrastructure, but I'm unclear about how everything fits together to actually allow a given router to make a good routing "decision" about where to send a packet that comes to it to do its part in correctly moving the packet towards its final destination.

(Note: I've looked at any of number of resources to try to gain a better understanding of this. But most things I've come upon thus far have either (1) elided over the technical topic of how a router on the Internet knows where to send a packet for the next hop, or (2) gotten so bogged down in technical details & jargon about protocols and such that it's been hard to gain a picture of how everything comes together at a router's decision point. And I thought this would be as good a place as any to get an actual technical answer to that question that might also be comprehensible to a non-expert in networking.)

2
  • 1
    Well....with respect I don't see anywhere in my question where I asked for recommendations about a good handbook about networking, or what VPN service I should use when I connect to public Wi-Fi hotspots. I asked a technical question about what happens when an intermediate router that is forwarding traffic across the Internet gets a packet and forwards it to Next Intermediate Router X instead of Next Intermediate Router Y to move the packet towards its destination IP. I fail to see how that calls for "low quality", "opinionated", "spam", and quickly-obsolete answers. Dec 24, 2015 at 0:57
  • FWIW, I think the answers and comment below together sketch out a useful view (a high-level, abstract view, sure, but I see now why that's probably necessary because of the topic) of what happens on the Internet to get a packet somewhere across the expanse of diverse ISP and network-infrastructure company networks, even where no one entity has any single, unified map that shows the complete optimal path between a source and a destination. I understand a bit more now than when I asked the question, which I value & appreciate. Dec 24, 2015 at 1:24

3 Answers 3

4

As you already mentioned BGP is you basic answer.

I'll try to summarize this, but the answer can get pretty long and complicated.

IP addresses are distributed by ARIN + few other similar international organizations which are tasked w/ distributing and keeping track of IP address space.

An ISP's border routers (where ever they might be) then advertise that they are the the destination for said IP address space, and they can also advertise the best path to take to them.

There are also various algorithms, and settings and etc that a Network Engineer can use to configure a router to take specific routes to get to a destination. For example avoiding a known bad carrier, or more complicated scenarios.

But again, what you're looking for is BGP and it's many options.

Some links for further reading: http://searchtelecom.techtarget.com/feature/BGP-essentials-The-protocol-that-makes-the-Internet-work http://www.cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/13753-25.html

1
  • 1
    BGP is only used for routing between ISPs (and some large ISP customers). This doesn't explain how routing works within an autonomous system.
    – Barmar
    Dec 16, 2015 at 6:49
2

Routers use routing protocols to distribute information about the location of each network on the Internet among themselves. Each router that participates in the routing protocol builds up a routing table (other routers mostly use pre-configured default routes). Each routing table entry essentially says "To reach destinations within prefix P, send through interface I to next-hop address A" (unless the destination is on a directly-connected network, in which case there's no next-hop address).

When a router wants to send to a destination, it looks for the entry with the longest prefix that matches it, and then follows its direction to forward the packet. Each router along the path uses this same mechanism, and the packet eventually reaches its destination.

Actual implementations make use of optimizations, such as caches and hardware features that automatically match addresses against routing tables, but the above is the basic algorithm.

1

A router has a routing table filled with information about where to send packets. If it's a simple home router, it probably has two entries; local network (e.g. 192.168.1.0/24) is directly connected on LAN interface and everything else is sent via the default route on the WAN interface to the gateway address (next hop), which is a router managed by the ISP.

The routing table can be filled manually if they are as simple as this example, or by running some routing protocol like BGP or OSPF, that talks to the peers and computes the contents of the routing table.

Not the answer you're looking for? Browse other questions tagged .