Community discussions

MikroTik App
 
levicki
newbie
Topic Author
Posts: 30
Joined: Mon Apr 30, 2018 12:22 pm
Location: Belgrade, Serbia
Contact:

[FR] A way to reference IP address on any interface in NAT

Sat Jun 23, 2018 12:22 am

It would be nice if MikroTik would add a variable that could be used in place of src-address, dst-address, or to-addresses in NAT commands.
Vyatta has this option where you can reference for example ADDRv4_eth2 to get current eth2 IP address anywhere in NAT rule and it is replaced and maintained transparently for the user.

I am aware this can be emulated with scripting and global variables, maybe even address lists, but still it would be more convenient and user friendly and greatly simplify port forwarding.

The reason why most people keep asking the same question over and over again ("how do I port forward / hairpin NAT with dynamic IP") in this forum is that they don't seem to understand that they need dst-address in dstnat and to-address in srcnat rules to be their public IP for this to work, nor they have any clue how to get the value there automatically.

If I am not mistaken, if you just want simple dstnat without hairpin / loopback then you can just specify in-interface and omit dst-address. But in order for hairpin / loopback to work you need to have dstnat on both LAN and WAN side which means you must leave out in-interface and specify the dst-address instead. Of course you also need the srcnat rule which also needs to-addresses so it makes sense to have variables that resolve to various interfaces IP addresses.

I propose adding something like this:
ether1_ipv4
ether2_ipv4
ether3_ipv4
...
ether7_ipv4
combo1_ipv4
Which could then be used in NAT rules without having to worry about resolving and updating.
 
Sob
Forum Guru
Forum Guru
Posts: 9121
Joined: Mon Apr 20, 2009 9:11 pm

Re: [FR] A way to reference IP address on any interface in NAT

Sat Jun 23, 2018 6:01 am

You don't need this if you're just after hairpin NAT. You can use dst-address-type=local and then exlude router's LAN address, i.e.:
/ip firewall nat
add chain=dstnat dst-address-type=local dst-address=!192.168.88.1 protocol=tcp dst-port=80 to-addresses=192.168.88.20
And then for hairpin NAT's srcnat rule, use either action=masquerade, or action=src-nat to-addresses=<some fake/virtual address to represent hairpinned conections>.

But your request is interesting. I'm not sure about magic variables, but I can imagine some automatically created address lists.

Who is online

Users browsing this forum: adimihaix, Bing [Bot], Extrems, vingjfg and 107 guests