Showing posts with label squid. Show all posts
Showing posts with label squid. Show all posts

Friday, February 3, 2012

Squid Proxy Server Configuration

Question about Squid proxy server:


I've just installed a squid cache server on a linux machine, the hierarchy is like this :




Code:

WAN LINK


|


------------- ---------------------


| Mikrotik Box | | Cache Linux Server |


------------- ----------------------


| /


| /


----------------------


| Switch ( Cheap one ) |


----------------------


| | |


Client1 Client2 Client3 etc.








What i'm trying to do is, I want all the traffic regarding to port 80 from Client1,Client2,Client3 to be forwarded to my Cache server at port 8080.


I tried with redirect rule, but it seems it only maps ports on his own and can't redirect somewhere else.




Any idea how to do this?




Thanks


Answer:


You have to use action=dstnat, as well do not forget to specify to-addresses, where you have to put squid address.


action=redirect is used to redirect traffic to router itself.


To do this, if you have squid version 2.6 you have to edit the squid configuration file (squid.conf) putting the following line:




http_port 3128 transparent


instead of




http_port 3128




Of course the command "http_port 3128" is the default squid proxy port configuration.




If you are using Webmin, you have to specify the option "transparent" on:




Servers -> Squid Proxy Server -> Ports and Networking



I think that the problem could be on the access lists of the proxy server.


What happens should be the following:




1. the hotspot receives your request no the Wireless interface and nat it to the proxy server address and proxy server port (to do it you should have configured the ip firewall nat rules on the Mikrotik);


2. when the hotspot forwards the request to the proxy server, it is forwarded not with the original address, but with the address of the interface which communicates with the proxy as the source address (the WAN address??), and it happens even if you don't enable the webproxy feature on it;


3. then, if you at the moment on the proxy server have an access list which permits just the network configured on the hotspot interface, it could be not enough.




I hope this could help you.


Another solution:



I am using a similar proxy setup as you are and it is working 100%. Just make sure you have the parent proxy port set up corectly, this stuffed me around initialy, here is my config. Note that this is not my gateway router with the wan's connected but the router behind it.




Code:

1 chain=dstnat action=redirect to-ports=8080 protocol=tcp dst-port=80




2 chain=srcnat action=masquerade







Code:

enabled: yes


src-address: 0.0.0.0


port: 8080


parent-proxy: 10.172.3.2


parent-proxy-port: 800


cache-administrator: ""


max-cache-size: none


cache-on-disk: no


max-client-connections: 1000


max-server-connections: 1000


max-fresh-time: 11h6m


serialize-connections: no


always-from-cache: yes


cache-hit-dscp: 4


cache-drive: system







Hope this helps.




Friday, January 27, 2012

Add Mikrotik ass SQUID proxy server


To add SQUID Proxy Caching Server support in Mikrotik, Assuming the following Scenario.


DSL MODEM IP = 192.168.1.1




MIKROTIK LAN IP = 10.0.0.1



SQUID LAN IP = 192.168.2.1




I assume that you already have working Mikrotik in place, and Already configured SQUID Server ready, (You can search guides about there configurations at my blog), I will just show you how to interconnect them together so All users browsing port 80 request will go to SQUID for caching facility)


We will divide this article in two sections.


1# MIKROTIK CONFIGURATION




2# SQUID CONFIGURATION


1# MIKROTIK CONFIGURATION


Mikrotik Have 3 Interfaces.


ether1 = 10.0.0.1




Connected to LAN


ether2 = 192.168.2.2




Connected Directly to PROXY's eth0 via crossover cable.


ether3 = 192.168.1.2




Connected Directly to WAN/DSL




As shown in the image below . . .



Open New Terminal and create new NAT rule to redirect port 80 traffic to SQUID proxy server. Command as follows.















1/ip firewall nat










2add action=dst-nat chain=dstnat disabled=no dst-port=80 protocol=tcp to-addresses=192.168.2.1 to-ports=8080




[192.168.2.2 is the SQUID proxy server ip]


As shown in the image below . . .





That's it for mikrotik configuration, moving on to squid


2# SQUID CONFIGURATION


SQUID PROXY SERVER have two Interfaces


eth0 = 192.168.2.1




Connected Directly with Mikrotik's PROXY interface via crossover cable.


eth1 = 192.168.1.3




Connected Directly with WAN/DSL


Note: I Will not discuss howto configure SQUID here as it have already been well described in my other articles as follows, Therefore I assume you have already configured SQUID and must be running it in TRANSPARENT mode (using squid.conf directives and iptables)


Add the following line in /etc/squid/squid.conf















1# PORT and Transparent Option










2http_port 8080 transparent




For iptables to redirect user request to port 8080 transparently, Add the following line in /etc/rc.local or issue the command at CLI,















1iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.2.1:8080




Where eth0 is LAN interface of SQUID.


Now Try to Browse, and at Proxy Server , Monitor SQUID Log by following command













1tail -f /var/log/squid/access.log




and you will see User Browsing request coming via Mikrotik ip.


As shown in the image below . . .





If you want to log USER's Original IP address instead of Mikrotik, Either add route in Squid server for your local user subnet pointing to mikrotik proxy interface, OR you have to use Packet Marking + ROUTING method as described in the following article.


Source