UFW está bloqueando todo incluso cuando establezco reglas para permitir


14

Estoy usando un servidor ubuntu, ahora estoy tratando de habilitar el firewall usando estos comandos:

ufw default deny incoming
ufw default allow outgoing

ufw allow ssh
ufw allow www
ufw allow https

ufw enable

También intenté hacer el ufw default deny incomingúltimo pero aún no tuve suerte, cuando habilito el firewall bloquea todo cuando configuro el valor predeterminado para negar, pero cuando lo configuro para permitir, funciona bien, como si se ignoraran las reglas. ¿Qué podría estar causando esto?

EDITAR

Este es mi resultado de iptables -L -v -n que también probé la solución propuesta pero aún no tuve suerte, funciona bien solo cuando la hagodefault allow incoming

Chain INPUT (policy DROP 30 packets, 1764 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 2 packets, 104 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-after-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-after-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:137
    0     0 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:138
    0     0 ufw-skip-to-policy-input  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:139
    0     0 ufw-skip-to-policy-input  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:445
    0     0 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:67
    0     0 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:68
    0     0 ufw-skip-to-policy-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type BROADCAST

Chain ufw-after-logging-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw-after-logging-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw-after-logging-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-after-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-before-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 3
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 4
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 11
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 12
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 8
    0     0 ufw-user-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-before-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ufw-logging-deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 3
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 4
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 11
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 12
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 8
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp spt:67 dpt:68
    0     0 ufw-not-local  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251          udp dpt:5353
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            239.255.255.250      udp dpt:1900
    0     0 ufw-user-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-before-logging-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-before-logging-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-before-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ufw-user-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-logging-allow (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW ALLOW] "

Chain ufw-logging-deny (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID limit: avg 3/min burst 10
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw-not-local (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type MULTICAST
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type BROADCAST
    0     0 ufw-logging-deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-reject-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-reject-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-reject-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-skip-to-policy-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-skip-to-policy-input (7 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-skip-to-policy-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-track-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-track-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-track-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate NEW
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate NEW

Chain ufw-user-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-user-input (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:22
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:443
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:443

Chain ufw-user-limit (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 5 LOG flags 0 level 4 prefix "[UFW LIMIT BLOCK] "
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable

Chain ufw-user-limit-accept (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain ufw-user-logging-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-user-logging-input (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-user-logging-output (0 references)
 pkts bytes target     prot opt in     out     source               destination         

Chain ufw-user-output (1 references)
 pkts bytes target     prot opt in     out     source               destination         

1
¿Me puedes hacer un favor? Haga ufw enable, luego pegue el resultado de sudo iptables -L -v -nsu pregunta. Tengo curiosidad por lo que subyace a la netfilter/ iptableslas cosas que está haciendo en realidad con las reglas de la UFW. :)
Thomas Ward

Los dos primeros comandos son innecesarios. Todo lo que necesita hacer es habilitar UFW y se aplicará la denegación de permiso predeterminada.
mchid

Oooh, mchid tiene razón, esos son los valores predeterminados, no los necesitas. Dicho esto, todavía quiero ver los iptablesdatos si, con esas dos primeras líneas excluidas, todavía tiene este problema.
Thomas Ward

Respuestas:


13

Abra una terminal y escriba los siguientes comandos:

Comience reiniciando, lo que eliminará todas las reglas existentes:

sudo ufw reset

Próximo,

sudo ufw app list

Esto mostrará una lista de los perfiles de aplicación disponibles, como OpenSSH y otros. Para obtener información sobre una aplicación, escriba el siguiente comando como en este ejemplo:

sudo ufw app info OpenSSH

Aquí está la salida:

Profile: OpenSSH
Title: Secure shell server, an rshd replacement
Description: OpenSSH is a free implementation of the Secure Shell protocol.

Port:
  22/tcp

Para permitir el acceso a OpenSSH, puede usar la siguiente regla:

sudo ufw allow 22/tcp

A diferencia de Debian, www y https generalmente no se incluyen como perfiles de aplicaciones, sin embargo, sabemos que funcionan en los puertos 80 y 443, por lo tanto, use los siguientes comandos:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Si desea agregar UDP, simplemente haga esto también.

sudo ufw allow 80/udp
sudo ufw allow 443/udp

Deshabilite y habilite ufw para aplicar los cambios:

sudo ufw disable
sudo ufw enable

Para mostrar tus reglas:

sudo ufw status

Finalmente, uno de los aspectos menos amigables de ufw es cómo las reglas de denegación generalmente prevalecen sobre las reglas de permitir. Por ejemplo, no puede configurar todo para negar y luego configurar puertos para permitir. Todos los puertos seguirán bloqueados. Ver aquí para más información .


Puede agregar estas reglas para bloquear globalmente todos los puertos, excepto 22, 53, 80 y 443. He agregado el puerto 53 para permitir solicitudes DNS. Si no necesita hacer consultas DNS, simplemente modifique las reglas en consecuencia.

Para establecer estas reglas de bloqueo solo para entrantes, usaría, sudo ufw deny in 1:22/tcppor ejemplo. Alternativamente, configure para saliente sudo ufw deny out 1:22/tcpy así sucesivamente.

sudo ufw deny 1:21/tcp
sudo ufw deny 1:21/udp
sudo ufw deny 23:52/tcp
sudo ufw deny 23:52/udp
sudo ufw deny 54:79/tcp
sudo ufw deny 54:79/udp
sudo ufw deny 81:442/tcp
sudo ufw deny 81:442/udp
sudo ufw deny 444:65535/tcp
sudo ufw deny 444:65535/udp

Muchas gracias por su respuesta, pero quiero bloquear todos los puertos, excepto aquellos, ¿debo usar ufw default block incomingdespués de establecer esas reglas?
engma

@ Developer106 No, cuando habilita ufw, el bloqueo de entrada ya está configurado como predeterminado. Puede verificar esto ejecutando el siguiente comando en una terminal abierta sudo ufw status verbose. Si no me equivoco, establecer explícitamente esa regla no permitirá sus puertos permitidos. Si desea bloquear todos los puertos excepto aquellos, realmente le sugiero que consulte este hilo, ya que eso es exactamente lo que hacen. Es muy completo, bloquea todos excepto aquellos y tendrá los puertos abiertos que desee. ubuntuforums.org/showthread.php?t=1893751
mchid

@ Developer106 Agregué algunas reglas para bloquear globalmente todas excepto 22, 53, 80 y 443 y negar o bloquear cualquier otro puerto.
mchid

ok solo funciona cuando especifique negar outsi digo denysin decir que es para salir específicamente, todavía no funciona. ¿Cuál podría ser la causa de eso?
engma

@ Developer106 lo que no funciona, ¿no está bloqueando o no permitiendo?
mchid

7

FYI: en caso de que otros tengan este problema.

En la salida detallada de iptables noté que faltan las reglas de ufw en las cadenas INPUT, OUTPUT y FORWARD. Mi sistema terminó así cuando ejecuté iptables -F para eliminar mis reglas de FW personalizadas después de habilitar ufw en algún momento. Parece que ufw no agrega las reglas de nivel superior si algunas de sus propias cadenas ya existen en iptables.

Terminé desinstalando ufw, reiniciando, ejecuté 'iptables -F' (para eliminar las reglas anteriores de iptables que aún estaban activas), luego reinstalé y configuré ufw. Las reglas ufw de nivel superior ahora están de vuelta. La desinstalación / reinstalación puede no haber sido necesaria. Simplemente eliminar todas las reglas de ufw de iptables deshabilitando ufw y reiniciar puede haber hecho el truco.

Así es como deberían verse las cadenas de nivel superior (en Debian 9.4).

Chain INPUT (policy DROP)
target     prot opt source               destination         
ufw-before-logging-input  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-before-input  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-after-input  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-after-logging-input  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-reject-input  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-track-input  all  --  0.0.0.0/0            0.0.0.0/0           

Chain FORWARD (policy DROP)
target     prot opt source               destination         
ufw-before-logging-forward  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-before-forward  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-after-forward  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-after-logging-forward  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-reject-forward  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-track-forward  all  --  0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
ufw-before-logging-output  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-before-output  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-after-output  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-after-logging-output  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-reject-output  all  --  0.0.0.0/0            0.0.0.0/0           
ufw-track-output  all  --  0.0.0.0/0            0.0.0.0/0           

1
Esto solucionó el problema para mí también.
Technophobe01

1
Ejecutar iptables -Xpara eliminar todas las cadenas no integradas y luego reiniciar ufwtambién funcionó para mí.
Tblue

0

Tengo el mismo problema, algún tipo de configuración atornillada ufwy subí la fail2bancadena de iptables. Todo se bloqueó tan pronto como comencé ufw, incluso sin reglas en la ufwcadena misma. ufwrestablecer no ayudó. Lo reinstalé completamente, esto funcionó.

sudo apt-get purge ufw
sudo apt-get install ufw

Hola maso ¿Tuvo que hacer alguna configuración adicional después de reinstalar?
Hee Jin

0

Para mí, este problema se resolvió estableciendo la regla desde

sudo ufw default deny outgoing
sudo ufw default allow outgoing

Eso es lo único que funcionó, no permitir el puerto 53, permitir dns, etc.

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.