<div dir="ltr">Hi Amos.<div><br></div><div>Thank you for your advice. I applied the instructionts that you have sent it to me in this link: <a href="https://wiki.squid-cache.org/ConfigExamples/Intercept/LinuxRedirect">https://wiki.squid-cache.org/ConfigExamples/Intercept/LinuxRedirect</a> and the <a href="https://wiki.squid-cache.org/ConfigExamples/Intercept/IptablesPolicyRoute">https://wiki.squid-cache.org/ConfigExamples/Intercept/IptablesPolicyRoute</a>, the case of: "<span style="color:rgb(0,0,0);font-family:Arial,"Lucida Grande",sans-serif;font-size:1.1em">When Squid is Internal amongst clients" and the section:  </span><span style="color:rgb(0,0,0);font-family:Arial,"Lucida Grande",sans-serif;font-size:1.3em">Routing Setup. Now I can see the squid is intercepting the traffic however, it is not applying my policies:</span></div><div><span style="color:rgb(0,0,0);font-family:Arial,"Lucida Grande",sans-serif;font-size:1.3em"><br></span></div><div>http_access deny cliente_linux sitios2<br>http_access deny cliente_windows sitios1<br>http_access allow mi_red<br></div><div><br></div><div>"sitios2"=facebook</div><div><div>"sitios1"=youtube</div><div> these policies work when I set up manually the proxy. Do you have any idea of how to troubleshoot this?</div><div>Thank you for your help</div><div><br></div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 16, 2022 at 11:35 PM Amos Jeffries <<a href="mailto:squid3@treenet.co.nz">squid3@treenet.co.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 17/11/2022 9:14 am, Lola Lo wrote:<br>
> Hi guys.<br>
><br>
><br>
> Could you please send a tutorial or any good guidance to implement  <br>
> squid on transparent mode on centos 9 with iptables.<br>
><br>
<br>
The configuration details for what you appear to be trying to configure <br>
are here:<br>
  <<a href="https://wiki.squid-cache.org/ConfigExamples/Intercept/LinuxRedirect" rel="noreferrer" target="_blank">https://wiki.squid-cache.org/ConfigExamples/Intercept/LinuxRedirect</a>><br>
<br>
My comments below relate to how your attempt differs and how to fix.<br>
<br>
> I have configured squid.conf with this parameters:<br>
><br>
><br>
><br>
> ens192: 172.31.168.28, internet interface<br>
><br>
> ens224: 192.168.1.10, LAN interface (private network)<br>
><br>
><br>
> # Mis ACLs #<br>
><br>
> acl mi_red src <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>><br>
><br>
> acl cliente_linux src 192.168.1.20<br>
><br>
> acl cliente_windows src 192.168.1.30<br>
><br>
> acl sitios1 url_regex "/etc/squid/listas/sitios1"<br>
><br>
> acl sitios2 url_regex "/etc/squid/listas/sitios2"<br>
><br>
><br>
> # Squid normally listens to port 3128<br>
><br>
> http_port 3128<br>
><br>
> http_port 8080 transparent<br>
><br>
><br>
<br>
Firstly, use "intercept" instead of "transparent" with modern Squid.<br>
<br>
Secondly, remember that only port 8080 is setup to receive intercepted <br>
traffic. Port 3128 still receives normal forward-proxy traffic.<br>
<br>
> I want the “deny all” rule get applied to test the client using the proxy<br>
><br>
><br>
<br>
You have not shown any http_access lines from your config. There is a <br>
clear bug in your NAT which explains the behaviour so I will assume that <br>
the squid.conf policy does what you want.<br>
<br>
<br>
> My iptables is configured as follows:<br>
><br>
><br>
> #!/bin/bash<br>
><br>
><br>
> ## NAT server configuration ##<br>
><br>
><br>
> sysctl -w net.ipv4.ip_forward=1<br>
><br>
> sysctl -p<br>
><br>
> iptables -X<br>
><br>
> iptables -F<br>
><br>
> iptables -t nat -X<br>
><br>
> iptables -t nat -F<br>
><br>
> iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT<br>
><br>
> iptables -I FORWARD-m state --state RELATED,ESTABLISHED -j ACCEPT<br>
><br>
> iptables -t nat -I POSTROUTING -o ens192 -j MASQUERADE<br>
><br>
><br>
><br>
<br>
Why is this a different script?<br>
Ideally the firewall rules should be as atomic as possible to avoid <br>
connections being setup with only part of the rules applied.<br>
<br>
<br>
><br>
> #!/bin/bash<br>
><br>
><br>
> ## proxy server configuration ##<br>
><br>
><br>
> ### Accepting traffic for the ports: 3128 and 8080##<br>
><br>
><br>
> iptables -A INPUT -s <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>> -p tcp <br>
> --dport 3128 -j ACCEPT<br>
><br>
> iptables -A INPUT -p tcp --dport 3128 -j DROP<br>
><br>
<br>
Do not accept traffic directly to the port 8080. Also Squid does not <br>
make outbound connections from its listening ports.<br>
So these ...<br>
<br>
> iptables -A OUTPUT -d <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>> -p tcp <br>
> --sport 3128 -j ACCEPT<br>
><br>
> iptables -A OUTPUT -p tcp --sport 3128 -j DROP<br>
><br>
><br>
> iptables -A INPUT -s <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>> -p tcp <br>
> --dport 8080 -j ACCEPT<br>
><br>
> iptables -A INPUT -p tcp --dport 8080 -j DROP<br>
><br>
> iptables -A OUTPUT -d <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>> -p tcp <br>
> --sport 8080 -j ACCEPT<br>
><br>
> iptables -A OUTPUT -p tcp --sport 8080 -j DROP<br>
><br>
><br>
<br>
... should be replaced with:<br>
<br>
   iptables -t mangle -A PREROUTING -p tcp --dport 8080 -j DROP<br>
<br>
<br>
><br>
> `### Accepting traffic for the ports: 3128 and 8080##<br>
><br>
><br>
> iptables -t nat -A POSTROUTING -o ens192 -j MASQUERADE<br>
><br>
<br>
You are missing a rule to allow Squid outbound traffic to avoid the NAT.<br>
<br>
   iptables -t nat -A PREROUTING -s 192.168.1.10 -p tcp --dport 80 -j ACCEPT<br>
<br>
> iptables -t nat -A PREROUTING -s <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <br>
> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>> -p tcp --dport 80 -j REDIRECT --to-port 8080<br>
><br>
> iptables -t nat -A PREROUTING -s <a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">192.168.1.0/24</a> <br>
> <<a href="http://192.168.1.0/24" rel="noreferrer" target="_blank">http://192.168.1.0/24</a>> -p tcp --dport 443 -j REDIRECT --to-port 8080<br>
><br>
><br>
<br>
Port 8080 in your squid.conf can only handle port 80 traffic syntax.<br>
<br>
Port 443 is a more tricky situation. I recommend removing that until you <br>
have the port 80 working.<br>
<br>
<br>
><br>
> But I got this error:<br>
><br>
><br>
> 1668381894.7460 192.168.1.20 NONE_NONE/000 0 - <br>
> error:transaction-end-before-headers - HIER_NONE/- -<br>
><br>
> 1668381967.8000 192.168.1.20 NONE_NONE/400 3690 - <br>
> error:invalid-request - HIER_NONE/- text/html<br>
><br>
<br>
This is likely from the missing NAT rule allowing Squid outbound.<br>
<br>
If the above changes do not fix everything make sure that you test <br>
exactly what the real clients will be doing. Specifically that they are <br>
making contact to servers on port 80 or directly to Squid port 3128. <br>
They know *nothing* about port 8080 existence so have no reason to send <br>
anything that way directly.<br>
<br>
<br>
HTH<br>
Amos<br>
<br>
_______________________________________________<br>
squid-users mailing list<br>
<a href="mailto:squid-users@lists.squid-cache.org" target="_blank">squid-users@lists.squid-cache.org</a><br>
<a href="http://lists.squid-cache.org/listinfo/squid-users" rel="noreferrer" target="_blank">http://lists.squid-cache.org/listinfo/squid-users</a><br>
</blockquote></div>