At our company we have 2 gateways: and

Is there a way to configure my machine to use different gateway based on a list of IP addresses/domains? My current solution is to go to the network card TCP/IP properties and change the gateway there manually.



everything else

On Windows, the Routing table is accessible with the route command.

You add static routes like this:

    > route ADD MASK METRIC 3 IF 2
             destination^      ^mask      ^gateway     metric^    ^

To learn about using masks (or CIDR, e.g. /24) see the Subnetwork entry.

A routing prefix is the sequence of leading bits of an IP address that precede the portion of the address used as host identifier. In IPv4 networks, the routing prefix is often expressed as a "subnet mask", which is a bit mask covering the number of bits used in the prefix. An IPv4 subnet mask is frequently expressed in quad-dotted decimal representation, e.g., is the subnet mask for the network with a 24-bit routing prefix (

  • Is there a wildcard character? E.g. 192.168.*.* or do I have to add 256^2 static routes? – daremon May 27 '09 at 13:15
  • Yes. The mask is effectively the wild card. 255 means use that octet, 0 means wild. – Orihara May 27 '09 at 16:56
  • Added ref to subnets and masks. – gimel May 27 '09 at 18:03

Not by domains, but what you're asking is standard routing. To add a route so that all packets to go via in Windows is this:


Remember that you can only control outgoing packets and not the return path (obviously if NAT is involved things change)


You could setup a third router between your 2 existing routers and the rest of the computers. Then use the that third router as a traffic copy to direct some traffic one direction and some the other direction. If you choose to setup Linux on that third system you can do some pretty advanced policy routing. You can direct traffic by protocol, by port, by source address, or basically anything that you could identify and mark with an iptables rule.

See the LARTC Howto.

I currently have an open question looking for tools to make managing the advanced routing system easier, but I haven't seen many answers. I have mostly given up and started to build my own tool, but it isn't ready to share yet.

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.