When working with multiple network interfaces in Windows 7, you might encounter situations where you need to route traffic for specific IP addresses through a secondary interface while maintaining primary routing through your default gateway. This becomes particularly important when:
- Testing connectivity through different networks
- Accessing geographically restricted content
- Implementing failover scenarios
- Debugging multi-homed network configurations
Windows automatically assigns metrics to routes based on interface speed and configuration:
C:\>route print
===========================================================================
Interface List
11...00 1a 4b 6f 3a 1c ......Realtek PCIe GBE Family Controller
12...00 21 5c ab 1f 2d ......Intel(R) Centrino(R) Wireless-N 100
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.1.1.1 10.1.10.149 10
0.0.0.0 0.0.0.0 172.22.12.1 172.22.12.110 20
The standard route add
command doesn't work as expected because Windows automatically calculates the metric:
C:\>route add 140.239.191.10 mask 255.255.255.255 172.22.12.1 metric 1 if 12
OK!
C:\>route print
...
140.239.191.10 255.255.255.255 172.22.12.1 172.22.12.110 31
Notice how Windows overrides our specified metric of 1 and assigns 31 instead.
To properly force routing through a specific interface, we need to combine several techniques:
- First, delete any existing route (if present):
route delete 140.239.191.10
- Then add the persistent route with explicit interface binding:
route -p add 140.239.191.10 mask 255.255.255.255 172.22.12.1 if 12
- Manually adjust the interface metric (requires admin privileges):
netsh interface ipv4 set interface 12 metric=1
After implementing these changes, verify your routing table:
C:\>route print
...
140.239.191.10 255.255.255.255 172.22.12.1 172.22.12.110 1
Test connectivity to confirm routing is working as intended:
tracert 140.239.191.10
pathping 140.239.191.10
curl http://whatismyipaddress.com/
For more modern systems with PowerShell available, consider this more flexible approach:
# Remove existing route if needed
Remove-NetRoute -DestinationPrefix "140.239.191.10/32" -Confirm:$false
# Add new persistent route
New-NetRoute -DestinationPrefix "140.239.191.10/32" -InterfaceIndex 12
-NextHop 172.22.12.1 -RouteMetric 1 -PolicyStore ActiveStore
# Make persistent across reboots
New-NetRoute -DestinationPrefix "140.239.191.10/32" -InterfaceIndex 12
-NextHop 172.22.12.1 -RouteMetric 1 -PolicyStore PersistentStore
- Route not persisting: Ensure you use the -p flag or equivalent persistent option
- Interface index changing: Use
netsh interface show interface
to verify current indexes - Conflicting metrics: Check all routes with
route print
and adjust metrics accordingly - Firewall interference: Temporarily disable firewalls to test if they block the alternate route
When working with multiple network interfaces on Windows 7, you might encounter situations where you need to route traffic for specific IP addresses through a particular interface while maintaining your primary routing configuration. The standard routing table doesn't always make this straightforward.
Here's what your current routing table looks like:
Network Destination | Netmask | Gateway | Interface | Metric
0.0.0.0 | 0.0.0.0 | 10.1.1.1 | 10.1.10.149 | 10
0.0.0.0 | 0.0.0.0 | 172.22.12.1 | 172.22.12.110 | 20
The initial approach using the route add
command:
route add 140.239.191.10 mask 255.255.255.255 172.22.12.1 metric 1 if 12
Results in this unexpected entry:
140.239.191.10 | 255.255.255.255 | 172.22.12.1 | 172.22.12.110 | 31
Windows automatically assigns a metric of 31 to host-specific routes, which causes the traffic to still go through the Ethernet interface (metric 10) instead of the WLAN interface. This happens because Windows always prefers the route with the lowest metric.
To properly route the specific IP through your WLAN interface, you need to use this command:
route -p add 140.239.191.10 mask 255.255.255.255 172.22.12.1 if 12 metric 5
The -p
flag makes the route persistent across reboots. The metric 5 (or any value lower than your Ethernet's default gateway metric) ensures this route takes precedence for the specified IP.
After adding the route, verify it with:
route print
Check connections to your target IP with:
tracert 140.239.191.10
For more advanced control, you can use the netsh
command:
netsh interface ipv4 add route 140.239.191.10/32 "Wireless Network Connection" 172.22.12.1 metric=5 store=persistent
- Always run Command Prompt as Administrator
- Double-check interface indexes using
route print
- Remember that changes might take a few seconds to apply
- If issues persist, try temporarily disabling then re-enabling the network interface