Page 1 of 1

Confused about default gateways

Posted: 2020/12/16 16:27:22
by bodisha
Hello, and thanks in advance for anyone that can help straighten me out on what I'm sure is a simple question

I've managed to confuse myself with how MAC addresses and default gateways work

My understanding of 2 machines on the same LAN is:

1) A source machine looks up the destination IP Address in it's ARP address table
2) If the destination IP Address doesn't map out to a MAC address, the source computer broadcasts an ARP request to all machines on the LAN
3) When the destination machine receive the ARP request, it replies with it's MAC address & IP Address
4) The source computer updates it's ARP address table with the destination MAC & IP addresses
5) Once a computer can map an IP address and MAC address... the source computer sends a frame to the destination machine
6) The destination machine only uses the MAC address to recognize itself and accept the frame


My understanding of why a default router is needed is where I'm confused... My understanding or a source machine communicating to a destination machine off the LAN is:

1) A source machine looks up the destination IP Address in it's ARP address table
2) If the destination IP Address doesn't map out to a MAC address, the source computer broadcasts an ARP request to all machines on the LAN
3) When a router receives the ARP request (and if it has the MAC & IP address in it's table) it replies with it's own MAC address and the destination IP Address
4) The source computer updates it's ARP address table with the router MAC address & the destination IP address
5) Once a computer can map an IP address and MAC address... the source computer sends a frame to the router
6) The router only uses the MAC address to recognize itself and to accept the frame
7) The router updates the frame with the next routers MAC address (Or the destination machine's MAC) and transmits it out till it reaches the destination machine

So I guess my question is if... if this is the procedure for a source computer to transmit a frame to a destination computer on a different network... Where/How/Why are default gateways defined in a source computer? The concept seems redundant to me... I realizer I'm missing something but can't figure out what

Once again... Thanks for any assistance with this!

Re: Confused about default gateways

Posted: 2020/12/16 18:52:28
by jlehtone
There might be tens of routers between you and destination. A router can be linked to more than one other routers. How do you think your model copes with solving the route?

Your machine has a routing table. You can see it with ip ro
The IP address-based (layer 3) routing decision is made before going into (layer 2) MACs.

Lets say you have simple table:

Code: Select all

default via 192.168.0.1
192.168.0.0/24 dev eth0 src 192.168.0.42
We have a packet with destination IP address X. The routing logic is something like:

Code: Select all

IF X belongs to 192.168.0.0/24
THEN resolve MAC of X (by ARP to eth0, if necessary) and toss packet out of eth0 with that MAC
ELSE we need to forward packet to 192.168.0.1
If we have to forward the packet, then we have to figure out how to route to 192.168.0.1.
The table resolves that 192.168.0.1 belongs to 192.168.0.0/24 and we can proceed to resolve its MAC-address (ARP via eth0, if needed)
The forwarded packet can then be tossed out of eth0. It will be addressed to MAC of 192.168.0.1, but the IP destination is X.

The router (192.168.0.1) receives that packet. Now it makes a routing decision. Since it is not X, it will toss packet out to some subnet.
Same repeats on every router on the "route", until we get to the one that is link-local to X. Only that last router will have to resolve/know the MAC of X.