# ================================================================================ # SCRIPT COMPLETO MIKROTIK - LOAD BALANCE + HOTSPOT SOCIAL # ================================================================================ # Configuração: 3 WANs com Load Balance/Failover + Hotspot Social na ETH5 # Gateways: 192.168.0.1, 192.168.1.1, 192.168.2.1 # Autor: Configuração Personalizada # Data: $(date '+%d/%m/%Y %H:%M:%S') # ================================================================================ # ============================ # AGUARDAR E PREPARAR SISTEMA # ============================ :log info "=== INICIANDO CONFIGURAÇÃO COMPLETA ===" :log info "Aguardando sistema estabilizar..." :delay 3s # ============================ # CONFIGURAÇÕES BÁSICAS DO SISTEMA # ============================ :log info "Configurando sistema básico..." # Nome do roteador /system identity set name="MikroTik-LoadBalance-Hotspot" # Configuração de tempo /system clock set time-zone-name=America/Sao_Paulo /system ntp client set enabled=yes server-dns-names=pool.ntp.br # ============================ # LIMPEZA DE CONFIGURAÇÕES ANTIGAS # ============================ :log info "Limpando configurações antigas..." # Remover hotspots existentes :foreach i in=[/ip hotspot find] do={/ip hotspot remove $i} :foreach i in=[/ip hotspot profile find name!="default"] do={/ip hotspot profile remove $i} :foreach i in=[/ip hotspot user profile find name!="default"] do={/ip hotspot user profile remove $i} # Remover DHCP servers existentes (exceto padrões) :foreach i in=[/ip dhcp-server find] do={/ip dhcp-server remove $i} # Remover pools existentes :foreach i in=[/ip pool find] do={/ip pool remove $i} # Limpar mangle e NAT :foreach i in=[/ip firewall mangle find] do={/ip firewall mangle remove $i} :foreach i in=[/ip firewall nat find] do={/ip firewall nat remove $i} # Limpar rotas dinâmicas :foreach i in=[/ip route find dst-address="0.0.0.0/0"] do={/ip route remove $i} :delay 2s # ============================ # CONFIGURAÇÃO DAS INTERFACES # ============================ :log info "Configurando interfaces de rede..." # Renomear interfaces /interface ethernet set ether1 name=wan1 /interface ethernet set ether2 name=wan2 /interface ethernet set ether3 name=wan3 /interface ethernet set ether4 name=lan /interface ethernet set ether5 name=hotspot-eth # Remover IPs existentes das interfaces :foreach i in=[/ip address find interface=wan1] do={/ip address remove $i} :foreach i in=[/ip address find interface=wan2] do={/ip address remove $i} :foreach i in=[/ip address find interface=wan3] do={/ip address remove $i} :foreach i in=[/ip address find interface=lan] do={/ip address remove $i} :foreach i in=[/ip address find interface=hotspot-eth] do={/ip address remove $i} :delay 1s # Configurar IPs das WANs /ip address add address=192.168.0.100/24 interface=wan1 comment="WAN1" /ip address add address=192.168.1.100/24 interface=wan2 comment="WAN2" /ip address add address=192.168.2.100/24 interface=wan3 comment="WAN3" # Configurar LAN e Hotspot /ip address add address=10.0.0.1/24 interface=lan comment="LAN-Principal" /ip address add address=192.168.100.1/24 interface=hotspot-eth comment="Hotspot" # ============================ # CONFIGURAÇÃO DNS # ============================ :log info "Configurando DNS..." /ip dns set servers=8.8.8.8,8.8.4.4,1.1.1.1 allow-remote-requests=yes cache-size=4096KiB # ============================ # CONFIGURAÇÃO DOS POOLS DE IP # ============================ :log info "Criando pools de IP..." # Pool para LAN /ip pool add name=lan-pool ranges=10.0.0.10-10.0.0.100 comment="Pool-LAN" # Pool para Hotspot /ip pool add name=hotspot-pool ranges=192.168.100.10-192.168.100.200 comment="Pool-Hotspot" # ============================ # CONFIGURAÇÃO DHCP # ============================ :log info "Configurando servidores DHCP..." # DHCP LAN /ip dhcp-server network add address=10.0.0.0/24 gateway=10.0.0.1 dns-server=10.0.0.1 comment="Network-LAN" /ip dhcp-server add name=lan-dhcp interface=lan address-pool=lan-pool lease-time=1d disabled=no comment="DHCP-LAN" # DHCP Hotspot /ip dhcp-server network add address=192.168.100.0/24 gateway=192.168.100.1 dns-server=192.168.100.1 comment="Network-Hotspot" /ip dhcp-server add name=hotspot-dhcp interface=hotspot-eth address-pool=hotspot-pool lease-time=2h disabled=no comment="DHCP-Hotspot" # ============================ # CONFIGURAÇÃO DE ROTEAMENTO # ============================ :log info "Configurando tabelas de roteamento..." # Criar tabelas de roteamento /routing table add name=wan1_table fib comment="Tabela-WAN1" /routing table add name=wan2_table fib comment="Tabela-WAN2" /routing table add name=wan3_table fib comment="Tabela-WAN3" :delay 1s # Rotas nas tabelas específicas /ip route add dst-address=0.0.0.0/0 gateway=192.168.0.1 routing-table=wan1_table distance=1 comment="Route-WAN1-Table" /ip route add dst-address=0.0.0.0/0 gateway=192.168.1.1 routing-table=wan2_table distance=1 comment="Route-WAN2-Table" /ip route add dst-address=0.0.0.0/0 gateway=192.168.2.1 routing-table=wan3_table distance=1 comment="Route-WAN3-Table" # Rotas principais para failover /ip route add dst-address=0.0.0.0/0 gateway=192.168.0.1 distance=1 check-gateway=ping comment="Main-WAN1" /ip route add dst-address=0.0.0.0/0 gateway=192.168.1.1 distance=2 check-gateway=ping comment="Backup-WAN2" /ip route add dst-address=0.0.0.0/0 gateway=192.168.2.1 distance=3 check-gateway=ping comment="Backup-WAN3" # ============================ # CONFIGURAÇÃO LOAD BALANCE # ============================ :log info "Configurando load balance..." # Mangle para load balance /ip firewall mangle add chain=prerouting in-interface=lan connection-mark=no-mark \ dst-address-type=!local per-connection-classifier=both-addresses:3/0 \ action=mark-connection new-connection-mark=wan1_conn comment="LB-Mark-WAN1" /ip firewall mangle add chain=prerouting in-interface=lan connection-mark=no-mark \ dst-address-type=!local per-connection-classifier=both-addresses:3/1 \ action=mark-connection new-connection-mark=wan2_conn comment="LB-Mark-WAN2" /ip firewall mangle add chain=prerouting in-interface=lan connection-mark=no-mark \ dst-address-type=!local per-connection-classifier=both-addresses:3/2 \ action=mark-connection new-connection-mark=wan3_conn comment="LB-Mark-WAN3" # Mangle para roteamento /ip firewall mangle add chain=prerouting connection-mark=wan1_conn \ action=mark-routing new-routing-mark=wan1_table comment="LB-Route-WAN1" /ip firewall mangle add chain=prerouting connection-mark=wan2_conn \ action=mark-routing new-routing-mark=wan2_table comment="LB-Route-WAN2" /ip firewall mangle add chain=prerouting connection-mark=wan3_conn \ action=mark-routing new-routing-mark=wan3_table comment="LB-Route-WAN3" # ============================ # CONFIGURAÇÃO NAT # ============================ :log info "Configurando NAT..." # NAT para todas as WANs /ip firewall nat add chain=srcnat out-interface=wan1 action=masquerade comment="NAT-WAN1" /ip firewall nat add chain=srcnat out-interface=wan2 action=masquerade comment="NAT-WAN2" /ip firewall nat add chain=srcnat out-interface=wan3 action=masquerade comment="NAT-WAN3" # ============================ # CONFIGURAÇÃO DO HOTSPOT # ============================ :log info "Configurando hotspot social..." # 1. Perfil do usuário hotspot /ip hotspot user profile add name=perfil-usuario \ session-timeout=4h \ idle-timeout=30m \ keepalive-timeout=2m \ status-autorefresh=1m \ shared-users=1 \ rate-limit=50M/50M \ transparent-proxy=yes \ comment="Perfil-Usuario-Hotspot" # 2. Perfil do servidor hotspot /ip hotspot profile add name=perfil-servidor \ hotspot-address=192.168.100.1 \ dns-name=login.wifi \ html-directory=hotspot \ http-proxy=0.0.0.0:0 \ login-by=email,http-chap \ use-radius=no \ mac-auth-mode=no \ trial-uptime-limit=4h \ trial-user-profile=perfil-usuario \ smtp-server=0.0.0.0:0 \ split-user-domain=no \ comment="Perfil-Servidor-Hotspot" :delay 2s # 3. Criar servidor hotspot /ip hotspot add name=servidor-hotspot interface=hotspot-eth address-pool=hotspot-pool \ profile=perfil-servidor disabled=no comment="Servidor-Hotspot-Principal" # 4. Usuários do hotspot /ip hotspot user add name=T-trial password="" profile=perfil-usuario limit-uptime=4h \ disabled=no comment="Usuario-Trial-Email" /ip hotspot user add name=admin password=123456 profile=perfil-usuario \ disabled=no comment="Usuario-Admin" # ============================ # CONFIGURAÇÃO FIREWALL # ============================ :log info "Configurando firewall..." # Firewall Filter /ip firewall filter add chain=input action=accept connection-state=established,related comment="Accept-Established" /ip firewall filter add chain=input action=accept src-address=10.0.0.0/24 comment="Accept-LAN" /ip firewall filter add chain=input action=accept src-address=192.168.100.0/24 comment="Accept-Hotspot" /ip firewall filter add chain=input action=accept protocol=icmp comment="Accept-ICMP" /ip firewall filter add chain=input action=accept protocol=tcp dst-port=22,80,443,8080,8291 comment="Accept-Management" /ip firewall filter add chain=input action=drop comment="Drop-All-Other-Input" # Forward rules /ip firewall filter add chain=forward action=fasttrack-connection connection-state=established,related comment="FastTrack" /ip firewall filter add chain=forward action=accept connection-state=established,related comment="Accept-Established-Forward" /ip firewall filter add chain=forward action=drop connection-state=invalid comment="Drop-Invalid-Forward" /ip firewall filter add chain=forward action=accept comment="Accept-All-Forward" # NAT para redirecionamento hotspot /ip firewall nat add chain=dstnat dst-port=80 protocol=tcp hotspot=from-client \ action=redirect to-ports=64872 comment="Hotspot-HTTP-Redirect" # ============================ # WALLED GARDEN # ============================ :log info "Configurando walled garden..." /ip hotspot walled-garden add dst-host=login.wifi comment="Login-Page" /ip hotspot walled-garden add dst-host=192.168.100.1 comment="Router-Access" # ============================ # PÁGINA DE LOGIN CUSTOMIZADA # ============================ :log info "Criando página de login..." # Aguardar sistema de arquivos :delay 2s # Criar diretório hotspot se não existir :execute { :local content "
Conecte-se gratuitamente à internet
\$(if error) \$(endif)