Route to interface, interfaces have same subnets

Hi,

I need to connect 4 “industry machines”. Everyone use same subnets 192.168.0.0, network device inside macihne have same static IP and I’cant change them. Inside machine is switch whitch networking two internal devices (192.168.0.2, 192.168.0.3) and some device for managing machine.

Managing this machine means connect them with TCP on IP 192.168.0.2 port 1234 and push some data. (Which is step one. Step two i the same on port 1235).

My idea is to make connection to 192.168.2.2 (ether1/LAN IP of routerboard ether1) on port 12341. Routerboard will translate this connection to 192.168.0.2 on machine1/ether2 to port 1234. (port 12342 come to machine2:port1234, port 12343 come to machine3:port1234, etc.).

Is possible to do same magic on routerboard to make it work?
4machine.png

Could it be so: put router to each machine, set nat with internal network for machine and external to your network. Then port translation will work. Looking from your network it will look like the machines have their own unique ip.

I’ll find a way.

  1. mangle packet with machine-specific routing mark (as it has specific port)
  2. routing to machine-interface using routing mark

Mangle:

/ip firewall mangle print 
Flags: X - disabled, I - invalid, D - dynamic 
 0   chain=prerouting action=mark-routing new-routing-mark=shark1 passthrough=yes 
     protocol=tcp dst-port=12341,12351 

 1   chain=prerouting action=mark-routing new-routing-mark=shark2 passthrough=yes 
     protocol=tcp dst-port=12342,12352 

 2   chain=prerouting action=mark-routing new-routing-mark=shark3 passthrough=yes 
     protocol=tcp dst-port=12343,12353 

 3   chain=prerouting action=mark-routing new-routing-mark=shark4 passthrough=yes 
     protocol=tcp dst-port=12344,12354

Routing:

/ip route print 
Flags: X - disabled, A - active, D - dynamic, 
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, 
B - blackhole, U - unreachable, P - prohibit 
 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 A S  192.168.0.0/24                     ether2-shark1             1
 1 A S  192.168.0.0/24                     ether3-shark2             1
 2   S  192.168.0.0/24                     ether4-shark3             1
 3   S  192.168.0.0/24                     ether5-shark4             1
 4 ADC  192.168.0.0/24     192.168.0.22    ether2-shark2             0
                                           ether3-shark1     
                                           ether4-shark3     
                                           ether5-shark4     
 5 ADC  192.168.2.0/24     192.168.2.2     ether1-gateway            0

Looks, that it works.

Jarda: thx for reply. Yes, this will be more “normal” solution. But uses more routers.