Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 23127

Scripting • Re: Automatic NAT 1:1 Rules Update Script for PPPoE Connections

$
0
0
3. **No Interruption of Active Connections**: The script updates only new connections with the new external IP, leaving existing connections unaffected to avoid disruptions.
bullshit: if the IP changes, the previous connection to an IP that no longer exists doesn't make the slightest sense.

4. **Automatic Scheduling**: The script is configured to run periodically (e.g., every minute) through the MikroTik's scheduler, ensuring that the NAT 1:1 rules are always up-to-date.
bullshit: there is already the part for scripts in the pppoe profile, just use the appropriate function without creating useless scripts or schedulers.


The script is poorly thought out.
Ignoring orrorgraphy, it updates the IP every minute, causing unnecessary continuous writes to the internal memory.

Also ignoring that it is the wrong method, it should at least check first if ip is the same as before.
But surprise: specifying the IP in the firewall rule is useless without consider the rest of the context.
If the outgoing pppoe interface has only one IP, it doesn't make any sense to specify it, so is all useless.
Hi,

Thanks for your feedback on my script. You raised some valid points that I hadn't considered.

I agree that the script could be improved by checking the current IP before updating the NAT rule and avoiding updating the rule every minute.

However, I still believe that the script can be useful for automating the update of NAT 1:1 rules when the external IP changes. It is relevant to use NAT 1:1 in corporate environments, and you may not have yet dealt with a scenario where you needed to use it and the IP changes constantly on PPPoE.

I will make the following changes to the script to address your concerns:

Check the current IP before updating the NAT rule.
Increase the time interval between IP checks to avoid unnecessary writes to internal memory.

Thanks again for your feedback. I appreciate your help in making the script better.

# Obtém o endereço IP atual da interface PPPoE
:local pppoeAddr [/ip address get [find interface="pppoe" address]]

# Se o endereço IP atual for diferente do IP especificado na regra NAT, atualize a regra
if ($pppoeAddr != "/ip firewall nat get [find action=src-nat chain=srcnat out-interface="pppoe" to-addresses=1.2.3.4]") {
/ip firewall nat set [find action=src-nat chain=srcnat out-interface="pppoe" to-addresses=1.2.3.4] to-addresses=$pppoeAddr
}

Statistics: Posted by dbuzatto — Thu Mar 28, 2024 4:35 am



Viewing all articles
Browse latest Browse all 23127

Trending Articles