All pastes #358794 Raw Edit

iptablesconf

public shellscript v1 · immutable
#358794 ·published 2007-02-16 12:06 UTC
rendered paste body
#### SCRIPT DE CONFIGURACION DE IPTABLES PARA PC1 #####!/bin/bash# Dispositivo de red de internet (ip pública, viene del modem fibertel)EXIF="eth1" # Dispositivo de red local (ip:192.168.0.1, el que va a pc2 y notebook por el bridge)INIF="eth0"# Puertos tcp que se desean redirigir a pc2 (separados por espacios)# Para aMule:xxxxx, BT:xxxxx, FW:xxxxxpc2TCP="xxxxx xxxxxx xxxxx xxxxx"# Puertos udp que se desean redirigir a pc2 (separados por espacios)# Para aMule:xxxxxx, BT:xxxxxx, FW:xxxxxx, DC++:xxxxxx y xxxxxxpc2UDP="xxxxx xxxxx xxxxx xxxxx xxxxx"# Puertos tcp que se desean redirigir a notebook (separados por espacios)# Para aMule:xxxxx, BT:xxxxx, FW:xxxxxntbkTCP="xxxxx xxxxxx xxxxx xxxxx"# Puertos udp que se desean redirigir a notebook (separados por espacios)# Para aMule:xxxxxx, BT:xxxxxx, FW:xxxxxx, DC++:xxxxxx y xxxxxxntbkUDP="xxxxx xxxxx xxxxx xxxxx xxxxx"# IPs a las que se les redirigen los puertospc2="192.168.0.2"notebook="192.168.0.3"fail=0[ -f /etc/default/rcS ] && . /etc/default/rcS. /lib/lsb/init-functionslog_begin_msg "Aplicando Reglas de Firewall..."## Borrado de reglas anterioresiptables -F || fail=1iptables -X || fail=1iptables -Z || fail=1iptables -t nat -F || fail=1## Establecemos politica por defectoiptables -P INPUT ACCEPT || fail=1iptables -P OUTPUT ACCEPT || fail=1iptables -P FORWARD DROP || fail=1iptables -t nat -P PREROUTING ACCEPT || fail=1iptables -t nat -P POSTROUTING ACCEPT || fail=1# Marcar paquetes salientes con su ip de origeniptables -t nat -A POSTROUTING -o $EXIF -j MASQUERADE || fail=1# Reenvio de IPecho 1 > /proc/sys/net/ipv4/ip_forward || fail=1# Aceptar paquetes para reenviar procedentes de la red localiptables -A FORWARD -i $INIF -o $EXIF -j ACCEPT || fail=1# Aceptar paquetes para reenviar procedentes de internet de conexiones ya establecidasiptables -A FORWARD -i $EXIF -o $INIF -m state --state RELATED,ESTABLISHED -j ACCEPT || fail=1# Se redirigen los puertos configurados arribafor puerto in $pc2TCPdoiptables -A FORWARD -i $EXIF -o $INIF -p tcp --dport $puerto -j ACCEPT || fail=1iptables -t nat -A PREROUTING -i $EXIF -p tcp --dport $puerto -j DNAT --to $pc2:$puerto || fail=1donefor puerto in $pc2UDPdoiptables -A FORWARD -i $EXIF -o $INIF -p udp --dport $puerto -j ACCEPT || fail=1iptables -t nat -A PREROUTING -i $EXIF -p udp --dport $puerto -j DNAT --to $pc2:$puerto || fail=1donefor puerto in $ntbk2TCPdoiptables -A FORWARD -i $EXIF -o $INIF -p tcp --dport $puerto -j ACCEPT || fail=1iptables -t nat -A PREROUTING -i $EXIF -p tcp --dport $puerto -j DNAT --to $notebook:$puerto || fail=1donefor puerto in $ntbk2UDPdoiptables -A FORWARD -i $EXIF -o $INIF -p udp --dport $puerto -j ACCEPT || fail=1iptables -t nat -A PREROUTING -i $EXIF -p udp --dport $puerto -j DNAT --to $notebook:$puerto || fail=1done# Se muestran los resultadoslog_end_msg $failif [ $fail -eq 0 ]thenlog_success_msg "Verifique que lo que se aplica con: iptables -L -n."elselog_warning_msg "Se ha producido un error al aplicar alguna de las reglas"fi#### FIN SCRIPT DE CONFIGURACION DE IPTABLES ####