11

Say I want to send a frame to a web server, and let's say this web server is in a very distant IP outside my local network e.g. a Google server. I initially send the frame to my router. My router decapsulates the frame, reads the destination IP address from the L3 data and through its routing table, finds the a next hop router. The router then re-encapsulates the packet into a frame.

These two answers, How does a router know the destination mac?, https://superuser.com/a/702854 , suggest the next hop router is found through checking the routing table for routers on its local network, but how does the router determine the next hop router if the server is in another country?

Now, it is possible that the next hop address is not on a network that your router is connected to. So your router looks in its route table to find the route to the next-hop address. That route will also have a next hop address (we'll call it NH2). NH2 will be on a common subnet, so your router will ARP for the MAC of NH2.

This answer seems promising, but I don't get how the routing table can just have a route to a next hop router that isn't on its network. "NH2 will be on a common subnet", how can you not be on the same network with a next hop router, but have a route to a next hop router on a common subnet?

Furthermore, how do you get the MAC address of the next hop router? The router does an ARP to get the MAC address of the next hop router to fill the destination MAC address for when the router re-encapsulates the packet, but I find it difficult to believe that the router will send an ARP request to all 250 other devices located within the subnet every time to get the MAC address of the next hop router, especially if you're sending a packet to an IP address as far away as another country.

3 Answers 3

18

Say I want to send a frame to a web server, and let's say this web server is in a very distant IP outside my local network e.g. a Google server.

You're sending packets to remote destinations. Frames are only used within a local network.

the next hop router is found through checking the routing table for routers on its local network, but how does the router determine the next hop router if the server is in another country?

The trick is that no single router knows the whole path to a destination (unless they share a subnet and it's the last hop). It only needs to know the next hop which it finds in its routing table. "I don't know myself but I know someone who knows." That actually works all the way from the source to the destination.

Each router either has a simple default route to the next upstream router on its uplink interface, or it has the full Internet routing table, or a mixture of both.

it is possible that the next hop address is not on a network that your router is connected to.

Generally, a router can only talk to other routers that it shares a network with. You seem to be missing the point that a router has multiple interfaces and is connected to multiple networks.

So your router looks in its route table to find the route to the next-hop address. That route will also have a next hop address (we'll call it NH2). NH2 will be on a common subnet, so your router will ARP for the MAC of NH2.

ARP is only used on MAC-based networks, most prominently IEEE networks. Other networks may use different mechanisms.

how the routing table can just have a route to a next hop router that isn't on its network.

See above - they need to share a network.

I find it difficult to believe that the router will send an ARP request to all 250 other devices located within the subnet every time to get the MAC address of the next hop router,

IP/MAC combinations resolved by ARP are cached, but essentially that's how it works. You don't know how many devices are connected to a subnet though. It may be just two, several hundred, or potentially a few thousand.

especially if you're sending a packet to an IP address as far away as another country.

The path of an IP packet beyond the next hop is irrelevant here. It only becomes relevant when the next hop becomes the current one, and then it's only the next hop again.

5
  • 1
    Thanks! That was very clear. So basically, every router is connected to multiple networks, which themselves are connected to multiple networks. Your router just has a route to a next hop router that it knows will get it closer to its destination, and each router keeps sending the packet to the next hop router until it reaches its destination.
    – JohnDoeyyy
    Aug 8 at 3:47
  • Yes, that's the general concept.
    – Zac67
    Aug 8 at 4:39
  • "I don't know myself but I know someone who knows." → is there formal evidence that this is a convergent search, so to speak? I am sure there is (since traffic on the Internet is a thing) but I am curious about the actual solution. Is there a "know all" backbone (or set of backbones), similar to DNS root servers?
    – WoJ
    Aug 8 at 11:26
  • The "know all" backbone doesn't really exist but you may visualize it all the same. Those nodes can route every single IP packet to the optimal next-hop gateway. What happens beyond that gateway is generally not known to nodes outside that path. For the general concept, you might be interested in Dijkstra's algorithm which describes the basis for many distributed routing protocols.
    – Zac67
    Aug 8 at 12:14
  • 4
    DNS root servers don't know it all. They only know the TLDs. You might say the lower level domains are summarized for the root servers. A similar process happens with routing.
    – Ron Trunk
    Aug 8 at 16:25
4

Routers learn routes in three ways:

  1. Directly connected networks
  2. Statically configured routes
  3. Dynamically through routing protocols

MAC addressing and ARP are used on a network that uses an IEEE data-link protocol (ethernet, Wi-Fi, token ring, FDDI, etc.) to resolve a MAC address from an IPv4 address (IPv6 does not use ARP, instead it uses NDP), but they are not used on other data-link protocols. It is not uncommon for DSL to use PPPoA, and that uses no addressing for PPP and VPI/VCI for the ATM instead of MAC addressing, so your WAN link would not have a MAC address and not use ARP.

A router creates a frame for a packet that is a frame of the data-link protocol on the interface to the next network. It may use ARP if the interface is IPv4 and uses MAC addressing, or it will use the means dictated by the protocol(s) used on the interface to the next network.

3

A router can have different types of route.

The most basic is directly connected routes, a router has multiple interfaces and for each interface there will be a directly connected route.

At the other extreme is the "default route", this is a route that basically says "the internet is this way". Not all routers will have a default route.

Routes can be configured statically, this works ok for small networks, but it's not good as networks grow larger and more complex.

So that brings us to dynamic routing protocols, we generally divide these into "internal" and "external".

Internal routing protocols are designed to work within a network controlled by a single entity. There are many different ones to choose from but all of them handle the task of distributing routes within an organisation. Mostly for internal routing protocols the next-hop can simply be determined by looking at where the route was received from.

External routing protocols handle exchange of routes between organisations, there is only one such protocol in widespread use, BGPv4. BGP is used to exchange routes between networks and also to exchange external routes between within a network. BGP normally has two modes, internal (iBGP) and external (eBGP). eBGP is used on links between autonomous systems and normally operates only within the scope of a singlelayer 2 link. iBGP on the other hand operates within an autonomous system and can cross multiple layer-2 links. Traditionally every BGP-speaking router in an autonomous system would have an iBGP link to every other BGP-speaking router in the autonomous system (there are other approaches, but that is drifting off-topic here).

BGP nexthop handling is a little different from it's handling in internal routing protocols. The next-hop provided by the BGP protocol may not be directly reachable by the router that needs to forward traffic. To get around this, a recursive lookup is performed in the routing table to translate the BGP next hop into a local interface and next hop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.