Batch - Windows Network Gateway Configuration


When you got 2 NIC on the same VM, one is Internal NIC, another is External NIC:

  • Internal:
  • External:

When you are trying to talk to out side of any of these 2 subnet, for example:,, etc…

The correct NIC the traffic should go through is via External. But somehow, you might be see this when you do route print:


We can see there are Double entries with same metric value as default gateway.

We need to do 2 things:

route –f –p -4 add mask metric 5

This will clear all existing gateway information but only the one we added

shutdown /r /t 10

restart the computer in 10 seconds, enough time for the script to be renamed, this will help to rebuild the route table

Make sure run this as a batch cmd, because you will lost connectivity if you are in the RDP session…

Enjoy scripting…