I have the following scenario:

Computer A: 198.51.100.8, netmask 255.255.255.0
Computer B: 203.0.113.9, netmask 255.255.255.0
Both computers are on the same LAN segment; no default gateway is specified in either case.

To get these two computers to communicate with each other, I've added two static routes, like so:

route add 203.0.113.9 mask 255.255.255.255 198.51.100.8

However, I would prefer to add the static routes by specifying a network interface, instead of by specifying a gateway IP address.

This is possible with Linux by using a command such as:

ip route add 203.0.113.9 dev eth0

and similarly in FreeBSD:

route add 203.0.113.9/32 -iface fxp0 -cloning

However, I'm at a loss of how to do this with Windows. Ideally I want to do something like:

route add 203.0.113.9 mask 255.255.255.255 if 2

but that merely prints out the usage for the route command, which tells me that I'm doing it wrong. I've also tried to use netsh, which tells me:

> netsh routing ip add persistentroute 203.0.113.9 255.255.255.255 "Local Area Connection"
Specify the next-hop for non point-to-point interfaces.

Any thoughts or suggestions?

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

This may not be possible with windows

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/route.mspx

Quote: For locally attached subnet routes, the gateway address is the IP address assigned to the interface that is attached to the subnet.

link|improve this answer
Hey Grizly -- thanks for the response! I tried both commands you suggested, but I got: "The route addition failed: Either the interface index is wrong or the gateway does not lie on the same network as the interface. Check the IP Address Table for the machine." I've only got two interfaces on the machine, 0x1 (MS TCP Loopback interface) and 0x2 (Intel(R) PRO/1000 MT Network Connection), so I'm pretty sure "if 2" is what I want to use. Any other thoughts? – fission Feb 23 '10 at 22:21
Just ignore the "metric 1 if 2" part.. it should figure it out. Best to test without -p as well. (that makes it persistent) – Grizly Feb 24 '10 at 7:29
I get the same result w/o the "metric 1 if 2" part. – fission Feb 24 '10 at 9:03
Ohh, my bad, seems the gateway is the ip of the interface.. answer updated. – Grizly Feb 24 '10 at 13:52
Right, which is what I am already doing, and what I was hoping to avoid. Thanks anyhow. – fission Feb 24 '10 at 19:11
show 2 more comments
feedback

Your Answer

 
or
required, but never shown

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