I’m attempting to create a script that will automatically configure 1:1 NAT assignments in a range. Is it possible to have more than one variable with :for?
The issue I have is that I need 2 variables created since the range for each variable is different, however they both increment by 1.
Here’s what I’m attempting to create:
:for i from 101 to 200 do={/ip firewall nat add action=src-nat chain=srcnat src-address=“xx.yy.$i.zz” to-addresses=“xxx.yyy.zzz.$u)”}
$u being the 2nd variable that needs to have its own range. How would I specify? Is it possible to create a script this way?
Thanks for the reply. I tested that, however it doesn’t work entirely well (a move in the right direction however)…
I ran a test as follows:
:for i from=101 to=120 do={
:for u from=11 to=30 do={
/ip firewall nat add action=src-nat chain=srcnat src-address=“10.50.$i.2” to-addresses=“192.168.200.$u”
}
}
I ended up getting a pattern like this:
10.50.101.2 → 192.168.200.11
10.50.101.2 → 192.168.200.12
10.50.101.2 → 192.168.200.13
etc (continues through the full range of 192.168.200.11 - 192.168.200.30)
So what exactly is the relationship between $i and $u? Is there a common rule that they both match? If so, you may as well do arithmetic.
If I’m guessing correctly, it seems the src-address is always “100 + $i”, while the to-address is always “10 + $i”, so:
:for i from=1 to=100 do={
/ip firewall nat add action=src-nat chain=srcnat src-address=(“10.50.” . (100 + $i) . “.2”) to-addresses=(“192.168.200.” . (10 + $i))
}The above should generate
10.50.101.2 → 192.168.200.11
10.50.102.2 → 192.168.200.12
etc. up to and including
10.50.200.2 → 192.168.200.110