Community discussions

MikroTik App
 
nmaton
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 72
Joined: Fri Feb 18, 2011 12:31 am

change out interface in ip firewall nat

Sat Mar 09, 2013 11:22 pm

I'm unable to change the out-interface in ip firewall nat with a script.

I have the following set in a script :

/ip firewall nat set numbers=9 out-interface=<pptp-test>



When i issue that command in terminal the out-interface gets adjusted but not when it's run from a script.
Any ideas on how to change this ?


thanks
 
ditonet
Forum Veteran
Forum Veteran
Posts: 835
Joined: Mon Oct 19, 2009 12:52 am
Location: Europe/Poland/Konstancin-Jeziorna
Contact:

Re: change out interface in ip firewall nat

Sun Mar 10, 2013 12:35 am

Add comment to this NAT rule (e.g. 'my_NAT_rule') and use following command:

ros code

/ip firewall nat set [find comment="my_NAT_rule"] out-interface=<pptp-test>
HTH,
 
User avatar
jgellis
Member Candidate
Member Candidate
Posts: 140
Joined: Wed May 30, 2007 10:57 am
Location: USA

Re: change out interface in ip firewall nat

Sun Mar 10, 2013 1:26 am

ditonet is correct.

The "number" attribute you see when printing in the terminal (i.e. 9 in your script) is not a configuration item on the nat rules. They are generated during a print command only. To set or get any values in a script you should always use the [find] command to narrow your results. [find] by itself would return all nat rules in this case, [find comment="blah"] would return only those with that exact comment, [find comment="blah" chain=forward] would return... well you probably get it by now.

If you cannot find it dynamically/uniquely using attributes set within the rule, then I do exactly what ditonet suggests, give it a unique comment and [find] it by that.
 
nmaton
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 72
Joined: Fri Feb 18, 2011 12:31 am

Re: change out interface in ip firewall nat

Sun Mar 10, 2013 1:41 am

Great info thank you all.
I had no idea scripting worked that way.

Thanks again :)