rfontoura
(usa Debian)
Enviado em 23/05/2014 - 10:12h
bom, vamos lá.
o acesso ao sistema do servidor é feito via putty, e tem uma interface gráfica.
e fica caindo toda hora. e não é em todos os clientes.
segue o script do firewall
#======================================================
#! /bin/sh
# chkconfig: 235 99 10
# description: Start or stop the Webmin server
#
### BEGIN INIT INFO
# Provides: webmin
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Start or stop the Webmin server
### END INIT INFO
#! /bin/bash
#Variaveis
ifaceExt="eth0"; #acesso internet (onboard)
ifaceInt="eth1"; #acesso intranet (rede interna) (offboard)
LAN="192.168.1.0/24"; #rede local
WAN="xxx.xxx.xxx.xxx."; #ip fixo modem
#Carrega modulos
/sbin/modprobe ip_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_queue
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_nat
/sbin/modprobe iptable_mangle
/sbin/modprobe ipt_state
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_multiport
/sbin/modprobe ipt_mac
/sbin/modprobe ipt_string
/sbin/modprobe ipt_MASQUERADE
start(){
echo "Firewall iniciado ...................... [OK]";
#limpa as regras
iptables -F
iptables -X
iptables -Z
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -Z
#Politica padrao INPUT=DROP | OUTUPT=ACCEPT | FORWARD=DROP
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
#Bloquei ping externo para o servidor (ICMP)
iptables -A INPUT -i $ifaceExt -p icmp --icmp-type 8 -j DROP
#LIBERANDO PORTAS
#--------------------------------------------------------------------------------------------------------
#Libera porta ssh servidor
iptables -A INPUT -p tcp --dport 22 -i $ifaceInt -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -i $ifaceExt -j ACCEPT
#Libera porta webmail
iptables -A INPUT -p tcp --dport 2095 -i $ifaceInt -j ACCEPT
iptables -A INPUT -p tcp --dport 2095 -i $ifaceExt -j ACCEPT
#Libera porta ssh servidor
iptables -A INPUT -p tcp --dport 81 -i $ifaceInt -j ACCEPT
iptables -A INPUT -p tcp --dport 81 -i $ifaceExt -j ACCEPT
#Libera porta ssh externo
iptables -A INPUT -p tcp --dport 2222 -i $ifaceInt -j ACCEPT
iptables -A INPUT -p tcp --dport 2222 -i $ifaceExt -j ACCEPT
#Libera porta DVR externo
iptables -A INPUT -p tcp --dport 37707 -i $ifaceInt -j ACCEPT
iptables -A INPUT -p tcp --dport 37707 -i $ifaceExt -j ACCEPT
#Redireciona porta 2222 para 22
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 192.168.1.101:22
#Redireciona porta 22 para Servidor SG
iptables -t nat -A PREROUTING -p tcp --dport 22 -j DNAT --to-destination 192.168.1.101:22
#Redireciona porta 37707 para DVR
iptables -t nat -A PREROUTING -p tcp --dport 37707 -j DNAT --to-destination 192.168.1.107:37707
#Libera porta (HTTP)
iptables -A INPUT -s $LAN -p tcp --dport 8081 -j ACCEPT
iptables -A INPUT -s $LAN -p udp --dport 8081 -j ACCEPT
#Libera portas (Porta 22)
iptables -A INPUT -p tcp -s $LAN -d 192.168.1.101 --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp -s 192.168.1.101 -d $LAN --dport 22 -j ACCEPT
#Libera portas (Porta 80)
iptables -A INPUT -p tcp -s $LAN -d 192.168.1.5 --dport 81 -j ACCEPT
iptables -A OUTPUT -p tcp -s 192.168.1.5 -d $LAN --dport 81 -j ACCEPT
#Libera portas (camera ip)
iptables -A INPUT -p tcp -s $LAN -d 192.168.1.5 --dport 81 -j ACCEPT
iptables -A OUTPUT -p tcp -s 192.168.1.5 -d $LAN --dport 81 -j ACCEPT
#Libera porta (SQUID)
#iptables -A INPUT -s $LAN -p tcp --dport 3128 -j ACCEPT
#Libera portas para acesso ao servidor sgsistemas ssh
iptables -A FORWARD -p tcp -d 192.168.1.101 --destination-port 22 -j ACCEPT
#Libera portas para acesso ao servidor sgsistemas ssh
iptables -A FORWARD -p tcp -d 192.168.1.107 --destination-port 37707 -j ACCEPT
#Libera IP (SGHOST) - NOTA FISCAL
#==========================================================================
iptables -I FORWARD -p tcp --dport 8081 -d 177.72.161.165 -j ACCEPT
iptables -I FORWARD -p tcp --dport 8081 -d 177.72.161.165 -j ACCEPT
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 8081 -d 177.72.161.165 -j RETURN
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 8081 -d 177.72.161.165 -j RETURN
###
#Sistema SGHost Nota Fiscal nao passando pelo squid
iptables -t nat -A PREROUTING -i $ifaceInt -p tcp ! -d 177.72.161.165 --dport 8081 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -i $ifaceInt -p tcp ! -d 177.72.161.165 --dport 8081 -j REDIRECT --to-port 3128
#--------------------------------------------------------------------------
#Permite pacotes transmitidos atraves da interface de loopback (localhost)
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i $ifaceInt -j ACCEPT
iptables -A INPUT -i $ifaceExt -j ACCEPT
#Compartilha a conexao disponivel na interface de internet
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s $LAN -o $ifaceExt -j MASQUERADE
echo "Compartilhamento de rede ativo";
#Permitindo e filtrando conexao estabelecidas
iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A FORWARD -s $LAN -o $ifaceExt -j ACCEPT
#Direciona trafego para squid
iptables -t nat -A PREROUTING -i $ifaceInt -p tcp --dport 80 -j REDIRECT --to-port 3128
echo "Firewall ativado! ...................... [OK]";
}
stop(){
#limpa as regras
iptables -F
iptables -X
iptables -Z
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -t nat -F
iptables -t nat -X
iptables -t nat -Z
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -Z
#Politica padrao
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
#Compartilha a conexao disponivel na interface de internet
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s $LAN -o $ifaceExt -j MASQUERADE
echo "Compartilhamento de rede ativo";
#Permitindo e filtrando conexao estabelecidas
iptables -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A FORWARD -s $LAN -o $ifaceExt -j ACCEPT
#Proxy squid
iptables -t nat -A PREROUTING -i $ifaceInt -p tcp --dport 80 -j REDIRECT --to-port 3128
echo "Firewall desativado! ................... [OK]";
}
case "$1" in
"start") start ;;
"stop") stop ;;
"reload") stop; start ;;
*)
echo "Use parametros start|stop|reload" ;;
esac