Community discussions

MikroTik App
 
LaZyLion
newbie
Topic Author
Posts: 32
Joined: Fri May 09, 2014 10:27 am

Question about srcnat

Thu Nov 05, 2015 5:22 am

Hi all,

Ever since I started working with RouterOS, I've wondered why is it necessary to specify the "out-interface" in the srcnat firewall rule?
/ip firewall nat 
	add   chain=srcnat    out-interface=ether1     action=masquerade   
	add   chain=srcnat    out-interface=ether2     action=masquerade    
	add   chain=srcnat    out-interface=ether3     action=masquerade   

Every example I see does it this way.

I've tested it both with and without in a multi-wan load balance situation and it didn't seem to make an difference.


My reasoning is this:

The packet is already in the srcnat table so we know it is going "out".

We already know what interface it is going out; the rule uses "out-interface" for matching,
not for providing information to the Action.

In a multi-wan setup, the action is the same is the same in all four rules: "action=masquerade". Nothing else is specified for Action so it is evidently able to extract whatever information it needs from the packet header itself.

Is there some reason we can't just use:
/ip firewall nat    add   chain=srcnat     action=masquerade   
Wouldn't this be more efficient?

Thanks all.
 
User avatar
docmarius
Forum Guru
Forum Guru
Posts: 1224
Joined: Sat Nov 06, 2010 12:04 pm
Location: Timisoara, Romania
Contact:

Re: Question about srcnat

Thu Nov 05, 2015 7:59 am

And this will mean that incoming WAN packets which will go to your LAN (out-interface=<LAN>) will be masqueraded to the internal LAN IP and every external host will appear local to the LAN (src address will be the router). The same will happen if you have more than 1 LAN and want to route between them. If this is really what you want it should be OK.
 
LaZyLion
newbie
Topic Author
Posts: 32
Joined: Fri May 09, 2014 10:27 am

Re: Question about srcnat

Mon Nov 09, 2015 9:44 pm

I see. So the srcnat chain is not restricted to packets that are leaving the router via a wan port.
Hence to need to specify the out-interface so that only packets leaving via wan get masked.

Thank you.


But could the same effect be had using:
/ip firewall nat add chain=srcnat src-address-type=!local action=masquerade
thus reducing the need for multiple rules in a multi-wan situation?

Or would "address type not local" not cover everything we need it to?
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Question about srcnat

Mon Nov 09, 2015 10:41 pm

No, local in src-address-type means address owned by router, so src-address-type=!local still covers every other address on internet and your LAN, everything except what your router has. You might have success with out-interface=!<LAN> (if you have just one LAN), but it's prone to later mistakes, e.g. when you add VPN connection.

Who is online

Users browsing this forum: No registered users and 11 guests