edu_dm
(usa Slackware)
Enviado em 22/02/2011 - 11:43h
olá amigos tenho um servidor aki com squid e firewall, apos um problema na máquina tive que formatar e o firewall que estava funcionando blza deu um pau aki a porta do squid naun fica transparente nem a pau so configurando o navegador, segue abaixo o script:
#!/bin/bash
fire_start() {
echo 1 > /proc/sys/net/ipv4/ip_forward
# ---------------------------------VARIAVEIS DE AMBIENTE
IPTABLES=`which iptables`
INTNET="172.16.0.0/24"
EXTDEV="eth0"
POLICY="DROP"
INTDEV="eth1"
FIREWALL="172.16.0.1"
PROXY_PORT="3128"
# CARREGAR MODULOS
echo -n " Carregando modulos "
modules="
ip_queue
ip_tables
ipt_ECN
ipt_LOG
ipt_MARK
ipt_MASQUERADE
ipt_NETMAP
ipt_REDIRECT
ipt_REJECT
ipt_SAME
ipt_TOS
ipt_TTL
ipt_addrtype
ipt_ah
ipt_ecn
ipt_iprange
ipt_owner
ipt_recent
ipt_tos
ipt_ttl
iptable_filter
iptable_mangle
iptable_nat
iptable_raw
nf_conntrack_ipv4
nf_nat
nf_nat_amanda
nf_nat_ftp
nf_nat_h323
nf_nat_irc
nf_nat_pptp
nf_nat_proto_gre
nf_nat_sip
nf_nat_snmp_basic
nf_nat_tftp
ipt_REJECT
ipt_TOS
ipt_LOG
iptable_mangle
iptable_filter
iptable_nat
ip_nat_ftp
ip_conntrack
ip_conntrack_ftp
ip_conntrack_irc
ip_nat_irc
ipt_mac
ipt_state
ipt_mark
ip_nat_pptp
ip_conntrack_pptp
"
for module in $modules; do
modprobe $module 2>/dev/null 1>/dev/null
echo -n "."
done
echo "OK"
# zera tudo
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -X
# LOOPBACK
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT
# liberar smtp e pop
$IPTABLES -A FORWARD -p tcp -m multiport --dport 25,110,443 -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -p tcp -m multiport --dport 25,110,443 -o $EXTDEV -j MASQUERADE
# Liberar conectividade social
$IPTABLES -A FORWARD -d 200.201.173.0/24 -j ACCEPT
$IPTABLES -A FORWARD -d 200.201.174.0/24 -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -d 200.201.173.0/24 -o $EXTDEV -j MASQUERADE
$IPTABLES -A POSTROUTING -t nat -d 200.201.174.0/24 -o $EXTDEV -j MASQUERADE
# Acesso Liberado (Rede Interna --> Firewall ----> Internet )
echo -n " Liberando usuarios com acesso privilegiado"
for LIBERADOS in `cat /etc/firewall/fullaccess |awk '{print $1}'`; do
$IPTABLES -A FORWARD -s $LIBERADOS -j ACCEPT
$IPTABLES -A POSTROUTING -t nat -s $LIBERADOS -o $EXTDEV -j MASQUERADE
done
echo -n "."
echo "."
echo "OK"
echo "."
echo "OK"
# Proxy transparente
$IPTABLES -t nat -A PREROUTING -i $INTDEV -p tcp --dport 80 -j REDIRECT --to-port $PROXY_PORT
# Acesso webmin
$IPTABLES -A INPUT -p tcp --dport 10000 -j ACCEPT
# Acesso ssh
$IPTABLES -A INPUT -p tcp --dport 22 -j ACCEPT
# liberar ping
$IPTABLES -A FORWARD -p icmp -j ACCEPT
$IPTABLES -A INPUT -p icmp -j ACCEPT
# vpn
$IPTABLES -A INPUT -i $EXTDEV -p tcp --dport 1723 -j ACCEPT
$IPTABLES -A INPUT -p 50 -j ACCEPT
# liberar dns
$IPTABLES -A FORWARD -p udp --dport 53 -j ACCEPT
$IPTABLES -A INPUT -p udp --dport 53 -j ACCEPT
# Rede Interna acessa o firewall
$IPTABLES -A INPUT -s $INTNET -j ACCEPT
# conexoes estabelecidas
$IPTABLES -t filter -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -t filter -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# Setando politica padrao
$IPTABLES -P INPUT $POLICY
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD $POLICY
# Gerar log
# $IPTABLES -A FORWARD -j LOG --log-prefix "FORWARD-DROP: "
# $IPTABLES -A INPUT -j LOG --log-prefix "INPUT-DROP: "
}
fire_stop() {
IPTABLES=`which iptables`
echo "Desativando Firewall..."
$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F
$IPTABLES -X
$IPTABLES -X -t nat
$IPTABLES -Z
$IPTABLES -F INPUT
$IPTABLES -F OUTPUT
$IPTABLES -F POSTROUTING -t nat
$IPTABLES -F PREROUTING -t nat
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
}
fire_restart() {
fire_stop
sleep 1
fire_start
}
case "$1" in
'start')
fire_start
;;
'stop')
fire_stop
;;
'restart')
fire_restart
;;
*)
echo "use $0 start|stop|restart"
esac