Setup NAT to reach multiple VLANS with overlapping subnets

I preface this with saying I am an electrical / software engineer who knows some networking but not a huge amount of experience with configuring routers, especially more complex routing rules.

We have some industrial products that are composed of a number of devices each with their own static IP. In general these machines are never connected to any external networks, except occasionally a technicians laptop for debugging purposes.

To make software project management easier for technicians usually each device within the product will have the same address. For any of these identical assemblies you can expect to be able to plug in and connect to a certain device at a certain address. This also allows exactly the same software to be loaded onto any instance of a machine without needing to update the addresses for every device.

We have had some situations where for factory testing purposes we would like to be able to connect multiple of these systems to one test bench for logging and control purposes.

A colleague mentioned that this should be achievable with some of the Mikrotik devices so I purchased a cheapskate E60iUGS to have a play with and learn.

My aim is to setup the following functionality

  • Each machine is plugged into any of the ports (1-4)
    • No DHCP on these networks
    • These networks cannot access outwards to any other machine networks or the logging network
  • Logging PC is connected to one port of the router (Port 5)
    • DHCP is setup to assign addresses in the range 10.0.0.100-10.0.0.254
    • Requests for 10.0.x.y will be routed/translated to the Port X network as 192.168.0.y

I.e. If I have a PC connected to the logging network it will be then able to connect to an address like 192.168.2.51 which would then be directed through to the second test stand and translated to an address like 192.168.0.51

I have been working through the help as best I can along with the following forum posts.

And the below is what I have come up with so far, but I don’t seem to be able to get any traffic to work from the logging PC to a device on one of the machine networks. Is anybody able to offer me some pointers to where I might be going wrong. I am green enough with RouterOS that some pointers on how this could be debugged would be much appreciated as well.

# 2025-03-11 05:51:25 by RouterOS 7.18.2
# software id = F8TY-SD07
#
# model = E60iUGS

/interface ethernet
set [ find default-name=ether1 ] name=ether1_Stand1
set [ find default-name=ether2 ] name=ether2_Stand2
set [ find default-name=ether5 ] name=ether5_Logging

/ip pool
add name=dhcp_pool0 ranges=10.0.0.100-10.0.0.254

/ip dhcp-server
add address-pool=dhcp_pool0 interface=ether5_Logging name=dhcp1

/ip vrf
add interfaces=ether1_Stand1 name=VRF-Stand1
add interfaces=ether2_Stand2 name=VRF-Stand2

/ip neighbor discovery-settings
set discover-interface-list=!dynamic

/ip address
add address=192.168.0.1/24 interface=ether1_Stand1 network=192.168.0.0
add address=192.168.0.1/24 interface=ether2_Stand2 network=192.168.0.0
add address=10.0.0.1/24 interface=ether5_Logging network=10.0.0.0

/ip dhcp-server network
add address=10.0.0.0/24 gateway=10.0.0.1

/ip firewall mangle
add action=mark-connection chain=prerouting connection-state=new dst-address=10.0.1.0/24 in-interface=ether5_Logging new-connection-mark=from-logging-to-VRF-Stand1
add action=mark-routing chain=prerouting dst-address=10.0.1.0/24 new-routing-mark=VRF-Stand1
add action=mark-routing chain=prerouting connection-mark=from-logging-to-VRF-Stand1 in-interface=VRF-Stand1 new-routing-mark=main passthrough=no

add action=mark-connection chain=prerouting connection-state=new dst-address=10.0.2.0/24 in-interface=all-ethernet new-connection-mark=from-logging-to-VRF-Stand2
add action=mark-routing chain=prerouting dst-address=10.0.2.0/24 new-routing-mark=VRF-Stand2
add action=mark-routing chain=prerouting connection-mark=from-logging-to-VRF-Stand2 in-interface=VRF-Stand2 new-routing-mark=main passthrough=no

/ip firewall nat
add action=netmap chain=dstnat dst-address=10.0.1.0/24 to-addresses=192.168.0.0/24
add action=netmap chain=dstnat dst-address=10.0.2.0/24 to-addresses=192.168.0.0/24

/ip route
add dst-address=10.0.1.0/24 gateway=ether1_Stand1@VRF-Stand1
add dst-address=10.0.2.0/24 gateway=ether2_Stand1@VRF-Stand2

/system note
set show-at-login=no

See this thread:

1:1 NAT / DNAT configuration help - RouterOS / Beginner Basics - MikroTik community forum

Here is a guide based on the thread:

Quick Guide: Bidirectional 1:1 NAT (SNAT, DNAT) Setup w/ working example - RouterOS / Useful user articles - MikroTik community forum

1 Like

For what its worth I managed to find my issue with the help of our AI overlord which is pretty scary in itself. There were two key issues in my script, one a typo, and two missing the NAT masquerade rules for return traffic.

Below is what I got working.

# --- 1. Interfaces, VRFs & Addresses ---
/interface ethernet
set [ find default-name=ether1 ] name=ether1_Stand1
set [ find default-name=ether2 ] name=ether2_Stand2
set [ find default-name=ether5 ] name=ether5_Logging

/ip vrf
add interfaces=ether1_Stand1 name=VRF-Stand1
add interfaces=ether2_Stand2 name=VRF-Stand2

/ip address
add address=192.168.0.1/24 interface=ether1_Stand1 network=192.168.0.0
add address=192.168.0.1/24 interface=ether2_Stand2 network=192.168.0.0
add address=10.0.0.1/24 interface=ether5_Logging network=10.0.0.0

# --- 2. DHCP for Logging PC ---
/ip pool
add name=dhcp_pool0 ranges=10.0.0.100-10.0.0.254
/ip dhcp-server
add address-pool=dhcp_pool0 interface=ether5_Logging name=dhcp1

# --- 3. Mangle Marking ---
/ip firewall mangle
# Logging Interface -> Stand 1
add action=mark-connection chain=prerouting connection-state=new dst-address=10.0.1.0/24 in-interface=ether5_Logging new-connection-mark=from-logging-to-VRF-Stand1
add action=mark-routing chain=prerouting dst-address=10.0.1.0/24 in-interface=ether5_Logging new-routing-mark=VRF-Stand1
add action=mark-routing chain=prerouting connection-mark=from-logging-to-VRF-Stand1 in-interface=VRF-Stand1 new-routing-mark=main passthrough=no

# Logging Interface -> Stand 2
add action=mark-connection chain=prerouting connection-state=new dst-address=10.0.2.0/24 in-interface=ether5_Logging new-connection-mark=from-logging-to-VRF-Stand2
add action=mark-routing chain=prerouting dst-address=10.0.2.0/24 in-interface=ether5_Logging new-routing-mark=VRF-Stand2
add action=mark-routing chain=prerouting connection-mark=from-logging-to-VRF-Stand2 in-interface=VRF-Stand2 new-routing-mark=main passthrough=no

# --- 4. NAT (Forwarding & Masquerade) ---
/ip firewall nat

# ether5 Netmap (Logging PC Access)
add action=netmap chain=dstnat dst-address=10.0.1.0/24 to-addresses=192.168.0.0/24
add action=netmap chain=dstnat dst-address=10.0.2.0/24 to-addresses=192.168.0.0/24

# Masquerade (Allows stands to reply via router IP)
add action=masquerade chain=srcnat out-interface=ether1_Stand1
add action=masquerade chain=srcnat out-interface=ether2_Stand2

# --- 6. Housekeeping ---
/ip neighbor discovery-settings set discover-interface-list=!dynamic
/system note set show-at-login=no

1 Like

Congrats to you (and your AI)! You've found one of the more consistent and nice ways of going about this.

Just for the OCD in me, I'd just remark that the first mark-routing rule

add action=mark-routing chain=prerouting dst-address=10.0.1.0/24 in-interface=ether5_Logging new-routing-mark=VRF-Stand1

can be changed to also use the connection mark for matching, making the configuration a bit more consistent:

add action=mark-routing chain=preroutingconnection-mark=from-logging-to-VRF-Stand1 in-interface=ether5_Logging new-routing-mark=VRF-Stand1

This, of course, has the same (correct) effect.

There's another quality of life improvement that can be easily achieved. I would think that it's common for your operators to want to connect to an outside network (maybe over WiFi) and the network provided by your router at the same time. This obviously leads to issues, because the default route of that PC is captured by either of the two connections. This can be helped by not providing a default route from your router, but only providing specific routes to the destinations it actually wants to capture traffic to using the classless route (121) DHCP option. It goes something like this:

/ip dhcp-server option
add code=121 name=classless value="'24''10''0''1''10.0.0.1''24''10''0''2''10.0.0.1'"
/ip dhcp-server network
add address=10.0.0.0/24 dhcp-option=classless dns-none=yes ntp-none=yes

BTW, I don't really know if it's just missing from your export, but you should have a dhcp network configured.