0

I have two subnets in local network - I need access from one to second via local ports without using gateway.

In linux I'm using this:

ip route add 90.5.5.0/24 dev eth0 (server have IP e.g. 91.6.6.5). Data are sending directly to MAC - "so stay in router only".

How can I set this in windows too please?

Thank you Pavel

EDIT: this is not duplicate with Specify route to an interface in Windows cmd - my problem is about two /24 subnets from one interface in one local physically network - I dont need use gateway to reach second subnet - but how?

Pavel
  • 487

2 Answers2

1

You're assuming that Windows networking stack is implemented exactly the same and with the same optimizations as the Linux networking stack. This is not necessarily true.

But if I've understood correctly, you'll first want to use netsh interface ipv4 show interfaces to identify the number of the interface you wish to attach the route specification to. I'll use [IFnumber] identify this number.

Then, if the system's own IP address is 91.6.6.5, then the route entry for telling that the 90.5.5.0/24 network is also directly connected through the same NIC, the syntax would be:

route add 90.5.5.0 mask 255.255.255.0 91.6.6.5 IF [IFnumber]

In other words: in the syntax of Windows route command it is mandatory to specify the gateway IP address. But if you don't want to use a gateway, then you'll need to specify the interface's own IP address in place of the gateway, to satisfy the syntax requirements.

You can try this and see if it works. If you do route print, it should now say the 90.5.5.0 network is "On-link" for the same interface that has the 91.6.6.5 IP address. Add a -p option to the command to store the route persistently, if you want.

But if it doesn't work, you should recognize that this is a non-standard way to do IP networking and is not guaranteed to be successful in all implementations. It will also cause the packets sent from this system to the 90.5.5.0/24 segment to have a technically invalid source IP address; but if the systems only look at Layer-2 addressing ("sending directly to MAC"), it may work. If either end has a software firewall that has a built-in filter for invalid packets, that could easily be a showstopper for this technique.

The normal way to handle this would be to add a secondary IP address (within the 90.5.5.0/24 segment) to the network interface. Adding that IP would automatically add a similar route to the routing table, and it would ensure that there is a valid source IP address to use when sending packets to the 90.5.5.0/24 segment.

telcoM
  • 4,876
0

If you don't need to use a gateway to reach the other network you don't need routing and you can just add a second IP to your NIC.

IPv4 properties -> Advanced... -> IP Addresses:Add...

If you are thinking about port forwarding between two connected networks it could be done with:

netsh interface portproxy add v4tov4 listenport=4422 listenaddress=192.168.1.111 connectport=80 connectaddress=192.168.0.33