Community discussions

MikroTik App
 
guru431
just joined
Topic Author
Posts: 15
Joined: Fri Nov 29, 2019 10:37 am

Using a gateway from a different subnet

Mon Mar 25, 2024 10:06 pm

Help me to solve the problem.
Below is a simplified diagram of my network.
Image
There is a main router (R1) to access the internet.
Also there are 2 additional channels - Through router R3 and through VPN to VPS.
There is a need sometimes to output PC through additional channels.
I do this through mangle rules configured on routers R1 and R2:
/routing/table/add name=route_to_VPS fib
/ip route add distance=1 gateway=192.168.1.20 routing-table=route_to_VPS
/ip firewall mangle add action=mark-routing chain=prerouting comment="Mark comp to VPS" dst-address-list=!my_int_ip in-interface-list=LAN new-routing-mark=route_to_VPS passthrough=no src-address-list=comp_to_VPS

/routing/table/add name=route_to_R3 fib
/ip route add distance=1 gateway=192.168.50.1 routing-table=route_to_R3
/ip firewall mangle add action=mark-routing chain=prerouting comment="Mark comp to R3" dst-address-list=!my_int_ip in-interface-list=LAN new-routing-mark=route_to_R3 passthrough=no src-address-list=comp_to_R3
These rules work great for computers on the 192.168.1.0/24 subnetwork.
But from subnet 192.168.15.0/24 only redirection to VPS works.
I successfully ping the gateway 192.168.50.1 from PC3 and PC4, but I can't use it as a gateway
I have tried to add routes:
/ip route
add distance=1 gateway=192.168.50.1 routing-table=route_to_R3 scope=40 target-scope=30
add distance=1 dst-address=192.168.50.0/24 gateway=192.168.1.1 routing-table=main scope=30 target-scope=10
But that doesn't work either.

Can you tell me how to make it so that I can use gateway 192.168.50.1 on the R2 router?
 
guru431
just joined
Topic Author
Posts: 15
Joined: Fri Nov 29, 2019 10:37 am

Re: Using a gateway from a different subnet  [SOLVED]

Thu Mar 28, 2024 8:50 am

I found a solution.
It is necessary to add an additional IP address to the WAN interface of router R2 and route traffic to R3 via this address using SNAT.

Settings on router R2:
/routing/table/add name=route_to_R3 fib
/ip address add address=192.168.1.11/24 interface=ether1 network=192.168.1.0
/ip firewall nat add action=src-nat chain=srcnat place-before=0 to-addresses=192.168.1.11 routing-mark=route_to_R3
/ip firewall mangle add action=mark-routing chain=prerouting comment="Mark comp to R3" dst-address-list=!my_int_ip in-interface-list=LAN new-routing-mark=route_to_R3 passthrough=no src-address-list=comp_to_R3

Settings on the R1 router:
/ip firewall address-list add address=192.168.1.11 list=comp_to_R3

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot], Jhonny and 27 guests