thiago_th
(usa Red Hat)
Enviado em 02/08/2012 - 14:32h
Boa tarde,
Segue abaixo o meu script:
=====================================
. /etc/rc.status
rc_reset
case "$1" in
start)
echo -n "Starting Firewall Rules: "
iptables -F
iptables -F -t nat
iptables -X
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1400:1536 -j TCPMSS --clamp-mss-to-pmtu
########REGRAS DE QOS PARA VOIP
##LIMPAR REGRAS
tc qdisc del dev eth0 root
tc qdisc del dev eth1 root
#eth1
tc qdisc add dev eth1 root handle 1: htb default 20
tc class add dev eth1 parent 1: classid 1:1 htb rate 1900kbps
###RESERVA PARA O VOIP
tc class add dev eth1 parent 1:1 classid 1:10 htb rate 300kbps ceil 300kbps prio 0
###RESTANTE DOS PACOTES
tc class add dev eth1 parent 1:1 classid 1:20 htb rate 1600kbps ceil 1600kbps prio 7
tc qdisc add dev eth1 parent 1:10 handle 10: sfq perturb 1
tc qdisc add dev eth1 parent 1:20 handle 20: sfq perturb 1
##ATAS DO VOIP
tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.0.122 flowid 1:10
match ip src 192.168.0.167 flowid 1:20
tc filter add dev eth1 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.0.124 flowid 1:10
iptables -t mangle -A PREROUTING -i eth1 -s 192.168.0.122 -j TOS --set-tos 16
iptables -t mangle -A PREROUTING -i eth1 -s 192.168.0.124 -j TOS --set-tos 16
#eth0
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1: classid 1:1 htb rate 1900kbps
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 300kbps ceil 300kbps prio 0
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 1600kbps ceil 1600kbps prio 7
tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 1
tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 1
##ATAS VOIP
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.0.122 flowid 1:10
#tc filter add dev eth0 protocol ip parent 1:0 prio 7 u32 match ip src 192.168.0.167 flowid 1:20
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.0.124 flowid 1:10
iptables -t mangle -A PREROUTING -i eth0 -s 192.168.0.122 -j TOS --set-tos 16
iptables -t mangle -A PREROUTING -i eth0 -s 192.168.0.124 -j TOS --set-tos 16
###########################FIM DO QOS
LAN="192.168.0.0/24"
echo -n "trojans, "
iptables -A FORWARD -d 208.185.211.71 -j DROP
iptables -A FORWARD -d 200.216.69.230 -j DROP
###BLOQUEAR CONEXOES EXTERNAS A PORTA 3128 - 02/08/2012
iptables -A INPUT -p tcp -s 192.168.0.0/255.255.255.0 --dport 3128 -j ACCEPT
iptables -A INPUT -p tcp --dport 3128 -j DROP
echo -n "transproxy, "
iptables -A PREROUTING -t nat -s $LAN -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
NEW,ESTABLISHED,RELATED -j MASQUERADE
##################
### FTP
iptables -A FORWARD -p tcp -s $LAN --dport 21 -j ACCEPT
iptables -A FORWARD -p tcp -s $LAN --dport 20 -j ACCEPT
###########REDIRECIONAMENTOS
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 2222 -j DNAT --to-destination 192.168.0.254:22
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 2223 -j DNAT --to-destination 192.168.0.253:22
#####REGRAS DO SERVIDOR 1######
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8081 -j DNAT --to-dest 192.168.0.1
iptables -A FORWARD -p tcp -i eth0 --dport 8081 -d 192.168.0.1 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 4550 -j DNAT --to-dest 192.168.0.1
iptables -A FORWARD -p tcp -i eth0 --dport 4550 -d 192.168.0.1 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 5550 -j DNAT --to-dest 192.168.0.1
iptables -A FORWARD -p tcp -i eth0 --dport 5550 -d 192.168.0.1 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 6550 -j DNAT --to-dest 192.168.0.1
iptables -A FORWARD -p tcp -i eth0 --dport 6550 -d 192.168.0.1 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8866 -j DNAT --to-dest 192.168.0.1
iptables -A FORWARD -p tcp -i eth0 --dport 8866 -d 192.168.0.1 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 5511 -j DNAT --to-dest 192.168.0.1
iptables -A FORWARD -p tcp -i eth0 --dport 5511 -d 192.168.0.1 -j ACCEPT
##########REGRAS DO SERVIDOR 2########
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to-dest 192.168.0.2
iptables -A FORWARD -p tcp -i eth0 --dport 8080 -d 192.168.0.2 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8060 -j DNAT --to-dest 192.168.0.2
iptables -A FORWARD -p tcp -i eth0 --dport 8060 -d 192.168.0.2 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8061 -j DNAT --to-dest 192.168.0.2
iptables -A FORWARD -p tcp -i eth0 --dport 8061 -d 192.168.0.2 -j ACCEPT
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8062 -j DNAT --to-dest 192.168.0.2
iptables -A FORWARD -p tcp -i eth0 --dport 8062 -d 192.168.0.2 -j ACCEPT
##########REGRAS DA VPN PARA O SERVIDOR 3############
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 6559 -j DNAT --to-dest 192.168.0.3
iptables -A FORWARD -p udp -i eth0 --dport 6559 -d 192.168.0.3 -j ACCEPT
##########GERADOR DE LOGS############
iptables -A INPUT -p tcp --dport 1004 -j LOG
iptables -A FORWARD -p tcp --dport 1004 -j LOG
iptables -A OUTPUT -p tcp --dport 1004 -j LOG
iptables -A INPUT -p tcp --dport 22 -j LOG
iptables -A FORWARD -p tcp --dport 22 -j LOG
iptables -A OUTPUT -p tcp --dport 22 -j LOG
echo ok
rc_status -v
;;
stop)
echo -n "Shutting down Firewall Rules"
iptables -F
iptables -t nat -F
iptables -X
rc_status -v
;;
restart)
$0 stop && $0 start
rc_status
;;
reload)
;;
status)
echo "Checking for Firewall Rules: "
echo "============================ "
iptables -nL
echo
echo "----------------- NAT Table: "
iptables -nL -t nat
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
rc_exit