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?

migrated from stackoverflow.com Jan 5 '12 at 17:48

This question came from our site for professional and enthusiast programmers.

  • the keyword is "default" if it just said ip gateway then things might be different. – tony roth Jan 5 '12 at 18:10
  • 1
    The best way to do this is to put a higher route metric on one of the defaults. That works pretty well on both Windows and Linux. The route with the lower metric wins, until that interface goes down – Mike Pennington Jan 5 '12 at 18:58
  • 1
    I would really like to know what you're trying to accomplish with multiple default gateways. Load balancing?? Perhaps there is a more specific underlying question. – Paul Ackerman Jan 5 '12 at 20:19

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...

  • 7
    +1 for food analogies. – Tom O'Connor Jan 5 '12 at 18:05
  • 1
    +1 Though most OSes can support multiple network views, which can allow for multiple default gateways, though almost certainly not in the same sense that the Questioner is thinking. – Chris S Jan 5 '12 at 18:14
  • What happens when you have two NICs, A and B, set a default gateway going out via A, and somebody starts a conversation with you via B? (I'm curious because I wrote an answer around this particular situation, and now I'm beginning to question it) – user80295 May 23 '12 at 15:46
  • 1
    @ArjunShankar then it transmits back using NIC B, simply because it knows about that route, the default route is only used when there's no direct route to a destination. – Chopper3 May 23 '12 at 16:00
  • Its good to point out though, that if you receive packets on B from a network you're not connected to (it was ROUTED to you) then you will get an asymmetric conversation because the destination network is not in the routing table and as such the replies will go to the default gateway. If it's a straight route, it should work anyway, but if it's going through a stateful firewall anywhere it may get pissy with you – SpacemanSpiff Jul 20 '12 at 23:36

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. 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.

  • Note, I intentionally left out more specific routes because the subject is about defaults. Route selection happens in the order of 1) most specific 2) highest preference 3) shortest metric. If all are equal it's more or less arbitrary. – bahamat Jul 20 '12 at 19:57
  • nice answer, makes sense, and short – SpacemanSpiff Jul 20 '12 at 23:39
  • @bahamat If I have two defaults and the active one can't get me to destination. Will the OS try right away to contact the second one? – AhmedWas Nov 12 '18 at 9:01
  • @AhmedWas Unfortunately, the answer is more complex than will fit in a stack exchange comment. It really depends on a lot of different factors. Sometimes it might, but other times it might not, depending on how it's configured and how other components on the network are behaving. – bahamat Nov 15 '18 at 4:39
  • @bahamat Thanks for the comment. Could you please just mention a simple example where the OS will try to contact the second available gateway? – AhmedWas Nov 15 '18 at 7:14

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.

  • It's also interesting to point out, that you can set the default gateway on multiple connections, but if you open the advanced settings menu under network connections where you can select the binding order, you it will choose whichever NIC is at the top first, then go down the line. It's funny to me how many people muck with some of that stuff via the CLI when its a simple click. – SpacemanSpiff Jul 20 '12 at 23:38
  • 1
    Default routes are not the same as default gateways. The two are used in different contexts. – John Gardeniers Jul 21 '12 at 11:53
  • @JPW If I have two defaults and the active one can't get me to destination. Will the OS try right away to contact the second one? – AhmedWas Nov 12 '18 at 9:02

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.

  • this should be the accepted answer. – prosti Sep 24 '18 at 16:35

A PC can have more then 1 default-gateway, but in the static IP configuration you enter only 1 address, actually it can be few default-gateways that take you outside of your network. There is an address that is called floating address, this address is only a virtual address and not real. The address is an address that is floating between two routers in one network. the floating address is entered on the PC and when it is coming to the switch on the work/before it enters the Routers it makes it's own conclusions about the path and choose one of the two or more default-gateways.

It is difficult to show you how it works it's a network professional level tools, the protocols that are running in the network when it is used are: VRRP and HSRP. Cisco and Juniper Protocols.


Yes you can. But what is the sense of it?

You are most probably looking for something like a "reflect mode" (I think this was called in Solaris 2.4.x). Perhaps you can detail your question here - what is your current setup and what is you goal.

Anyway - I am guessing that you have a multi-homed server with network interfaces that can potentially receive traffic from any client. Now you want to answer back through the same interface that the traffic came in...

This can be done - but not with the simple means of a default gateway.


for a windows machine: the tool of choice to play with is found at the command prompt: "route" "route print" will display your current routing table

you can only have one default gateway per adapter. The PC will effectively use only one gateway - the first card listed in the NIC binding order routing will look throu your route table, using more specific rules and getting more generic as it works through the table.

have a look at this article for ideas... Windows 7 has not changed this much since win2k. http://support.microsoft.com/kb/140859

  • 1
    anyone mind sharing why they down voted me? The answer I provided starts to answer some of the additional questions that were asked. – cwheeler33 Jul 21 '12 at 15:00

If your server/PC is multihomed, meaning it is part of two separate networks, you would have a default gateway on each network adapter. You then prioritize the network adapters. Like others have said though, you still just have one default gateway, but it's per network adapter.

  • 4
    No, no you REALLY wouldn't - this is an astonishingly incorrect answer – Chopper3 Jul 20 '12 at 23:23
  • 2
    You're confusing default routes with default gateways, which are completely different animals. – John Gardeniers Jul 21 '12 at 11:55

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.