Recent Posts

Sponsors
![]() |
How to install basic Squid on FreeBSDMichel Nadeau, 10-02-2009 |
Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. It runs on most available operating systems, including Windows and is licensed under the GNU GPL.
This tutorial describes how to install a very simple implementation of Squid on your network.
1. Getting started
The first thing you want to do is to download Squid. In this tutorial, we're going to work in the /usr/local/src directory.
Then you want to extract Squid and change to its directory:
We're now ready to compile and install Squid!
2. Compiling/installing Squid
Compiling and installing Squid is very easy:
If the configure command fails because you don't have Perl, you can simply install it like this:
Then re-run the configure command.
3. Configuring Squid
First of all, you need to add the "visible_hostname" setting in your Squid configuration file. The main configuration file is:
Open it with your favorite editor and find this block:
At the end of the block (before the next "TAG" block), insert a new line and put something like this:
Replace "freebsd" with any hostname you want Squid to use - it can be a local hostname or a fully qualified domain name. Save the file.
Now you need to adjust some permissions before Squid can be initialized...
Squid can now be initialized. Use this command:
Squid is now ready to run!
4. Starting/stopping Squid
Starting Squid:
Stopping Squid:
You can start Squid automatically at boot time by creating the /usr/local/etc/rc.d/squid.sh file with this content:
You also need to allow execution of this file:
5. Using Squid with your browser
To use Squid with your browser, you simply need to set it as a proxy in your browser's settings. Squid is listening on TCP port 3128. So if your FreeBSD machine's IP is 1.2.3.4, you will configure your proxy to be 1.2.3.4, port 3128.
Once configured, all the traffic over the chosen protocols (usually your browser lets you choose for which protocols you want to use a proxy) will go through your Squid server.
6. "Overriding" Web sites addresses
The first place where Squid is looking when it comes to resolving URL's to IP addresses is in the /etc/hosts file. If you want to "override" Web sites addresses, simply add them in the /etc/hosts file along with the IP address where you want to redirect traffic.
For example, let's say that you want your Squid's users to be sent to 1.2.3.4 when they request www.google.com instead of to the real google.com. To do so, you will add this line in your /etc/hosts file:
Replace "1.2.3.4" with the IP of the machine where you want to redirect traffic. This isn't really a "redirect" as the users will never see 1.2.3.4 in their browser. For them, it will look like just as if they were really on www.google.com, not on 1.2.3.4.
NOTE: you NEED to restart Squid when you make changes in /etc/hosts.
Conclusion
Squid is very simple to install and use. Though, it's also VERY powerful and flexible: it has literally thousands of options! This tutorial only covered the very basic use - refer to the Squid users guide if you want to customize squid.conf.
Resources
* Squid
* Configuration guide
* Configuration examples
* Users guide
This tutorial describes how to install a very simple implementation of Squid on your network.
1. Getting started
The first thing you want to do is to download Squid. In this tutorial, we're going to work in the /usr/local/src directory.
$ mkdir -p /usr/local/src
$ cd /usr/local/src
$ wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE19.tar.gz
$ cd /usr/local/src
$ wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE19.tar.gz
Then you want to extract Squid and change to its directory:
$ tar xvfz squid-3.0.STABLE19.tar.gz
$ cd squid-3.0.STABLE19
$ cd squid-3.0.STABLE19
We're now ready to compile and install Squid!
2. Compiling/installing Squid
Compiling and installing Squid is very easy:
$ ./configure --prefix=/usr/local/squid
$ make all
$ make install
$ make all
$ make install
If the configure command fails because you don't have Perl, you can simply install it like this:
$ pkg_add -r perl
Then re-run the configure command.
3. Configuring Squid
First of all, you need to add the "visible_hostname" setting in your Squid configuration file. The main configuration file is:
/usr/local/squid/etc/squid.conf
Open it with your favorite editor and find this block:
# TAG: visible_hostname
At the end of the block (before the next "TAG" block), insert a new line and put something like this:
visible_hostname freebsd
Replace "freebsd" with any hostname you want Squid to use - it can be a local hostname or a fully qualified domain name. Save the file.
Now you need to adjust some permissions before Squid can be initialized...
$ mkdir -p /usr/local/squid/var/logs/
$ chmod 777 /usr/local/squid/var/logs/
$ mkdir -p /usr/local/squid/var/cache/
$ chmod 777 /usr/local/squid/var/cache/
$ chmod 777 /usr/local/squid/var/logs/
$ mkdir -p /usr/local/squid/var/cache/
$ chmod 777 /usr/local/squid/var/cache/
Squid can now be initialized. Use this command:
/usr/local/squid/sbin/squid -z
Squid is now ready to run!
4. Starting/stopping Squid
Starting Squid:
/usr/local/squid/sbin/squid
Stopping Squid:
kill -9 `cat /usr/local/squid/var/logs/squid.pid`
You can start Squid automatically at boot time by creating the /usr/local/etc/rc.d/squid.sh file with this content:
#!/bin/sh
/usr/local/squid/sbin/squid
/usr/local/squid/sbin/squid
You also need to allow execution of this file:
$ chmod 755 /usr/local/etc/rc.d/squid.sh
5. Using Squid with your browser
To use Squid with your browser, you simply need to set it as a proxy in your browser's settings. Squid is listening on TCP port 3128. So if your FreeBSD machine's IP is 1.2.3.4, you will configure your proxy to be 1.2.3.4, port 3128.
Once configured, all the traffic over the chosen protocols (usually your browser lets you choose for which protocols you want to use a proxy) will go through your Squid server.
6. "Overriding" Web sites addresses
The first place where Squid is looking when it comes to resolving URL's to IP addresses is in the /etc/hosts file. If you want to "override" Web sites addresses, simply add them in the /etc/hosts file along with the IP address where you want to redirect traffic.
For example, let's say that you want your Squid's users to be sent to 1.2.3.4 when they request www.google.com instead of to the real google.com. To do so, you will add this line in your /etc/hosts file:
1.2.3.4 google.com www.google.com
Replace "1.2.3.4" with the IP of the machine where you want to redirect traffic. This isn't really a "redirect" as the users will never see 1.2.3.4 in their browser. For them, it will look like just as if they were really on www.google.com, not on 1.2.3.4.
NOTE: you NEED to restart Squid when you make changes in /etc/hosts.
Conclusion
Squid is very simple to install and use. Though, it's also VERY powerful and flexible: it has literally thousands of options! This tutorial only covered the very basic use - refer to the Squid users guide if you want to customize squid.conf.
Resources
* Squid
* Configuration guide
* Configuration examples
* Users guide
![]() |
yasir, 01-31-2012 |
Thx Mate :) That was helpful.
![]() |
syawal, 03-27-2012 |
I can't access ftp server with this config. adding
acl FTP proto FTP
always_direct allow FTP
not solving problem. what should I do so I can acces ftp server. thank in advance.
acl FTP proto FTP
always_direct allow FTP
not solving problem. what should I do so I can acces ftp server. thank in advance.
![]() |
ali fraz khan, 04-27-2012 |
great job...... may u blessed.....
![]() |
Zamir Jimenez Casado, 05-11-2012 |
thanks my friend Michael
|

Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments