# RouterOS 7.5
# software id = 7MD6-CZR2
#
# model = RBD52G-5HacD2HnD
# serial number = <OCULTO>
/interface bridge
add admin-mac=<OCULTO> auto-mac=no comment=defconf name=bridge
/interface wireguard
add listen-port=42937 mtu=1420 name=vpn-casa
/interface vlan
add interface=ether1 name=vlan832 vlan-id=832
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
add authentication-types=wpa2-psk mode=dynamic-keys name=protegido \
supplicant-identity=""
/interface wireless
set [ find default-name=wlan1 ] band=2ghz-g/n country=spain disabled=no \
distance=indoors frequency=2437 mode=ap-bridge security-profile=protegido \
ssid=<OCULTO> wps-mode=disabled
set [ find default-name=wlan2 ] band=5ghz-n/ac channel-width=20/40/80mhz-eCee \
country=spain disabled=no distance=indoors frequency=5200 mode=ap-bridge \
security-profile=protegido ssid=<OCULTO>-5G wps-mode=disabled
/ip pool
add name=default-dhcp ranges=192.168.1.2-192.168.1.254
/ip dhcp-server
add address-pool=default-dhcp interface=bridge name=defconf
/interface bridge port
add bridge=bridge comment=defconf interface=ether2
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=wlan1
add bridge=bridge comment=defconf interface=wlan2
/ip neighbor discovery-settings
set discover-interface-list=LAN
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WAN
add interface=*F list=LAN
/interface wireguard peers
add allowed-address=10.10.1.2/32 comment="Redmi Note 7" interface=vpn-casa \
public-key="<OCULTO>"
add allowed-address=10.10.1.3/32 comment="Port\E1til (<OCULTO>)" interface=\
vpn-casa public-key="<OCULTO>="
/ip address
add address=192.168.1.1/24 comment=defconf interface=bridge network=\
192.168.1.0
add address=10.10.1.1/24 interface=vpn-casa network=10.10.1.0
/ip cloud
set ddns-enabled=yes ddns-update-interval=5m
/ip dhcp-client
add comment=defconf interface=vlan832 use-peer-dns=no use-peer-ntp=no
/ip dhcp-server lease
add address=192.168.1.125 client-id=<OCULTO> mac-address=\
<OCULTO> server=defconf
add address=192.168.1.100 client-id=<OCULTO> mac-address=\
<OCULTO> server=defconf
add address=192.168.1.105 client-id=<OCULTO> mac-address=\
<OCULTO> server=defconf
/ip dhcp-server network
add address=192.168.1.0/24 comment=defconf dns-server=192.168.1.1 gateway=\
192.168.1.1
/ip dns
set allow-remote-requests=yes servers=1.1.1.1,1.0.0.1
/ip dns static
add address=192.168.1.1 comment=defconf name=router.lan
/ip firewall address-list
add address=<OCULTO> list=public-ip
/ip firewall filter
add action=accept chain=input comment=\
"defconf: accept established,related,untracked" connection-state=\
established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
"defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=accept chain=input comment=vpn-casa dst-port=42937 protocol=udp
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
in-interface-list=!LAN
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
"defconf: accept established,related, untracked" connection-state=\
established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
connection-state=invalid
add action=drop chain=forward comment=\
"defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat \
connection-state=new in-interface-list=WAN
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" \
ipsec-policy=out,none out-interface=vlan832
add action=dst-nat chain=dstnat comment=qBittorrent dst-port=8988 \
in-interface=vlan832 protocol=tcp to-addresses=192.168.1.100 to-ports=\
6881
add action=dst-nat chain=dstnat comment="Nginx Proxy (1)" disabled=yes \
dst-port=80 in-interface=vlan832 protocol=tcp to-addresses=192.168.1.125 \
to-ports=10080
add action=dst-nat chain=dstnat comment="Nginx Proxy (2)" disabled=yes \
dst-port=443 in-interface=vlan832 protocol=tcp to-addresses=192.168.1.125 \
to-ports=10443
/ip service
set telnet disabled=yes
set ftp disabled=yes
set www disabled=yes
set ssh disabled=yes
set api disabled=yes
set api-ssl disabled=yes
/ipv6 firewall address-list
add address=::/128 comment="defconf: unspecified address" list=bad_ipv6
add address=::1/128 comment="defconf: lo" list=bad_ipv6
add address=fec0::/10 comment="defconf: site-local" list=bad_ipv6
add address=::ffff:0.0.0.0/96 comment="defconf: ipv4-mapped" list=bad_ipv6
add address=::/96 comment="defconf: ipv4 compat" list=bad_ipv6
add address=100::/64 comment="defconf: discard only " list=bad_ipv6
add address=2001:db8::/32 comment="defconf: documentation" list=bad_ipv6
add address=2001:10::/28 comment="defconf: ORCHID" list=bad_ipv6
add address=3ffe::/16 comment="defconf: 6bone" list=bad_ipv6
/ipv6 firewall filter
add action=accept chain=input comment=\
"defconf: accept established,related,untracked" connection-state=\
established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
invalid
add action=accept chain=input comment="defconf: accept ICMPv6" protocol=\
icmpv6
add action=accept chain=input comment="defconf: accept UDP traceroute" port=\
33434-33534 protocol=udp
add action=accept chain=input comment=\
"defconf: accept DHCPv6-Client prefix delegation." dst-port=546 protocol=\
udp src-address=fe80::/10
add action=accept chain=input comment="defconf: accept IKE" dst-port=500,4500 \
protocol=udp
add action=accept chain=input comment="defconf: accept ipsec AH" protocol=\
ipsec-ah
add action=accept chain=input comment="defconf: accept ipsec ESP" protocol=\
ipsec-esp
add action=accept chain=input comment=\
"defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=input comment=\
"defconf: drop everything else not coming from LAN" in-interface-list=\
!LAN
add action=accept chain=forward comment=\
"defconf: accept established,related,untracked" connection-state=\
established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
connection-state=invalid
add action=drop chain=forward comment=\
"defconf: drop packets with bad src ipv6" src-address-list=bad_ipv6
add action=drop chain=forward comment=\
"defconf: drop packets with bad dst ipv6" dst-address-list=bad_ipv6
add action=drop chain=forward comment="defconf: rfc4890 drop hop-limit=1" \
hop-limit=equal:1 protocol=icmpv6
add action=accept chain=forward comment="defconf: accept ICMPv6" protocol=\
icmpv6
add action=accept chain=forward comment="defconf: accept HIP" protocol=139
add action=accept chain=forward comment="defconf: accept IKE" dst-port=\
500,4500 protocol=udp
add action=accept chain=forward comment="defconf: accept ipsec AH" protocol=\
ipsec-ah
add action=accept chain=forward comment="defconf: accept ipsec ESP" protocol=\
ipsec-esp
add action=accept chain=forward comment=\
"defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=forward comment=\
"defconf: drop everything else not coming from LAN" in-interface-list=\
!LAN
/system clock
set time-zone-name=Europe/Madrid
/system ntp client
set enabled=yes
/system ntp client servers
add address=hora.roa.es
/system scheduler
add disabled=yes interval=30m name="Duckdns Updater" on-event=duckdns-updater \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=sep/11/2022 start-time=17:46:57
/system script
add dont-require-permissions=no name="Cambio DHCP Server" owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
############## CABECERA ##################\r\
\n:local newRouerIP \"192.168.1.1\"\r\
\n:local newRouterPool \"192.168.1.2-192.168.1.254\"\r\
\n:local mainPoolName \"default-dhcp\"\r\
\n:local mainLanInterface \"bridge\"\r\
\n########### FIN DE LA CABECERA #############\r\
\n/ip pool set [find name=\$mainPoolName] ranges=\$newRouterPool\r\
\n/ip address set [find interface=\$mainLanInterface] address=\"\$newRouer\
IP/24\"\r\
\n/ip dhcp-server network set 0 address=\\\r\
\n[/ip address get [find interface=\$mainLanInterface] network] \\\r\
\ngateway=\$newRouerIP dns-server=\$newRouerIP\r\
\n/log/info \"Router LAN successfully updated\""
add dont-require-permissions=no name=duckdns-updater owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="#\
\_Modificad las siguientes tres asignaciones de variables, relativas a la \
interfaz wan, el dominio y el token, con vuestros datos. Se cambia lo que \
va entrecomillado.\r\
\n\r\
\n# Poned aqu\ED la interfaz por la que te conectas a internet, ejemplo:\r\
\n:global wanInterface \"vlan832\"\r\
\n\r\
\n# Poned aqu\ED el dominio duckdns que queramos mantener actualizado, eje\
mplo:\r\
\n:global domain \"<OCULTO>\"\r\
\n\r\
\n# Poned aqu\ED el token que nos da duckdns para nuestra cuenta, ejemplo:\
\r\
\n:global token \"<OCULTO>\"\r\
\n\r\
\n# Inicio del Script\r\
\n:global actualIP value=[/ip address get [find where interface=\$wanInter\
face] value-name=address];\r\
\n:global actualIP value=[:pick \$actualIP -1 [:find \$actualIP \"/\" -1] \
];\r\
\n:if ([:len [/file find where name=ipstore.txt]] < 1 ) do={\r\
\n/file print file=ipstore.txt where name=ipstore.txt;\r\
\n/delay delay-time=2;\r\
\n/file set ipstore.txt contents=\"0.0.0.0\";\r\
\n};\r\
\n:global previousIP value=[/file get [find where name=ipstore.txt ] value\
-name=contents];\r\
\n:if (\$previousIP != \$actualIP) do={\r\
\n:log info message=(\"Try to Update DuckDNS with actual IP \".\$actualIP.\
\" - Previous IP are \".\$previousIP);\r\
\n/tool fetch mode=https keep-result=yes dst-path=duckdns-result.txt addre\
ss=[:resolve www.duckdns.org] port=443 host=www.duckdns.org src-path=(\"/u\
pdate\?domains=\$domain&token=\$token&ip=\".\$actualIP);\r\
\n/delay delay-time=5;\r\
\n:global lastChange value=[/file get [find where name=duckdns-result.txt \
] value-name=contents];\r\
\n:global previousIP value=\$actualIP;\r\
\n/file set ipstore.txt contents=\$actualIP;\r\
\n:if (\$lastChange = \"OK\") do={:log warning message=(\"DuckDNS update s\
uccessfull with IP \".\$actualIP);};\r\
\n:if (\$lastChange = \"KO\") do={:log error message=(\"Fail to update Duc\
kDNS with new IP \".\$actualIP);};\r\
\n};"
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN