CHULETA REDIRECCIONAMIENTO, SSH Y UFW
Configuracion Router Debian, /etc/network/interfaces:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp0s3
iface enp0s3 inet dhcp
auto enp0s8
iface enp0s8 inet static
address [Link]
netmask [Link]
up iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE #(red interna > internet)
iptables –t nat –A POSTROUTING –o enp0s8 –j MASQUERADE #(red interna > internet)
Configurar el router para que enrute, /etc/[Link] . Cambiamos ip_forward a 1.
sysctl -p para confirmar los cambios
Configuracion del cliente en la lan1:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enp0s3
iface enp0s3 inet static
address [Link]
netmask [Link]
gateway [Link]
dns-nameservers [Link] [Link]
Configuracion del cliente en la lan2:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug enp0s3
iface enp0s3 inet static
address [Link]
netmask [Link]
gateway [Link]
dns-nameservers [Link] [Link]
Configuracion router Ubuntu:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
addresses: [[Link]/24]
routes:
- to: default
via: [Link]
dhcp4: no
nameservers:
addresses: [[Link]]
enp0s8:
addresses: [[Link]/24]
Script en /etc/[Link]:
#!/bin/bash
# activar forwarding
sysctl -w net.ipv4.ip_forward=1
# habilitar NAT
iptables -t nat -F
iptables -t nat -A POSTROUTING -s [Link]/24 -j MASQUERADE
iptables -t nat -A PREROUTING -p tcp --dport 2022 -j DNAT --to-destination [Link]:22
iptables -t nat -A PREROUTING -p tcp --dport 8888 -j DNAT --to-destination [Link]:80
En /lib/systemd/system/[Link] creamos un script para que se inicie cada vez que encendemos
la maquina:
[Unit]
Description=Script iptables para enrutado
After=[Link]
[Service]
Type=forking
ExecStart=/etc/[Link]
[Install]
WantedBy=[Link]
wget <ip> para descagar el [Link] en una maquina sin entorno grafico
UFW
Ufw status, enable, disable
Las políticas por defecto están en el fichero /etc/default/ufw, podemos cambiarlas (reafirmarlas porque
coinciden con las políticas por defecto) con el siguiente comando
ufw default deny incoming
ufw default allow outgoing
En nuestro caso queremos que, además, enrute, así que damos permiso para que lo haga
ufw default allow routed
Las reglas de para el redireccionamiento (forwarding) y las reglas NAT se colocan en el fichero de
configuración /etc/ufw/[Link].
# rules should be added to one of these chains:
# ufw-before-input
# ufw-before-output
# ufw-before-forward
*nat
:PREROUTING ACCEPT [0:0]
# redirige [Link] puerto 80 a [Link]:80
-A PREROUTING -i enp0s3 -d [Link] -p tcp --dport 80 -j DNAT --to-destination [Link]:80
# inicializar routing
-A POSTROUTING -o enp0s3 -j MASQUERADE
COMMIT
en el archivo de conf de interfaces, comentamos o borramos las reglas de iptables ya que hacen la
misma funcion.