Difference between revisions of "UPnP Multi-WAN"

From MikroTik Wiki
Jump to: navigation, search
m
m
Line 1: Line 1:
1. Make the simplest UPnP config for just WAN1.
+
* 1. Make the simplest UPnP config for just WAN1
 +
 
 +
* 2. Add the following script as a schedule: will clone UPnP Dynamic NAT entries as normal NAT entries for WAN2.
 +
Schedule time can be every minute.
  
2. Add the following script: will clone UPnP NAT entries from WAN1 as normal NAT entries for WAN2:
 
(Schedule every few minutes)
 
 
(set <WAN2 IP> manually)
 
(set <WAN2 IP> manually)
  
 
+
<pre>
 
:global UPnPs [/ip fi nat find dynamic]; :if ($UPnPs != $UPnPz) do={ :global UPnPz; :set $UPnPz $UPnPs; /ip fi nat remove [/ip fi nat find comment="UPnP_Cloned"]; :foreach i in=([/ip fi nat find dynamic]) do={/ip fi nat add chain=dstnat dst-address="<WAN 2 IP>" protocol=[/ip fi nat get $i protocol] to-addresses=[/ip fi nat get $i to-addresses] to-ports=[/ip fi nat get $i to-ports] action=dst-nat dst-port=[/ip fi nat get $i dst-port] comment="UPnP_Cloned"}}
 
:global UPnPs [/ip fi nat find dynamic]; :if ($UPnPs != $UPnPz) do={ :global UPnPz; :set $UPnPz $UPnPs; /ip fi nat remove [/ip fi nat find comment="UPnP_Cloned"]; :foreach i in=([/ip fi nat find dynamic]) do={/ip fi nat add chain=dstnat dst-address="<WAN 2 IP>" protocol=[/ip fi nat get $i protocol] to-addresses=[/ip fi nat get $i to-addresses] to-ports=[/ip fi nat get $i to-ports] action=dst-nat dst-port=[/ip fi nat get $i dst-port] comment="UPnP_Cloned"}}
 +
</pre>
  
 +
[http://forum.mikrotik.com/viewtopic.php?p=426711#p426711 Same script easier to read with syntax colorization]
  
Same script easier to read with syntax colorization:
 
  
'''forum.mikrotik.com/viewtopic.php?p=426711#p426711'''
+
* 3. For large networks you may find it useful to clean any Dynamic NAT entries and cloned NAT entry every other night, as old ones may pile up:
  
 +
<pre>
 +
/ip firewall nat remove [/ip firewall nat find comment="UPnP_Cloned"]
 +
</pre>
  
3. For large networks you may find it useful to clean any Dynamic NAT entries and cloned NAT entry every other night, as old ones may pile up:
 
  
/ip firewall nat remove [/ip firewall nat find comment="UPnP_Cloned"]
+
[[Category: Scripting]]

Revision as of 11:30, 18 May 2014

  • 1. Make the simplest UPnP config for just WAN1
  • 2. Add the following script as a schedule: will clone UPnP Dynamic NAT entries as normal NAT entries for WAN2.

Schedule time can be every minute.

(set <WAN2 IP> manually)

:global UPnPs [/ip fi nat find dynamic]; :if ($UPnPs != $UPnPz) do={ :global UPnPz; :set $UPnPz $UPnPs; /ip fi nat remove [/ip fi nat find comment="UPnP_Cloned"]; :foreach i in=([/ip fi nat find dynamic]) do={/ip fi nat add chain=dstnat dst-address="<WAN 2 IP>" protocol=[/ip fi nat get $i protocol] to-addresses=[/ip fi nat get $i to-addresses] to-ports=[/ip fi nat get $i to-ports] action=dst-nat dst-port=[/ip fi nat get $i dst-port] comment="UPnP_Cloned"}}

Same script easier to read with syntax colorization


  • 3. For large networks you may find it useful to clean any Dynamic NAT entries and cloned NAT entry every other night, as old ones may pile up:
/ip firewall nat remove [/ip firewall nat find comment="UPnP_Cloned"]