I have a computer(Windows XP) connected to two network interfaces, these two interfaces are connected to different networks and they are configured to receive a DHCP configuration, which means that both of them will give to the computer a default gateway.
The computer behaves sometimes correctly and sends packets to the right interfaces, sometimes it doesn't.
Is there a logical explanation about how computers behave in such situations?
Is there a right way to keep these both interfaces configured like that and behave correctly ?
5 Answers
If Windows has multiple interfaces connected to several networks that use DHCP, it installs default gateways for all those interfaces.
By default, Windows sets the metric of the default gateways to the same, effectively leading to random selection of default gateway.
If you want to make Windows to select certain gateway always, you can change interface metrics for the interfaces' configuration you don't want to use:
- Go to your Network adapter properties
- Select Internet Protocol v4.
- Click the Advanced button on General tab.
- Uncheck
Automatic metric
. - Enter a number higher than 10 to the
Interface metric
field.
The default automatic metric for interfaces is 10. The lower the metric, the higher the preference to use it. So, you have to enter metric higher than 10 for the interfaces you don't want to use.
EDIT: These instructions are for Windows 7, XP might be different. You shouldn't be using XP anyway.
- Your computer will not apply DHCP configuration from BOTH DHCP servers at the same time.
- Windows computer CAN have two default gateways. You cannot set second default gateway in GUI, but you can add it in command line with
route
command. In this case Windows will use path with lower metric value.
You can check if you have two default gateways with route print
command. Default gateway is there, where both network address and network mask are assigned to 0.0.0.0
-
2You certainly could add another route to 0.0.0.0 with a lower metric but Windows is not going to route traffic as you'd expect it to. There can be only one
Default Gateway
. Commented Mar 30, 2014 at 15:35 -
1@joeqwerty, seems that you are right. I've checked this situation and can now confirm that Windows not (or not always) sends traffic to route with lower metric. Next time I will check twice before answering )– kallaxCommented Mar 30, 2014 at 15:49
-
1
It either uses the first default gateway it decides to use, sometimes randomly and with weird results, or it loses the ability to connect altogether.
In Windows, it is a total misconfiguration and causes much grief.
You run a script using route delete
to remove default gateways (0.0.0.0) from all but the desired interface that will pass traffic to unknown subnets.
Basically, you want one default gateway and the rest will be gateways to specific subnets either internal or external.
For the non-default-gateway routes, you have to be very network specific. I.E. add a persistent route for the specific subnet you're trying to hit through that interface.
so if you do route print and you have persistent routes that read like
0.0.0.0 0.0.0.0 192.168.1.1 default 0.0.0.0 0.0.0.0 10.0.0.1 default
then you would change it to be more like
0.0.0.0 0.0.0.0 192.168.1.1 default 10.0.0.0 255.255.255.0 10.0.0.1 3 10.0.1.0 255.255.255.0 10.0.0.1 3
etc etc
the default gateway should be limited to the connection you use for your internet on most machines, but apply this however you need to to make it work.
Alternately, there are ways to make windows behave properly with RIP, but I don't use RIP on any of my networks so I'm not the one to explain how it works.
Windows doesn't automatically add default gateways for each network, they need to be explicitly added, either through the GUI, DHCP, or some other manipulation of the IP stack (e.g. "route add"). Ideally there should be one and only one default gateway configured.
-
1Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.– Community BotCommented Dec 15, 2021 at 13:46
the computer behaves sometimes correctly and sends packets to the right interfaces, sometimes it doesn't
doesn't tell us anything about what you mean. You need to give us more details. 2. Windows computers can't use multiple default gateways. - windows.microsoft.com/en-us/windows/…