Community discussions

MikroTik App
 
MADM1k3
just joined
Topic Author
Posts: 1
Joined: Thu Apr 25, 2024 8:36 pm

Dynamic port forwarding

Thu Apr 25, 2024 8:41 pm

Simple problem, but couldn't find anything in existing threads.
I have 2 same servers behind NAT with all the necessary ports forwarded to 1 of them. If one goes down, i manually change port forwarding to the 2nd server.
Is it possible, to setup port forwarding with DOWN detection, so if the 1st server goes down, ports would automatically forwarded to the 2nd server?
Thanks!
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19674
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Dynamic port forwarding

Thu Apr 25, 2024 11:47 pm

Why does a server go down? Makes no sense.
 
User avatar
mkx
Forum Guru
Forum Guru
Posts: 11760
Joined: Thu Mar 03, 2016 10:23 pm

Re: Dynamic port forwarding

Thu Apr 25, 2024 11:57 pm

Why does a server go down? Makes no sense.
There are many reasons for server to go down ... one is that it emits smoke. Snd what @OP wants to do is a "poor man's high-availability". I'm affraid that out of the box, ROS doesn't have such functionality. But there's always possibility to create some script which checks one server and if it fails to respond, reconfigure DST-NAT rules to redirect traffic to the other server. And vice versa.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3610
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Dynamic port forwarding

Fri Apr 26, 2024 4:41 am

Yeah /tool/netwatch is the "poor mans" way of HA. See https://help.mikrotik.com/docs/display/ROS/Netwatch


Basically you can ping your primary server using netwatch, and have an "on-down" script that modifies the firewall to change the to-address to the 2nd servers. And also an "on-up" script that then changes same dst-nat rules to-address back to 1st servers.
e.g. basically a few "set" operation in on-up or up-down, with one for each dst-nat your using in the general form:
/ip/firewall/nat/set [find protocol=tcp dst-port=XXX] to-address=<server>


I suppose another alternative be setting up VRRP on the servers themselves, and RouterOS using the VRRP address for dst-nat.
 
User avatar
k6ccc
Forum Guru
Forum Guru
Posts: 1510
Joined: Fri May 13, 2016 12:01 am
Location: Glendora, CA, USA (near Los Angeles)
Contact:

Re: Dynamic port forwarding

Fri Apr 26, 2024 6:31 pm

There are many reasons for server to go down ... one is that it emits smoke.
I actually had that happen once - although it was running as a server (and a server OS) it was actually a dell tower. Everything after that that was running as a server was a "real" server machine. The first of which came with 14 internal fans. You could hear it reboot from across the street because all 14 fans came up to full speed - SCREAM. Got me highly motivated to build my data cabinet out in the garage.

To get back on topic, I have used the "poor mans HA". It does work.

Who is online

Users browsing this forum: Google [Bot], shadowEvil and 22 guests