Set Gateway for Specific IP and Port – How to Configure Gateway for Specific Destination

netshnetworkingstatic-routeswindows

I have two internet connections. One has a static public ip address (WAN-STATIC gateway ip 10.0.0.1) and the other has a dynamic public ip address (WAN-DYNAMIC gateway ip 10.0.0.254). I wish to force traffic to specific ip addresses and ports to use WAN-STATIC. I tried to do this with a dual wan router but after a long telephone call with the support team it seems this is not possible in the router. I tried this:

 route add xxx.xxx.xxx.0 mask 255.255.255.0 10.0.0.1 metric 1

This redirects my traffic correctly but i also need to specify the port. For example traffic to xxx.xxx.xxx.1 on port 80 needs to use the default gateway and traffic on port 8080 needs a static route. My computers runs on windows 7.

Best Answer

As you've hinted in the question, you can statically route specific ranges/hosts via the operating system or router's routing tables.

Dynamically routing ports however, is not possible on Windows. Routing is a Layer 3 task, whereas ports are Layer 5. See the below diagram for more information:

enter image description here
(source: s-msft.com)

If you're determined, you can use a Linux router running the iptables firewall to re-route packets according to their port - you'll need separate routing tables to handle the specific ports, and then use fwmark to mark each packet. See this forum post as a starting point.