Diego-Garcia
(usa Linux Mint)
Enviado em 10/10/2013 - 09:42h
O meu script de firewall esta assim:
-----------------------------------------------------------------------------------------------------------
#!/bin/sh -e
echo "# Limpando regras anteriores."
iptables -F
iptables -X
iptables -Z
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
echo "# Configuracao de interfaces."
IP_range=192.168.0.0/24 # Faixa de IP.
WAN_iface=eth0 # Conexao com a internet.
LAN_iface=eth1 # Conexao com a rede interna.
echo "# Modulo de repasse e conntrack que habilita a parte de status de conexao."
echo "1" > /proc/sys/net/ipv4/ip_forward
modprobe ip_conntrack
echo "# Policiamento. Tudo parado como sempre, assim, liberado o necessario."
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
echo "# Permitindo acesso do servidor pela internet e pela rede interna."
iptables -t filter -A INPUT -i $WAN_iface -j ACCEPT
iptables -t filter -A OUTPUT -o $WAN_iface -j ACCEPT
iptables -t filter -A INPUT -s $IP_range -j ACCEPT
iptables -t filter -A OUTPUT -d $IP_range -j ACCEPT
echo "# Liberado so o desejado para a rede interna."
iptables -t filter -A FORWARD -s $IP_range -p tcp --dport 80 -j ACCEPT
iptables -t filter -A FORWARD -s $IP_range -p tcp --dport 433 -j ACCEPT
iptables -t filter -A FORWARD -s $IP_range -p tcp --dport 8080 -j ACCEPT
#iptables -t filter -A FORWARD -s $IP_range -p tcp --dport 0:65535 -j ACCEPT
iptables -t filter -A FORWARD -m state --state ESTABLISHED,RELATED,NEW -j ACCEPT
echo "# Mascaramento."
iptables -t nat -A POSTROUTING -s $IP_range -o $WAN_iface -j MASQUERADE
echo "# Bloqueando Facebook e IPs."
iptables -N FACEBOOK
iptables -I FORWARD -s $IP_range -j FACEBOOK
for face in `cat /etc/squid3/acls/IPB`;do
iptables -A FACEBOOK -d $face -j REJECT
echo "# Liberando Facebook e IPs via MAC."
iptables -I FORWARD -m mac --mac-source 78:84:3C:32:8E:61 -d $face -j ACCEPT # Mauricio Lan
iptables -I FORWARD -m mac --mac-source 4C:0F:6E:D4:D9:9C -d $face -j ACCEPT # Mauricio Wireless
iptables -I FORWARD -m mac --mac-source 54:53:ED:B4:58:F1 -d $face -j ACCEPT # Fernando Lan
iptables -I FORWARD -m mac --mac-source 84:4B:F5:D5:36:A3 -d $face -j ACCEPT # Fernando Wireless
iptables -I FORWARD -m mac --mac-source E0:DB:55:A1:C7:C0 -d $face -j ACCEPT # Jacinta Lan
iptables -I FORWARD -m mac --mac-source BC:85:56:FC:58:CB -d $face -j ACCEPT # Jacinta Wireless
iptables -I FORWARD -m mac --mac-source 00:90:F5:93:F9:EC -d $face -j ACCEPT # Ricardo Lan
iptables -I FORWARD -m mac --mac-source 48:5D:60:0C:9F:8E -d $face -j ACCEPT # Ricardo Wireless
iptables -I FORWARD -m mac --mac-source 38:AA:3C:6B:A9:A4 -d $face -j ACCEPT # Carla Celular
iptables -I FORWARD -m mac --mac-source 10:D5:42:10:F5:91 -d $face -j ACCEPT # Geni Celular
done
echo "# Liberando Acesso Externo ao Tecnicon."
iptables -A FORWARD -p tcp --sport 8080 -j ACCEPT
iptables -A FORWARD -p tcp --dport 8080 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 8080 -j DNAT --to-destination 192.168.0.2:8080
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 8080 -j DNAT --to-destination 192.168.0.2:8080
echo "# Liberando Acesso Externo as Cameras."
iptables -A FORWARD -p tcp --sport 70 -j ACCEPT
iptables -A FORWARD -p tcp --dport 70 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 70 -j DNAT --to-destination 192.168.0.230:70
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 70 -j DNAT --to-destination 192.168.0.230:70
#
iptables -A FORWARD -p tcp --sport 4550 -j ACCEPT
iptables -A FORWARD -p tcp --dport 4550 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 4550 -j DNAT --to-destination 192.168.0.230:4550
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 4550 -j DNAT --to-destination 192.168.0.230:4550
#
iptables -A FORWARD -p tcp --sport 5550 -j ACCEPT
iptables -A FORWARD -p tcp --dport 5550 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 5550 -j DNAT --to-destination 192.168.0.230:5550
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 5550 -j DNAT --to-destination 192.168.0.230:5550
#
iptables -A FORWARD -p tcp --sport 6550 -j ACCEPT
iptables -A FORWARD -p tcp --dport 6550 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 6550 -j DNAT --to-destination 192.168.0.230:6550
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 6550 -j DNAT --to-destination 192.168.0.230:6550
#
iptables -A FORWARD -p tcp --sport 8866 -j ACCEPT
iptables -A FORWARD -p tcp --dport 8866 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 8866 -j DNAT --to-destination 192.168.0.230:8866
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 8866 -j DNAT --to-destination 192.168.0.230:8866
#
iptables -A FORWARD -p tcp --sport 5511 -j ACCEPT
iptables -A FORWARD -p tcp --dport 5511 -j ACCEPT
iptables -t nat -A PREROUTING -i $WAN_iface -p tcp --dport 5511 -j DNAT --to-destination 192.168.0.230:5511
iptables -t nat -A PREROUTING -i $WAN_iface -p udp --dport 5511 -j DNAT --to-destination 192.168.0.230:5511
echo "# Redirecionando porta 80 para 3128."
iptables -t nat -A PREROUTING -i $LAN_iface -p tcp --dport 80 -j REDIRECT --to-port 3128
exit 0;