Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ## Scrip de IPTABLES
- ## Cortafuegos - Servidor de Red Local y Acceso a Internet
- ##
- ## Interfaces
- ## ----------------
- ## eth1 - Internet
- ## eth2 - Local
- echo -n Aplicando las Reglas del Cortafuegos...
- REDLOCAL="172.17.1.0/24"
- # Cambiar Puerto 8080 por 3128 si se desea SQUID sin DANSGUARDIAN (Ver Prerouting abajo)
- ACEPTAR_TCP_ENTRADA_LAN="21 22 53 80 135 136 137 138 139 443 445 631 901 1863 2200 5222 5229 5269 3128 8000 8008 8080 8443 9090 9091 9256 10000"
- DENEGAR_TCP_ENTRADA_LAN="1433"
- ACEPTAR_UDP_ENTRADA_LAN="22 135 136 137 138 139 1194 1863 9256"
- DENEGAR_UDP_ENTRADA_LAN="1433"
- ACEPTAR_TCP_ENTRADA_WAN="22 1194 1863 2200"
- DENEGAR_TCP_ENTRADA_WAN="25 110 113 135 136 137 138 139 1433 3128 8000 8443"
- ACEPTAR_UDP_ENTRADA_WAN="22 53 1194 1863"
- DENEGAR_UDP_ENTRADA_WAN="67 68 135 136 137 138 139 1433"
- DENEGAR_TCP_SPT_WAN="25 1863"
- ACEPTAR_TCP_FORWARD="22 25 53 80 110 137 138 139 443 445 1194 1863 2200 2121 2222 3128 5222 5229 5260 5900 6667 7767 8008 8080 8443 9090 9091 9256 10000"
- DENEGAR_TCP_FORWARD=""
- ACEPTAR_UDP_FORWARD="53 863 1194 1863 5222 5229 5900 7777 9090 9256"
- DENEGAR_UDP_FORWARD=""
- # -------------------- NO MODIFICAR A PARTIR DE AQUI -------------------- #
- # Se limpian y se eliminan todas las reglas anteriores
- iptables -F
- iptables -t nat -F
- iptables -X
- # Politicas por defecto
- iptables -P INPUT ACCEPT
- #iptables -P FORWARD ACCEPT
- # Allow TUN interface connections to OpenVPN server
- iptables -A INPUT -i tun+ -j ACCEPT
- # Allow TUN interface connections to be forwarded through other interfaces
- iptables -A FORWARD -i tun+ -j ACCEPT
- # Se acepta el loopback y las conexiones establecidas
- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- # iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -i lo -j ACCEPT
- iptables -A INPUT -i lo -j ACCEPT
- # Se habilita el ping
- iptables -A INPUT -p icmp -j ACCEPT
- #iptables -A FORWARD -p icmp -j ACCEPT
- # ============= DANSGUARDIAN ============
- # Redireccionamiento para el DANSGUARDIAN
- iptables -t nat -A PREROUTING -i eth2 -p tcp --dport 80 -j REDIRECT --to-port 8080
- # Regla para lograr el NAT
- iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
- # Permitir entrada de DHCP
- iptables -A INPUT -i eth2 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
- # Ciclos para variables - No modificar nada
- for puerto in $ACEPTAR_TCP_ENTRADA_LAN;
- do
- iptables -A INPUT -p tcp --dport $puerto -i eth2 -j ACCEPT
- done
- for puerto in $DENEGAR_TCP_ENTRADA_LAN;
- do
- iptables -A INPUT -p tcp --dport $puerto -i eth2 -j DROP
- done
- for puerto in $ACEPTAR_UDP_ENTRADA_LAN;
- do
- iptables -A INPUT -p udp --dport $puerto -i eth2 -j ACCEPT
- done
- for puerto in $DENEGAR_UDP_ENTRADA_LAN;
- do
- iptables -A INPUT -p udp --dport $puerto -i eth2 -j DROP
- done
- # Variable cambiada en servidor de Punto Fijo por prueba aqui queda igual
- for puerto in $ACEPTAR_TCP_ENTRADA_LAN;
- do
- iptables -A INPUT -p tcp --dport $puerto -i eth2 -j ACCEPT
- done
- # Variable
- for puerto in $DENEGAR_TCP_ENTRADA_LAN;
- do
- iptables -A INPUT -p tcp --dport $puerto -i eth2 -j DROP
- done
- # variable
- for puerto in $ACEPTAR_UDP_ENTRADA_LAN;
- do
- iptables -A INPUT -p udp --dport $puerto -i eth2 -j ACCEPT
- done
- for puerto in $DENEGAR_UDP_ENTRADA_LAN;
- do
- iptables -A INPUT -p udp --dport $puerto -i eth2 -j DROP
- done
- for puerto in $ACEPTAR_TCP_ENTRADA_WAN;
- do
- iptables -A INPUT -p tcp --dport $puerto -i eth1 -j ACCEPT
- done
- for puerto in $DENEGAR_TCP_ENTRADA_WAN;
- do
- iptables -A INPUT -p tcp --dport $puerto -i eth1 -j DROP
- done
- for puerto in $ACEPTAR_UDP_ENTRADA_WAN;
- do
- iptables -A INPUT -p udp --dport $puerto -i eth1 -j ACCEPT
- done
- for puerto in $DENEGAR_UDP_ENTRADA_WAN;
- do
- iptables -A INPUT -p udp --dport $puerto -i eth1 -j DROP
- done
- for puerto in $DENEGAR_TCP_SPT_WAN;
- do
- iptables -A INPUT -p tcp --sport $puerto -i eth1 -j DROP
- done
- for puerto in $ACEPTAR_TCP_FORWARD;
- do
- iptables -A FORWARD -p tcp --dport $puerto -j ACCEPT
- iptables -A FORWARD -p tcp --sport $puerto -j ACCEPT
- done
- for puerto in $DENEGAR_TCP_FORWARD;
- do
- iptables -A FORWARD -p tcp --dport $puerto -j DROP
- done
- for puerto in $ACEPTAR_UDP_FORWARD;
- do
- iptables -A FORWARD -p udp --dport $puerto -j ACCEPT
- iptables -A FORWARD -p udp --sport $puerto -j ACCEPT
- done
- for puerto in $DENEGAR_UDP_FORWARD;
- do
- iptables -A FORWARD -p udp --dport $puerto -j DROP
- done
- ## Comentar las siguientes seis lineas para permitir descargas de archivos FTP
- #iptables -A FORWARD -s ! $REDLOCAL -d ! $REDLOCAL -j LOG --log-prefix " ## ### ### ### "
- #iptables -A FORWARD -s ! $REDLOCAL -d ! $REDLOCAL -j DROP
- #iptables -A INPUT -j LOG
- #iptables -A INPUT -j DROP
- #iptables -A FORWARD -j LOG
- #iptables -A FORWARD -j DROP
- ## Reglas de prueba para evitar Denegacion de Servicios (DoS) ## Añadido por ellanos
- iptables -A FORWARD -p tcp --syn -m limit --limit 1/s --limit-burst 1 -j ACCEPT
- iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s --limit-burst 1 -j ACCEPT
- iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s --limit-burst 1 -j ACCEPT
- echo "CORTAFUEGOS CONFIGURADO.................. [ OK ]"
- echo "1" > /proc/sys/net/ipv4/ip_forward
- # Fin del Scrip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement