Home > Hacking, Hardware, Software, linux > Keeping tabs on your bandwidth usage

Keeping tabs on your bandwidth usage

January 22nd, 2010 Leave a comment Go to comments

I run a business which rents out fully serviced office space on a short and long term basis.  One of the services I offer my customers is internet access.

During the last few months the average ADSL bandwidth usage has grown to over 50 GB per month.  As bandwidth is still relatively expensive in SA (I use Afrihost’s excellent value for money ADSL at R29/GB) I needed to see where this actually goes.

The solution is a ubuntu based linux server with a collection of different open source products installed, plugged into the network just before the traffic enters the internet.

The ideal place for this server is between the network switch and the default gateway.  All traffic from devices on the inside of the bridge will now have to pass through the bridge server before entering the internet.

The server contains two network interfaces and is configured in bridge mode, allowing network traffic to pass through the server transparently, without even being aware of being scanned.

The key to this working is by bridging both ethernet interfaces together, using the ubuntu bridge-utils package and brctl command. Also make sure that http traffic  destined for the web gets redirected to dansguardian for filtering before leaving the network.

Using bridge mode has the added advantagew that it is not only completely invisible, it also require no changes on the existing netork pc’s. As long as it is placed just before the external gateway / firewall then all traffic will pass through it, including hardware devices like wifi routers, etc.

Once the server is installed, configured and switched into bridge mode the necessary monitoring software is installed. I use squid as a proxy server, dansguardian for traffic filtering and ntop for bandwith monitoring.

Dansguardian is great for rule based filtering, but comes with a static set of rules. I expanded my configuration by adding blacklists from shalla. The shalla lists are broken down by category and contains over 1.3 million entries.  As the lists are updated frequently I configured a cron job to download the lists nightly and copy it to the appropriate folders.

In dansguardian I then enable the specific categories that needs to be blocked, like porn, gambling, etc. Dansguard also contains exception lists for blocking or unblocking specific sites, keywords or ip addresses.

Another handy feature of dansguardian is that is uses clamav to automatically scan all downloaded files for virusses before letting it through.

Squid is configured as a transparent proxy server, allowing traffic caching and reporting. 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.

Ntop is used to monitor and report on all network traffic passing through the server. When configuring ntop make sure to set it to watch the external interface only, so you do not pick up traffic not destined for the internet.

Iptables is used as a firewall for blocking specific protocols or destinations, and also for forwarding all HTTP traffic destined for the internet to dansguardian, which applies its rule based filters and then pass the traffic on to squid, which in turn passes it on to the internet if not served from the local cache.

Some outstanding issues is dealing effectively with bittorrent and peer to peer traffic, without having to create countless manual rules. For now the ntop reports give clear usage by source, target, protocol, etc. It is relatively easy to identify bandwith hogs and deal with them, but it takes time and is a re-active process rather than being pro-active.

Next step is to automate the creation of iptable firewall rules on the fly to filter traffic as it is identified as inappropriate. Another todo is to add is to scan mail for spam and virusses.

  1. February 25th, 2010 at 08:53 | #1

    If your clients are paying to use the internet, why use dansguardian to filter content? You should have them pay per gb and have them do what they want with it. The more gb’s they use, the more they have to buy from you.

    Instead of Ntop, have you had a look at Darkstat yet? I’ve seen that ntop is quite a resource hog.

  2. February 25th, 2010 at 13:21 | #2

    Hi Stephen, I use dansguardian to virus scan traffic but also to filter out illegal movies and mp3 downloads.
    There is also a quality issue, as I want all users to get a good connection. If someone downloads a large file (movie) then it takes all the bandwidth and all the other users get a degraded service.
    I did look at darkstat but it is a bit too limited in the depth of stats it provides, but agree, it is usefull where a lightweight monitoring solution is required.

  3. March 4th, 2010 at 09:50 | #3

    Hi, does anyone know of someone in Cape Town who can set up/maintain my Linux proxy currently running Squid?

  4. March 4th, 2010 at 10:21 | #4

    Hi Gerhard, does it have to be someone based in Cape Town?
    Maybe you can open up ssh or openvpn access to the box for someone to do the config remotely?

  1. No trackbacks yet.