Community discussions

MikroTik App
 
Wazza
newbie
Topic Author
Posts: 45
Joined: Thu Oct 13, 2011 10:43 am

DSTNAT to multiple addresses - load balancing?

Tue Dec 06, 2016 4:47 pm

Okay, so I have a requirement to redirect an inbound connection. Basically a dstnat rule, to an address.

What I'd like however is to redirect to a list of addresses, and have it round robin them in some way:-
/ip firewall nat
add action=dst-nat chain=dstnat dst-address=123.123.123.123 dst-port=25 \
    in-interface=public protocol=tcp to-addresses=10.10.10.20 to-ports=25
add action=dst-nat chain=dstnat dst-address=123.123.123.123 dst-port=25 \
    in-interface=public protocol=tcp to-addresses=10.10.10.30 to-ports=25
add action=dst-nat chain=dstnat dst-address=123.123.123.123 dst-port=25 \
    in-interface=public protocol=tcp to-addresses=10.10.10.40 to-ports=25
add action=dst-nat chain=dstnat dst-address=123.123.123.123 dst-port=25 \
    in-interface=public protocol=tcp to-addresses=10.10.10.50 to-ports=25
add action=dst-nat chain=dstnat dst-address=123.123.123.123 dst-port=25 \
    in-interface=public protocol=tcp to-addresses=10.10.10.60 to-ports=25
Is something like that doable?
The idea being that I can spread the load, and possibly use some scripting / netwatch to identify if any of the destinations is offline, and disable the specific target rule, taking it out of rotation.

Note also, I don't particularly want to use a range of IP addresses (123.123.123.10-123.123.123.50), but rather a non continuous list.

Thoughts?
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: DSTNAT to multiple addresses - load balancing?

Tue Dec 06, 2016 7:29 pm

Using nth= option should work, at least a quick test in my local network did:
/ip firewall nat
add action=dst-nat chain=dstnat dst-address=<pubaddr> dst-port=80 nth=3,1 protocol=tcp to-addresses=192.168.80.1
add action=dst-nat chain=dstnat dst-address=<pubaddr> dst-port=80 nth=3,2 protocol=tcp to-addresses=192.168.80.40
add action=dst-nat chain=dstnat dst-address=<pubaddr> dst-port=80 nth=3,3 protocol=tcp to-addresses=192.168.80.70
Or per-connection-classifier=src-address-and-port:x/y is another option.
 
rftnon
newbie
Posts: 29
Joined: Fri Feb 28, 2014 6:34 pm

Re: DSTNAT to multiple addresses - load balancing?

Tue Jan 30, 2018 8:25 pm

This is an important post ...
 
marktomlinson
newbie
Posts: 35
Joined: Wed Aug 03, 2016 12:22 pm

Re: DSTNAT to multiple addresses - load balancing?

Thu Jul 05, 2018 5:35 pm

Hi All

Sorry to re-open an old thread, however I am looking to do something similar and wondered if there was an option to do this with some kind of affinity?

Mark
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: DSTNAT to multiple addresses - load balancing?

Thu Jul 05, 2018 6:07 pm

I think it's job for real load balancer, but as poor man's alternative, per-connection-classifier=src-address:x/y should work too.