I know how computers in a LAN communicate with each other (all the Ethernet/MAC address/NAT etc stuff), but I wonder, how do Internet routers communicate? Are they connected into some kind of giant LAN? What protocol is used to deliver packets (e.g. IP and BGP packets)?

4 Answers
4

The routers form a mesh, of sorts. Each one is connected to several others (conceivably on a LAN, but typically just a direct connection, maybe over a long distance like an undersea cable or a T-carrier or fibre link), and each one knows which it is connected to. Each router typically has many IP addresses, one per link to another router it has.

The routers usually run routing protocols which allow them to discover what their neighbours (the routers to which they are directly connected) are connected to. These are IS-IS, BGP, EIGRP, RIP, OSPF, etc. They can also keep track of this statically; routing protocols are a labour-saving device that lets network administrators automate routing table maintenance in case of changes (either intentional or due to a failure). So, each router is connected to several others, and knows what is where more or less. This information can be allowed to filter through the Internet; routers will inform each other of their neighbours' neighbours also, so it is possible to build a view of everything reachable in every direction (approximately). Routers also keep track of how far away things are (how many routers are between, and potentially how fast the path is), to facilitate getting packets to their destination efficiently.

Some routers (eg. your LAN gateway, or some of your ISP's routers) have only a couple routes: the LAN they are the gateway for, and usually one default route for the rest of the internet (in IPv4 networking, this is 0.0.0.0/0, or the "default" route). They therefore know that packets going to their LAN go in one direction (out the LAN interface), and packets going elsewhere go in another direction (out the WAN interface).

Other routers with more links and more networks on either side extend this concept somewhat. They will know what prefixes (the network number part of an IP address, formally) are in each of several directions, and send packets along that route (thus their name). They relay the packet to each other this way until it reaches its destination; if this is impossible, there are several mechanisms to drop it and show that it has been dropped.

So, your packet gets to your ISP, possibly from your LAN router which knows what interface the Internet is on and sends it that way. Each successive router looks at the destination address and determines which network it is part of and so which direction it goes according to its routing table; it will know that addresses beginning with a certain number are in the "direction" of one particular other ISP, and send it that way (changing the layer 2 information at each hop in order to do this, so the MAC address for instance will change at each hop). Eventually, it reaches a router on the same network as the host you're trying to reach, and it gets to that destination.

Each of these relay steps is called a hop. You can see this work using the traceroute utility (tracert on windows), though you may not see all the hops due to ICMP filtering being very widespread.

Yes, BGP is used to exchange routing informations between ASes.
Thus enabling successful routing on the internet. This happens using TCP (and obviously IP)
Then you have IGRP and OSPF in use within ASes.

The protocol is TCP/IP, they are connected through WAN connections not LAN. The routing protocol is only the "language" that your router speaks. In a basic network you configure the same routing protocol so that your routers can understand each other, and these routing protocols are known as Interior Gateway Protocols. The "language" used in the Internet is called BGP this is called Exterior gateway Protocol.