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
  • 397
  • 6
  • 16
  • 2
    Possible duplicate of [Specify route to an interface in Windows cmd](https://serverfault.com/questions/818169/specify-route-to-an-interface-in-windows-cmd) – Lenniey Mar 27 '18 at 14:30
  • I dont think - see my edit please. – Pavel Mar 28 '18 at 06:02
  • So you just need to access both subnets from one physical NIC? Sorry, I don't follow...maybe it's too early in the day, but then I don't understand the correlation between `ip route add 90.5.5.0/24 dev eth0`, `I have two subnets in local network` and the question. – Lenniey Mar 28 '18 at 07:34
  • Sorry, maybe my bad english is problem:). But yes. I have this two servers in one local phys. network. One server have e.g. 91.6.6.5 (from /24) and second have 90.5.5.81 (from /24). What I need is that traffic will sent direct to router port from both servers. Now traffic go to gateway first which is another router in network and this saturates router port which is connected to gateway. – Pavel Mar 28 '18 at 07:44
  • So: `s1 eth0=192.168.0.1, eth1=91.6.6.5`, `s2 eth0=192.168.0.2, eth1=91.5.5.81`, for example? And both should send their traffic to a special router, and not the serves default gateway? – Lenniey Mar 28 '18 at 07:58
  • In this case is not solution use local network IP - because cloud software. It is more complicated. I need solution as on linux :). There is not problem this. – Pavel Mar 28 '18 at 08:33
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/75178/discussion-between-lenniey-and-pavel). – Lenniey Mar 28 '18 at 08:45

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,153
  • 12
  • 23
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
  • This are IPs from public subnets - I'd like save this IPs. This situation is on more servers. It is possible on Linux - so in Windows must be some way to solved this with some static route which will fill ARP entries from second subnet. :-) – Pavel Mar 28 '18 at 06:41