rodolfobertelli
(usa Ubuntu)
Enviado em 25/10/2011 - 10:41h
Bom dia,
obrigado pela atenção,
segue meu firewall e a configuração do squid e das interfaces da rede.
Não tem nada de mais nesse servidor, minha real intenção é fazer a VPN funcionar e esta funcionando.
Mas preciso que além da VPN, que tenha uma navegação normal na internet.
Bom a internet a rádio tem um IP fixo, configurei no roteador e coloquei DHCP e o servidor esta pegando o IP 192.168.1.2 na ETH0, já na ETH1 configurei com IP fixo coloquei na rede 10.1.1.0 e coloquei o ip do servidor como 10.1.1.1
Para melhor analise segue a configuração das interfaces da rede:
# The loopback network interface
auto lo
iface lo inet loopback
#(ETH0)
auto eth0
iface eth0 inet dhcp
#(ETH1)
auto eth1
iface eth1 inet static
address 10.1.1.1
netmask 255.255.255.0
network 10.1.1.0
broadcast 10.1.1.255
FIREWALL:
#!/bin/bash
openvpn --config /etc/openvpn/client.ovpn --daemon
echo '************ Iniciando Firewall ******************';
ipt=/sbin/iptables
echo '************ Limpar regras ***********************';
$ipt -t filter -F
$ipt -t nat -F
$ipt -t mangle -F
echo '************ Definindo Politicas Padrao **********';
$ipt -P INPUT DROP #entrada
$ipt -P FORWARD ACCEPT #redirecionar
$ipt -P OUTPUT ACCEPT #saida
echo '************ Levantando mdprobes *****************';
modprobe iptable_nat
modprobe ip_conntrack
modprobe iptable_filter
modprobe iptable_nat
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/eth1/proxy_arp
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
echo '************ Setando Regras NAT ******************';
$ipt -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
$ipt -t nat -A POSTROUTING -s 10.1.1.0/24 -o eth0 -j MASQUERADE
$ipt -t filter -I INPUT -p udp --sport 53 --dport 1024:65535 -j ACCEPT
$ipt -t filter -I INPUT -p tcp -m state --state RELATED,ESTABLISHED -j ACCEPT
echo '************ Setando Regras INPUT ****************';
$ipt -A INPUT -i lo -j ACCEPT
$ipt -A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
$ipt -A INPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
$ipt -A INPUT -p icmp -m icmp --icmp-type 5 -j ACCEPT
$ipt -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
$ipt -A INPUT -p icmp -m icmp --icmp-type 12 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp --tcp-flags ALL SYN,ACK -j DROP
$ipt -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A INPUT -m state --state INVALID -j DROP
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 80 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 137 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 137 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 10.1.1.0/24 --dport 137 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 138 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 10.1.1.0/24 --dport 138 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 139 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 10.1.1.0/24 --dport 139 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 445 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 10.1.1.0/24 --dport 445 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 3128 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 10.1.1.0/24 --dport 3128 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 6891 -j DROP
$ipt -A INPUT -p udp -m udp -s 10.1.1.0/24 --dport 6891 -j DROP
$ipt -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp --dport 2222 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 0/0 --dport 137 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 0/0 --dport 137 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 0/0 --dport 138 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 0/0 --dport 138 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 0/0 --dport 139 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 0/0 --dport 139 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 0/0 --dport 445 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 0/0 --dport 445 -j ACCEPT
$ipt -A INPUT -p tcp -m tcp -s 0/0 --dport 1195 -j ACCEPT
$ipt -A INPUT -p udp -m udp -s 0/0 --dport 1195 -j ACCEPT
#$ipt -A INPUT -s 10.0.0.0/8 -d loginnet.passport.com -j REJECT
#$ipt -A INPUT -s 10.0.0.0/8 -d messenger.hotmail.com -j REJECT
#$ipt -A INPUT -s 10.0.0.0/8 -d webmessenger.msn.com -j REJECT
$ipt -A INPUT -p TCP -i eth1 --dport 6891:6900 -j DROP
$ipt -A INPUT -p TCP -i eth1 --dport 6891:6900 -j DROP
$ipt -A INPUT -p TCP -i eth1 --dport 6901 -j DROP
$ipt -A INPUT -p UDP -i eth1 --dport 6901 -j DROP
echo '*******Liberando o Apache para o Mundo *************';
#$ipt -A INPUT -p tcp -i eth0 --dport 80 -j ACCEPT
# Liberar conexao FTP
#iptables -A INPUT -s 0/0 -p tcp --dport 20:21 -j ACCEPT
echo '************ Setando Regras OUTPUT ***************';
$ipt -A OUTPUT -o lo -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 21 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 80 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 137 -j ACCEPT
$ipt -A OUTPUT -p udp -m udp -s 10.1.1.0/24 --dport 137 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 138 -j ACCEPT
$ipt -A OUTPUT -p udp -m udp -s 10.1.1.0/24 --dport 138 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 139 -j ACCEPT
$ipt -A OUTPUT -p udp -m udp -s 10.1.1.0/24 --dport 139 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 445 -j ACCEPT
$ipt -A OUTPUT -p udp -m udp -s 10.1.1.0/24 --dport 445 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 3128 -j ACCEPT
$ipt -A OUTPUT -p udp -m udp -s 10.1.1.0/24 --dport 3128 -j ACCEPT
$ipt -A OUTPUT -p tcp -m tcp -s 10.1.1.0/24 --dport 6891 -j DROP
$ipt -A OUTPUT -p udp -m udp -s 10.1.1.0/24 --dport 6891 -j DROP
$ipt -A OUTPUT -p tcp -m tcp -s 0/0 --dport 1195 -j ACCEPT
$ipt -A OUTPUT -p udp -m udp -s 0/0 --dport 1195 -j ACCEPT
echo '************ Setando Regras FORWARD **************';
$ipt -A FORWARD -p tcp -m tcp -m multiport -d 10.1.1.0/24 --dports 21,22,25,53,80,110,443,1080,1863,3128 -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp --icmp-type 0 -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp --icmp-type 3 -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp --icmp-type 5 -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp --icmp-type 8 -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp --icmp-type 12 -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp -m limit --limit 1/s -j ACCEPT
$ipt -A FORWARD -p icmp -m icmp -j ACCEPT
#$ipt -A FORWARD -j LOG --log-prefix "IPTables FW:FORWARD"
$ipt -A FORWARD -m state --state INVALID -j DROP
$ipt -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$ipt -A FORWARD -p tcp -m tcp --syn -m limit --limit 1/s -j ACCEPT
$ipt -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
$ipt -A FORWARD -p tcp -m tcp -o eth1 -s 10.1.1.0/24 -j ACCEPT
$ipt -A FORWARD -s 10.1.1.0/24 -p tcp -m tcp --dport 1080 -j REJECT
$ipt -A FORWARD -s 10.1.1.0/24 -p tcp -m tcp --dport 1836 -j REJECT
$ipt -A FORWARD -p tcp -m tcp -s 0/0 --dport 1195 -j ACCEPT
$ipt -A FORWARD -p udp -m udp -s 0/0 --dport 1195 -j ACCEPT
$ipt -A FORWARD -p tcp -m tcp --dport 6891:6900 -j DROP
$ipt -A FORWARD -p udp -m udp --dport 6891:6900 -j DROP
$ipt -A FORWARD -s 10.1.1.0/24 -j ACCEPT
echo '************* LIBERANDO VPN COM A MATRIZ" **********';
iptables -I FORWARD -s 172.16.1.0/24 -j ACCEPT
iptables -I FORWARD -d 172.16.1.0/24 -j ACCEPT
iptables -t nat -I POSTROUTING -s 10.0.0.0/24 -d 10.1.1.0/24 -j MASQUERADE
route add -net 10.0.0.0 netmask 255.255.255.0 gw 172.16.1.1 dev tun0
echo '************* Firewall Aplicado **********';
______________________________________________________________________________________
Configuração do squid:
http_port 3128 transparent
cache_mem 100 MB
cache_swap_low 95
cache_swap_high 98
maximum_object_size 6144 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 100 KB
ipcache_size 1024
ipcache_low 95
ipcache_high 98
cache_replacement_policy lru
memory_replacement_policy lru
cache_dir ufs /var/cache/squid 500 16 16
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log none
emulate_httpd_log off
client_netmask 255.255.255.255
#Default:
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
cache_mgr ********* ou entre em contato com seu Administrador
#cache_effective_user proxy
#cache_effective_group proxy
#visible_hostname proxy
cache_effective_user *
cache_effective_group *
visible_hostname *
acl SSL_ports port 443 563
acl Safe_ports port 80 21 443 563 70 210 1025-65535
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
acl NOCACHE url_regex -i "/etc/squid/direto.txt" \?
no_cache deny NOCACHE
always_direct allow NOCACHE
acl all src 10.1.1.0/255.255.255.0
always_direct allow all
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
#acl diretores src 10.1.1.2
acl rede src 10.1.1.0/255.255.255.0
acl negapalavra url_regex "/etc/squid/negapalavra.txt"
acl liberapalavra url_regex "/etc/squid/liberapalavra.txt"
acl negasites dstdomain "/etc/squid/negasites.txt"
acl horario time MTWHF 08:00-11:30 13:20-17:30
acl bloqueia url_regex "/etc/squid/horarios.txt"
acl MIME_MSN rep_mime_type -i application/x-msn-messenger
acl URL_MSN url_regex -i "/etc/squid/url_msn.txt"
#http_access allow diretores
http_access deny negasites rede
http_access deny negapalavra rede
http_access deny horario bloqueia
http_access allow URL_MSN
#http_access deny MIME_MSN
http_access allow localhost
http_access allow rede
http_access allow manager localhost
http_access allow liberapalavra rede
#http_access allow diretores
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny rede
http_access deny all