The scenario

I am using a 3G modem. Unfortunately here it does not work as it should, being unstable and slow, most of time. Only 10% of the full contrated speed is guaranteed. It still is expensive, but for mobility, it is what it is. One other detail: I am always in the same sites. A great number the sites, but usually the same.

The solution

A proxy is the best way to make it go faster. According to wikipedia, a proxy is "a server (a computer system or an application program) that acts as a go-between for requests from clients seeking resources from other servers".

Thus, every web access will be requested to the proxy, and it will fetch it in Internet. This web page will remain a little in the system, because if it is requested again, some components will already be downloaded. That means that your browser will show the page faster.

We will see some changes to be made in proxy server, and some others in browser.

The Software

We'll be using Squid, a well-known proxy server, famous, free and widely used. This configuration is not difficult, but requires attention. You should know how to use vim.

Squid installation

As usual, installing a sofware in Ubuntu is a breeze. We will work using CLI, instead of GUI. I recommend you to copy the commands written here and paste them in BASH, to avoid typos.

First, let's assure that Ubuntu has informtion about the most recent packages. Open the CLI, and paste the following lines:

sudo aptitude update

sudo aptitude install squid

Remeber that if you want, you can dispose the whole squid configuration with the following lines:

sudo chattr -i /etc/squid/squid.conf.original

sudo rm /etc/squid/squid.conf.original

sudo aptitude purge squid

You need vim to be installed. If you are not sure about it, copy this line and paste it on Bash:

sudo aptitude install vim

Squid Configuration

First of all, let's do a backup copy of it's configuration file:

sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.original

sudo chattr +i /etc/squid/squid.conf.original

Squid Configuration file has lots of comments. They are really helpful, but can be annoying sometimes. So we will "clean" it all:

sudo egrep -v "^$|^ *#" \

/etc/squid/squid.conf.original > /etc/squid/squid.conf

We must know the version of our software. This is how I can identify squid version:

sudo dpkg -p squid

 

Package: squid

Priority: optional

Section: web

Installed-Size: 1748

Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>

Architecture: i386

Version: 2.7.STABLE3-4.1ubuntu1

Replaces: squid-novm

Depends: libc6 (>= 2.4), libcomerr2 (>= 1.01), libdb4.7, libkrb53 (>= 1.6.dfsg.2), libldap-2.4-2 (>= 2.4.7), libpam0g (>= 0.99.7.1), netbase, adduser, logrotate (>= 3.5.4-1), squid-common (>= 2.7.STABLE3-4.1ubuntu1), lsb-base (>= 3.2-14), ssl-cert (>= 1.0-11ubuntu1)

Pre-Depends: debconf (>= 1.2.9) | debconf-2.0

Suggests: squidclient, squid-cgi, logcheck-database, resolvconf (>= 0.40), smbclient, winbind

Conflicts: sarg (<<>

</ubuntu-devel-discuss@lists.ubuntu.com>

This another way to do te same:

 

sudo dpkg -l | grep squid

In my system, this was the result:

ii squid 2.7.STABLE3-4.1ubuntu1 Internet object cache (WWW proxy cache)

Note that if your version is different, may ther be some differences.

 

Finally, let's start with the changes in Squid:

sudo vim /etc/squid/squid.conf -c ":set number"

I did the following changes:

...

35 icp_access deny all

36 http_port 127.0.0.1:3128

37 hierarchy_stoplist cgi-bin ?

...

48 extension_methods REPORT MERGE MKACTIVITY CHECKOUT

49 dns_nameservers 200.169.116.23 200.169.116.22

50 hosts_file /etc/hosts

Line 36 makes my Ubuntu more secure. In line 49 I stated both DNS IPs from my provider. acrescentei a linha 49, com os IPs do DNS do meu provedor. If you don't know about these IPs (they should be given by your ISP), you may see them in your Ubuntu system:

sudo cat /etc/resolv.conf

In my system, I had the following:

nameserver 200.255.121.39

nameserver 200.169.117.14

After these changes, we need to restart squid. So, let's do it:

sudo /etc/init.d/squid reload

To assure it is working, we can search the open ports. Squid uses port 3128:

sudo netstat -ltnp | grep -i squid

In my system:

tcp 0 0 127.0.0.1:3128 0.0.0.0:* OUÇA 3216/(squid)

What is bold in this line, is the same content of line 36 of squid's configuration file.

Browser configuration

The changes in our browser will be much easier. Let's do it in Firefox, which is already present in Ubuntu:

Let's first access Preferences, in edit menu.

After, we need to push Advanced button. In network tab, click on CONFIGURE.

Do the same changes I did in this screen. Mine is in Brazilian Portuguese, but the fields are in the same place.

It is done. Proxy server installed and configured, and browser configured to talk to proxy server. In my computer, in about 8 days of use, I had the folowing use of HD:

sudo du -sh /var/spool/squid/

32M /var/spool/squid/

You should always control the space used by squid. If it increases too much, you can empty this cache. Type the following:

sudo squid -z

 

This article which was retrieved from Postado por, A few drops about Linux, linuxdrops.blogspot.com (last visited Sep. 17, 2009), is licensed under a Creative Commons Atribuição 2.5 Brasil License