Proxy transparente con ubuntu 9

Forums: 

Hola chicos. Tengo una inquietud. Actualmente quiero montar un proxy transparente con mi ubuntu desktop. Hasta ahora, he instalado squid y lo he configurado, squid ha arrancado de buena forma; pero estoy teniendo problemas en la definición de las reglas de iptables. No logro que las paginas sean redireccionadas hacia el puerto, y que sean servidas a los PCs. Sé que es un problema de reglas.

También he activado ya el reenvio de paquetes en /etc/sysctl.conf a 1. Las configuraciones que estoy usando son:

Squid.conf:

http_port 3128 transparent
#http_port 80
#http_port 8080
icp_port 3130
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
cache_mem 64 MB
cache_swap_low 5590
cache_swap_high 5595
maximum_object_size 716800 KB
cache_dir ufs /var/spool/squid 20000 16 256
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
mime_table /etc/squid/mime.conf
client_netmask 255.255.255.0
ftp_user miguel@casianet.com
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl red_local src 192.168.0.0/255.255.255.0
acl aceptados src "/etc/squid/aceptados"
acl negados src "/etc/squid/negados"
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 563 # https, snews
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
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
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager
# Deny requests to unknown ports
http_access deny !Safe_ports
# Deny CONNECT to other than SSL ports
http_access deny CONNECT !SSL_ports
#http_access allow our_networks
http_access allow red_local aceptados !negados
# And finally deny all other access to this proxy
http_access deny all
http_reply_access allow all
icp_access allow all
store_avg_object_size 8192 KB
cache_mgr admin@casianet.com
#httpd_accel_port 80
#httpd_accel_host virtual
#httpd_accel_with_proxy on
#httpd_accel_uses_host_header on
coredump_dir /var/lib/squid/cache
offline_mode on
ie_refresh on

Y pues aqui viene el problema. En iptables si ingreso esta regla, ya estando activado el reenvío, las paginas se sirven, pero no se registran en el /var/log/squid/access.log, lo q me dice claramente qno estan pasando atraves del proxy. Las regla es:

iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

Ahi todo bien. Ahora, inclui esta regla:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128

para hacer que pasen por el proxy,pero ahi ya no anda la cosa.

Podrían indicarme un set correcto de reglas de iptables para compartir internet atraves de squid con ubuntitu? se que no estoy muy lejos de que funcione, pero estoy perdido de momento.

Gracias de antemano

Tienes 3 tarjetas de red?

Imagen de damage

Tienes 3 tarjetas de red? pregunto por que esta una eth2 en el enmascaramiento, seguro por esa interfaz sales a Internet??, la eth0 es la que esta del lado de tu LAN? en el PREROUTING especifica el source de donde vendran los paquetes con -s 192.168.x.x, aplica estos modulos te seran utiles:

modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_conntrack_irc
modprobe ip_conntrack_h323
modprobe ip_nat_h323
modprobe ipt_REJECT
modprobe ipt_TOS
modprobe ipt_MASQUERADE
modprobe ipt_LOG
modprobe iptable_mangle
modprobe iptable_nat
modprobe ip_nat_ftp
modprobe ip_nat_irc

Pon las reglas y lo que te he pasado en un archivo .sh o .rc como desees y lo haces ejecutable, asi tienes tu mini script de iptables. Ojo ademas fijate que no tengas politicas en DROP por default dinos que sale cuan iptables -nL.

Saludos

Hola, tengo 3 tarjetas, pero

Imagen de luiyirockero

Hola,

tengo 3 tarjetas, pero una es una wifi, y las otras 2 son ethernet...estoy usando las ethernet para esto, asi que uso eth0 y eth2

estoy ya haciendo el script...ahora, en cuanto a las reglas que me diste, adjunto las q me das a estas? o uso solo las tuyas? (pregunto por el enrutamiento hacia el proxy)

Gracias de antemano

Bien, la prueba de: iptables

Imagen de luiyirockero

Bien, la prueba de: iptables -nL arroja lo siguiente:

root@luis-laptop:/home/luis# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
root@luis-laptop:/home/luis#

hasta donde veo, luego de hacer un tail /var/log/squid/access.log:

root@luis-laptop:/home/luis# tail /var/log/squid/access.log
1246035913.541 155385 192.168.0.0 TCP_MISS/504 1557 GET http://es-es.start2.mozilla.com/firefox?client=firefox-a&rls=org.mozilla:es-ES:official - DIRECT/es-es.start2.mozilla.com text/html
1246035935.601 155963 192.168.0.0 TCP_MISS/504 1496 GET http://yahoo.com/ - DIRECT/yahoo.com text/html
1246035935.646 0 192.168.0.0 TCP_MISS/504 1518 GET http://yahoo.com/favicon.ico - DIRECT/yahoo.com text/html
1246035938.646 0 192.168.0.0 TCP_MISS/504 1518 GET http://yahoo.com/favicon.ico - DIRECT/yahoo.com text/html
1246036197.413 155479 192.168.0.0 TCP_MISS/504 1496 GET http://gmail.com/ - DIRECT/gmail.com text/html
1246036197.520 0 192.168.0.0 TCP_MISS/504 1518 GET http://gmail.com/favicon.ico - DIRECT/gmail.com text/html
1246036200.448 0 192.168.0.0 TCP_MISS/504 1518 GET http://gmail.com/favicon.ico - DIRECT/gmail.com text/html
1246036306.689 156217 192.168.0.0 TCP_MISS/504 1608 POST http://safebrowsing.clients.google.com/safebrowsing/downloads?client=navclient-auto-ffox&appver=3.0.8&pver=2.2&wrkey=AKEgNisGGq92OuZL8hkX68F0xRGDxHHjgLemD4ES808wE1SuJkAjj1VX-yvpg-BDjCM_JKhCwUfeHPbCmM62GWHcQw0h9Mq3xA== - DIRECT/safebrowsing.clients.google.com text/html
1246053068.425 155857 192.168.0.0 TCP_MISS/504 1576 GET http://es-es.www.mozilla.com/es-ES/firefox/central/ - DIRECT/es-es.www.mozilla.com text/html
1246053068.540 0 192.168.0.0 TCP_MISS/504 1554 GET http://es-es.www.mozilla.com/favicon.ico - DIRECT/es-es.www.mozilla.com text/html
root@luis-laptop:/home/luis#

Aunque al tiempo, se registra en el log de squid la pagina peticionada, en browser se muestra esto:

The requested URL could not be retrieved

While trying to retrieve the URL: http://es-es.www.mozilla.com/es-ES/firefox/central/

The following error was encountered:

Unable to determine IP address from host name for es-es.www.mozilla.com

The dnsserver returned:

Timeout

This means that:

The cache was not able to resolve the hostname presented in the URL.

Check if the address is correct.

Your cache administrator is admin@casianet.com.

Generated Fri, 26 Jun 2009 21:51:08 GMT by luis-laptop (squid/2.7.STABLE3)

La PC con ubuntu que tiene el proxy tiene los DNS establecidos, al igual que la PC cliente que solicita las paginas..aun asi tengo esta respuesta del proxy...

Alguna sugerencia?

Pues segun veo tus reglas no

Imagen de falcom

Pues segun veo tus reglas no estan cargandose
[quote]root@luis-laptop:/home/luis# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination[/quote]
si ejecutaste bien tu script de iptables??

Puedes llegar tanto desde el

Imagen de Root Bit

Puedes llegar tanto desde el Linux como desde las PCs de la red interna hacia los DNS ???

puedes pasar la salida del comando iptables -nL -t nat para verificar si efectivamente se esta realizando el redireccionamiento.

Saludos

There are only 10 types people in the world:
Those who understand binary and those who don't

Perdon por escribir tarde, no

Imagen de damage

Perdon por escribir tarde, no hay ninguna regla en input, output y forward, al menos estan en accept, ahora como te comentan da la salida que te sale con iptables -nL -t nat como te indican. Mira si no tienes el servicio de iptables corriendo y quizas eso te haga flush de reglas. si es así, para el inicio de iptables y genera tu script y lo ejecutas al iniciar el linux

Bien, ya de vuelta por acá

Imagen de luiyirockero

Bien, ya de vuelta por acá luego de sus respectiva sugerencias...

En cuanto a iptables, he utilizado estas reglas:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

Repitiendo a squid.conf he reordenado reglas quedando el squid.conf completo asi:

http_port 3128 transparent
#http_port 80
#http_port 8080
icp_port 3130
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
cache_mem 64 MB
cache_swap_low 5590
cache_swap_high 5595
maximum_object_size 716800 KB
cache_dir ufs /var/spool/squid 2000 16 256
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
#mime_table /etc/squid/mime.conf
client_netmask 255.255.255.0
ftp_user miguel@casianet.com
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl red_local src 192.168.0.0/255.255.255.0
#acl aceptados src "/etc/squid/aceptados"
acl negados url_regex "/etc/squid/negados"
acl msnmime req_mime_type ^application/x-msn-messenger
acl msngw url_regex -i gateway.dll
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 563 # https, snews
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
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
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager
# Deny requests to unknown ports
http_access deny !Safe_ports
# Deny CONNECT to other than SSL ports
http_access deny CONNECT !SSL_ports
#http_access allow our_networks
http_access deny msnmime
http_access deny msngw
http_access allow red_local !negados
#http_access deny negados
#aceptados !negados
#http_reply_access allow all
icp_access allow all
# And finally deny all other access to this proxy
http_access deny all
store_avg_object_size 8192 KB
cache_mgr admin@casianet.com
#httpd_accel_port 80
#httpd_accel_host virtual
#httpd_accel_with_proxy on
#httpd_accel_uses_host_header on
coredump_dir /var/lib/squid/cache
offline_mode on
ie_refresh on

De momento ya anda bien, y de hecho incluso ya configuré dhcp para mi red..y todo anda bien....en cuanto al problema q estuve teniendo, me resulta extraño lo siguiente, luego de aplicar las 2 reglas de iptables q cito arriba (las cuales funcionan) y aun con squid andando, es cuando no hay pagineo en las PCs....asi que hice pruebas ingresando las reglas de iptables y luego reiniciando squid.... asi es como funcionó el proxy transparente y el pagineo funciona muy bien...

Ahora bien, tengo 3 consultas..... donde ubico el archivo de las reglas de iptables para que se inicie automáticamente al iniciar el sistema? de hacer el archivo de reglas para que arranque con el sistema, donde se le llama y que permisos se le dan?

luego de ingresarlas directamente en consola, puede usarse el comando: iptables save para guardar? o es mejor hacer un archivo y llamarlo al arranque?

Gracias de antemano

Lo ubicas donde te sea mas

Imagen de damage

Lo ubicas donde te sea mas facil y mejor, yo personalmente creo un subdirectorio dentro de /etc y lo llamo firewall y dentro de este coloco el script el cual llamo firewall.sh, mira algo del manual de pello y veras como tener un script basico de iptables, luego de tenerlo edita el archivo rc.local que esta en /etc/rc.local en este archivo coloca la ruta donde este tu script de iptables en mi caso sería /etc/firewall/firewall.sh.
Los permisos luego de hacer el archivo deben ser estos:

chmod +x

Con eso lo haces ejecutable, puedes hacer otro script el cual llame al tu iptables script, y colocarlo dentro de init.d de manera que te quede como un servicio pero ya es hilar más fino.