
Tengo un servidor A con IP de túnel WG 10.9.0.1, un servidor B con IP de túnel WG 10.9.0.4 y mi móvil con IP de túnel WG 10.9.0.3.
Los servidores A y B tienen UFW habilitado y permiten puertos entrantes como puerto SSH y WG.
Me conectaré al Servidor A a través de mi móvil para todas mis actividades de Internet, lo cual funciona bien. Estoy intentando acceder a un servidor web que se ejecuta en el servidor B en mi navegador móvil a través dehttp://10.9.0.4y no puedo hacerlo funcionar cuando UFW en el servidor B está habilitado. Sin embargo, cuando desactivo UFW en el servidor B, puedo acceder al servidor web a través de mi móvil. Quiero que se acceda al servidor web solo mediante VPN y no quiero acceso público. ¿Alguien puede ayudarme a encontrar qué regla falta en UFW que bloquea mi acceso al servidor web del Servidor B? Intenté aceptar todas las entradas/salientes en la interfaz wg0 en el servidor B, pero fue en vano.
El servidor B y el dispositivo móvil están conectados como pares al servidor AI y puedo hacer ping al servidor B desde el dispositivo móvil y al servidor A.
UFW para el servidor B
Status: active
Logging: on (low)
Default: deny (incoming), deny (outgoing), deny (routed)
New profiles: skip
To Action From
-- ------ ----
5440 ALLOW IN Anywhere
44787/udp ALLOW IN Anywhere
80,443/tcp on wg0 ALLOW IN Anywhere
5440 (v6) ALLOW IN Anywhere (v6)
44787/udp (v6) ALLOW IN Anywhere (v6)
80,443/tcp (v6) on wg0 ALLOW IN Anywhere (v6)
443 ALLOW OUT Anywhere
53 ALLOW OUT Anywhere
80 ALLOW OUT Anywhere
443 (v6) ALLOW OUT Anywhere (v6)
53 (v6) ALLOW OUT Anywhere (v6)
80 (v6) ALLOW OUT Anywhere (v6)
UFW para el servidor A
Status: active
Logging: on (low)
Default: deny (incoming), deny (outgoing), deny (routed)
New profiles: skip
To Action From
-- ------ ----
5440 ALLOW IN Anywhere
44787 ALLOW IN Anywhere
44787 (v6) ALLOW IN Anywhere (v6)
53 ALLOW OUT Anywhere
80,443/tcp ALLOW OUT Anywhere on wg0
53/udp ALLOW OUT Anywhere on wg0
53 (v6) ALLOW OUT Anywhere (v6)
80,443/tcp (v6) ALLOW OUT Anywhere (v6) on wg0
53/udp (v6) ALLOW OUT Anywhere (v6) on wg0
Editar: deshabilité UFW en el servidor B y lo reemplacé con iptables como se muestra a continuación. El problema existe.
#!/usr/bin/env bash
#############################
# SETUP
#############################
# Define your hostname
DEMOSTHENES=X.X.X.X
# Clear all rules
/sbin/iptables -F
iptables -I FORWARD -s 10.9.0.0/24 -i wg0 -j ACCEPT #sample rule to allow packet forwarding from your wg subnet
#############################
# MANAGEMENT RULES
#############################
# Allow SSH (alternate port)
/sbin/iptables -A INPUT -p tcp -d $DEMOSTHENES --dport 5440 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -d $DEMOSTHENES --dport 44787 -j ACCEPT
/sbin/iptables -A INPUT -p udp -d $DEMOSTHENES --dport 44787 -j ACCEPT
# Allow web server access
iptables -A INPUT -i wg0 -p tcp -m multiport --dports 80,443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -o wg0 -p tcp -m multiport --sports 80,443 -m state --state ESTABLISHED -j ACCEPT
/sbin/iptables -A INPUT -j DROP
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere v8.domain.co tcp dpt:5440
ACCEPT tcp -- anywhere v8.domain.co tcp dpt:44787
ACCEPT udp -- anywhere v8.domain.co udp dpt:44787
ACCEPT tcp -- anywhere anywhere multiport dports http,https state NEW,ESTABLISHED
DROP all -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 10.9.0.0/24 anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere multiport sports http,https state ESTABLISHED
Respuesta1
No he usado ufw antes, pero veo que dice que su política 'enrutada' está configurada para denegar las reglas de ufw en el servidor B, lo que significa que todos los paquetes que ingresan desde un host diferente y que están destinados a terminar en el servidor B están siendo bloqueados ( si entiendo correctamente). Intente crear una regla para permitir el reenvío de paquetes (edite también /etc/sysctl.conf y asegúrese de reenviar paquetes ipv4 e ipv6; net.ipv4.ip_forward=1 y net.ipv6.conf.all.forwarding=1) o establezca la política predeterminada para que la cadena FORWARD la acepte y vea qué sucede. Utilizo iptables y es muy complicado, a veces usar Insertar en lugar de Agregar para una regla marca la diferencia.
iptables -I FORWARD -s 10.9.0.0/24 -i wg0 -j ACCEPT #sample rule to allow packet forwarding from your wg subnet
iptables -P FORWARD ACCEPT #change default policy on filter tables FORWARD chain