Can a PC have more than one Default Gateway?

I know that a PC can have multiple network adapters each of which with different network identifiers (IP,MAC etc.).

My question is, can a certain PC have more than one active default gateway? And if so, how does the PC (or better say the OS) knows to what adapter use for any given packet?


Solution 1:

Technically yes, practically no.

The key is in the term 'default', it's the default - I have a default sandwich I order from Subway (Meatball Marinara with cheese and jalapeños) which I vary from routinely, still my default though, I don't have two defaults.

So it's the same with network interfaces, you define the 'norm' and then specify whenever you want to break from that norm via 'static routes' (look at the 'route' command on your OS of choice).

Hope this helps, and didn't make you too hungry...

Solution 2:

No, it can't have more than one active default gateway.

Any operating system can have multiple default gateways configured (technically a route to the unspecified address, i.e. 0.0.0.0 or ::). In that event, it does what it would do for any route destination with multiple paths.

  • It chooses the active route based on the Preference value
  • If there are multiple with the same Preference then it chooses one based on the Metric
  • If both Preference and Metric are the same (which would likely only be the case for static routes) the method of choosing which will vary by operating system, but it will select one and mark it as active

It will use the active selection until the system can detect that it's no longer functional (this will vary depending on how routes were inserted into the routing table) and then it switches to another available route (again, based on Preference then Metric).

And if a new route is introduced with a higher Metric or Preference it will switch to the most preferred, then shortest metric.

But at any one time it can only have one (or zero) active route to any particular destination.

Solution 3:

The default gateway is the route use if none of the other routes match. So by that definition, there can be only one at a time.

Except not really, because your routing rules might be more complicated. Modern versions of Linux, for example, support using multiple completely independent routing tables, and making packet-by-packet determination as to which table to consult. So for example, perhaps you have one network configuration used for normal traffic, but a completely different routing table for your web browser. Or perhaps you have another routing table that's only used for packets with specific TOS bits set. But each would have its own default gateway which would reflect the default route for that specific routing table.

Normally, the routing table is as simple as, "local traffic to the local interface, everything else to the router." But if you're using a more complicated network setup, then the tools exist to cope with whatever network scenario you can dream up.

Solution 4:

On Windows (at least Vista), having multiple default routes on the same interface with different metrics is fine. Windows will automatically switch to the route with the next highest metric if the lower metric router goes down. If there are multiple default routes with the same metric, Windows randomly selects one to use.

This allows you to have redundant routers without configuring failover on the routers.

On Linux, this does not work. You can have multiple default routes with different metrics, but currently the Linux kernel ignores the metric value. If the default router with the lowest metric disappears, traffic will not flow.