Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

At our company we have 2 gateways: 192.168.1.1 and 192.168.1.2

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.

E.g.:

[192.168.1.1]
192.168.*
*domain.com
*domain2.com

[192.168.1.2]
everything else
share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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

You add static routes like this:

    > route ADD 157.0.0.0 MASK 255.0.0.0  157.55.80.1 METRIC 3 IF 2
             destination^      ^mask      ^gateway     metric^    ^
                                                         Interface^

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., 255.255.255.0 is the subnet mask for the 192.168.1.0 network with a 24-bit routing prefix (192.168.1.0/24).

share|improve this answer
    
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
add comment

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

route ADD 192.168.2.0 MASK 255.255.255.0 192.168.1.2 METRIC 1

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.