Páginas

Mostrando entradas con la etiqueta winbox. Mostrar todas las entradas
Mostrando entradas con la etiqueta winbox. Mostrar todas las entradas

jueves, 12 de junio de 2025

Firewall Mikrotik Protege LAN y Permite Acceso a Internet

Configuración de firewall para MikroTik (RouterOS)

Protege la red LAN (10.10.10.0/24) y permite acceso a Internet. Las reglas incluyen protección anti-spoofing, bloqueo de tráfico no autorizado, y permiten tráfico legítimo.

El router Mikrotik esta conectado al puerto ehter1 (WAN_ether1) y uno de los puertos ethernet del router ISP usando DHCP Client

Configuración básica de interfaces

/interface bridge
add name=LAN_bridge
/interface bridge port
add bridge=LAN_bridge interface=ether2
add bridge=LAN_bridge interface=ether3
add bridge=LAN_bridge interface=ether4
add bridge=LAN_bridge interface=ether5
add bridge=LAN_bridge interface=wlan1
add bridge=LAN_bridge interface=wlan2
/ip address
add address=10.10.10.1/24 interface=LAN_bridge

DHCP Client en WAN (WAN_ether1)

/ip dhcp-client
add interface=WAN_ether1

NAT para acceso a Internet

/ip firewall nat
add chain=srcnat out-interface=WAN_ether1 action=masquerade

POLÍTICAS POR DEFECTO (FILTER)

/ip firewall filter

CONEXIONES ESTABLECIDAS

add chain=input action=accept connection-state=established,related \
comment="Permitir conexiones Establecidas/Realacionadas (Input)"
add chain=forward action=accept connection-state=established,related \
comment="Permitir conexiones Establecidas/Relacionadas (Forward)"
add chain=output action=accept connection-state=established,related \
comment="Permitir conexiones Establecidas/Relacionadas (Output)"

ANTI-SPOOFING Y SEGURIDAD BÁSICA Bloqueo de IPs falsas en WAN

add chain=input action=drop in-interface=WAN_ether1 src-address=10.10.10.0/24 \
comment="Bloquear LAN IP Spoofing (Input)"
add chain=forward action=drop in-interface=WAN_ether1 src-address=10.10.10.0/24 \
comment="Bloquear LAN IP Spoofing (Forward)"

Protección contra escaneos y ataques comunes

add chain=input action=drop in-interface=WAN_ether1 protocol=tcp psd=21,3s,3,1 \
comment="Bloquear TCP SYN Scans"
add chain=input action=drop in-interface=WAN_ether1 protocol=udp

REGLAS INPUT (TRÁFICO AL ROUTER) Permitir administración solo desde LAN

add chain=input action=accept in-interface=LAN_bridge protocol=tcp dst-port=22,8291,443 \
comment="Acceso Administracion (LAN)"

Permitir ICMP (ping)

add chain=input action=accept protocol=icmp comment="Allow ICMP"

Permitir DHCP desde ISP

add chain=input action=accept in-interface=WAN_ether1 protocol=udp src-port=67-68 dst-port=67-68 \
comment="DHCP Cliente"

Bloquear todo lo demás en WAN

add chain=input action=drop in-interface=WAN_ether1 \
comment="Bloquear Todo WAN Input"

REGLAS FORWARD (TRÁFICO A TRAVÉS DEL ROUTER)

Permitir LAN -> Internet

add chain=forward action=accept in-interface=LAN_bridge out-interface=WAN_ether1 \
connection-state=new comment="LAN a Internet"

Bloquear Internet -> LAN (excepto respuestas)

add chain=forward action=drop in-interface=WAN_ether1 out-interface=LAN_bridge \
connection-state=new comment="Bloquear Internet a LAN"

Permitir tráfico entre interfaces LAN (opcional)

add chain=forward action=accept in-interface=LAN_bridge out-interface=LAN_bridge \
comment="Inter-LAN Tráfico"

REGLAS OUTPUT (TRÁFICO DESDE EL ROUTER)

add chain=output action=accept comment="Permitir Router Output" disabled=no

REGLAS ADICIONALES DE SEGURIDAD Bloqueo de redes reservadas/rfc1918 desde WAN

add chain=input action=drop in-interface=WAN_ether1 src-address-list=private_ranges \
comment="Bloquear IPs Privada (Input)"
add chain=forward action=drop in-interface=WAN_ether1 src-address-list=private_ranges \
comment="Bloquear IPs Privada (Forward)"

Lista de redes reservadas

/ip firewall address-list
add address=172.16.0.0/12 list=private_ranges
add address=10.0.0.0/8 list=private_ranges
add address=192.168.0.0/16 list=private_ranges
add address=169.254.0.0/16 list=private_ranges

LOGGING (OPCIONAL)

add chain=input action=log log-prefix="[BLOQUEO DE CORTAFUEGOS] " \
comment="Log Bloqueado Input"
add chain=forward action=log log-prefix="[BLOQUEO DE CORTAFUEGOS] " 
comment="Log Bloqueado Forward"

Configurar servicios:

/ip service
set ssh address=10.10.10.0/24,192.168.88.0/24
set winbox address=10.10.10.0/24,192.168.88.0/24
set ftp disable=yes
set telnet disable=yes
set api disable=yes
set api-ssl disable=yes
set www disable=yes
set www-ssl disable=yes

Protección bridge:

/interfaces bridge settings
set use-ip-firewall=yes

Protección extra:

/ip firewall filter
add chain=forward protocol=tcp tcp-flags=syn,!ack action=drop comment="Bloquear SYN-flood"
add chain=forward protocol=udp limit=10/1m action=drop comment="Limite UDP floods"

Explicación:

1. Conexiones Establecidas: - Acepta tráfico de respuestas en todas las cadenas (input, forward, output).

2. Protección Anti-Spoofing: - Bloquea tráfico WAN con IPs de la LAN (10.10.10.0/24). - Bloquea redes reservadas (RFC 1918) desde WAN.

3. Reglas INPUT: - Solo permite administración (SSH, Winbox, WebFig) desde la LAN. - Permite ICMP (ping) y DHCP del ISP. - Bloquea todo el tráfico entrante no autorizado en WAN.

4. Reglas FORWARD: - Permite nuevas conexiones desde LAN hacia Internet. - Bloquea nuevas conexiones desde Internet hacia LAN. - Permite comunicación entre dispositivos LAN (opcional).

5. Reglas OUTPUT: - Permite todo el tráfico generado por el router (se puede ajustar si es necesario).

6. Protección Adicional: - Bloqueo de escaneos TCP/UDP desde Internet. - Logging de tráfico bloqueado para diagnóstico.

Notas: - Políticas por Defecto: - Input: drop (implícito por reglas). - Forward: drop (regla final bloquea tráfico no autorizado). - Output: accept.

- NAT: La regla masquerade en srcnat permite a la LAN acceder a Internet usando la IP WAN (asignada por DHCP).

- Personalización: - Para permitir acceso desde Internet (ej: servidor web), agregar reglas `forward` específicas. - Ajustar puertos de administración en reglas `input` según necesidades.

Esta configuración equilibra seguridad y funcionalidad, protegiendo la LAN de amenazas externas mientras permite acceso a Internet.

FreeBSD es genial!.