jedg_logo

UFW

Utilizo el firewall sencillo de Ubuntu porque está disponible en Ubuntu y es muy simple.

Instalar UFW

Si ufw no está instalado de forma predeterminada, asegúrese de instalarlo primero.

$ sudo apt-get install ufw

NAT

Si necesitaba ufw para NAT las conexiones desde la interfaz externa a la interna, la solución es bastante sencilla. En el archivo /etc/default/ufw cambie el parámetro DEFAULT_FORWARD_POLICY

DEFAULT_FORWARD_POLICY="ACCEPT"

También configure /etc/ufw/sysctl.conf para permitir el reenvío ipv4 (los parámetros están comentados de forma predeterminada). Descomente para ipv6 si lo desea.

net.ipv4.ip_forward=1
#net/ipv6/conf/default/forwarding=1
#net/ipv6/conf/all/forwarding=1

El último paso es agregar NAT a la configuración de ufw. Agregue lo siguiente a /etc/ufw/before.rules justo antes de las reglas de filtro.

# NAT table rules
*nat
:POSTROUTING ACCEPT [0:0]

# Forward traffic through eth0 - Change to match you out-interface
-A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

# don't delete the 'COMMIT' line or these nat table rules won't
# be processed
COMMIT

Ahora habilite los cambios reiniciando ufw.

$ sudo ufw disable && sudo ufw enable

REENVÍO

Para el reenvío de puertos simplemente haga algo como esto.

# NAT table rules
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]

# Port Forwardings
-A PREROUTING -i eth0 -p tcp --dport 22 -j DNAT --to-destination 192.168.1.10

# Forward traffic through eth0 - Change to match you out-interface
-A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

# don't delete the 'COMMIT' line or these nat table rules won't
# be processed
COMMIT