1

I’m struggling to understand the need of specifying the default gateway in the host’s routing table.

When a host is building a frame to be sent, it needs to specify two MAC addresses; one for the interface through which the packet is going to be sent, and one for the interface of the next node that will receive the packet.

To know the first MAC address, the host looks in its routing table for a network that includes the destination IP address and reads the corresponding IP address of the interface through which packets destined to that network are supposed to be sent. Then, it looks in its MAC address table for the MAC address that corresponds to the IP address of that interface.

As for the second MAC address, i.e. of the next node that will receive the packet, the host first checks if the destination IP address is within one of the local networks that it belongs to. If the destination IP address turned out to belong to one of these networks, the first node that will receive the packet will also be the last and will, by definition, co-exist with the host in the same network. To know its MAC address, the host can either check its MAC address table for an entry with the destination IP address or perform an ARP request. If, on the other hand, the destination IP address turned out to be in another network, the host checks its routing table for a network that includes the destination IP address and retrieves the IP address of the corresponding [default] gateway. Then, either by using the MAC address table or performing an ARP request, the host finds the MAC address of that default gate.

My question is this: Why does the host need to check the routing table to know which default gateway to send the frame to? Doesn’t the host already store information pertaining to the IP addresses of its different interfaces and their respective subnet masks? If so, then it could easily iterate over the pairs (IP address, subnet mask) associated to each interface and check if the destination IP address falls within one of the networks associated with each pair.

1 Answer 1

2

You are confusing the default gateway with gateway. You only need and use one default gateway, which is the gateway of last resort when other paths to the destination network are unknown.

There can be multiple gateways on a network, one of which is your default gateway, but there can be others with more specific routes. If your default gateway is Router A, and Router B is your gateway to 10.11.12.0/24, you want to configure your host to use Router B for that network. It could be that network is another network inside your company, but Router A is the gateway to the public Internet. You then have two gateways, but only one default gateway.

When sending packets, the routing table is checked for a destination network matching the destination address. More-specific routes (most bits matching the destination address) are preferred over less-specific routes. A default route is the least-specific route there is (0 matching bits), so any route that matches more bits will be preferred over the default route.

A default gateway is the gateway to which the default route points, so it is the gateway of last resort for when no other routes to other gateways match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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