# User Network Quota...

## Utoxin

I did a quick search, and couldn't find anything to help with this, so I'll ask.

I'm trying to find a way to monitor network usage per-user on a Gentoo box, so that I can determine if I need to start enforcing some usage restrictions. (Info on how to enforce the limits would be nice too.)

Thanks.

----------

## pjp

Have you looked into 'emerge -s quota'?

```
Searching...   

[ Results for search key : quota ]

[ Applications found : 1 ]

 

*  sys-apps/quota

      Latest version available: 3.03

      Latest version installed: [ Not Installed ]

      Homepage: http://sourceforge.net/projects/linuxquota/

      Description: Linux quota tools
```

----------

## rac

I haven't tried it, but it looks like iptables might be able to do what you want here with the owner match and LOG target options.

----------

## Utoxin

 *kanuslupus wrote:*   

> Have you looked into 'emerge -s quota'?
> 
> ```
> Searching...   
> 
> ...

 

That's Hard Disk quotas. Already got that installed.  :Wink: 

----------

## Utoxin

 *rac wrote:*   

> I haven't tried it, but it looks like iptables might be able to do what you want here with the owner match and LOG target options.

 

Thanks, I'll look into it.

----------

## Utoxin

Well, iptables looks like it can do the job. The one concern I have, is that I want to make sure it's totally transparent. It sounds like it is, but maybe who's used it could verify that for me?

(And I'll be using the source/destination port matches, actually, not the owner.)

----------

## Utoxin

Just an update.

iptables is going to work beautifully, and it will do more than I 'needed' too. I'm going to be doing traffic logging to a MySQL database, to allow me to build graphs of bandwidth usage by every user on my machine. I'll also be able to throttle their bandwidth usage, or disable it if they reach a certain amount.

Thanks for the pointer! It's going to work perfectly. In 3 hours, I'm rebooting the server to load iptables into the kernel.

----------

## splooge

That sounds outstanding, I hope you will share your code ;p

----------

## meyerm

 *Utoxin wrote:*   

> I'll also be able to throttle their bandwidth usage, or disable it if they reach a certain amount.

 

Great! I just can add another time: please share your code/ideas!  :Smile:  It could save many hours of spare admin-time in all those school- or university-networks.  :Wink: 

----------

## Utoxin

Okay. Here's my basic setup:

Latest Gentoo Kernel (with some patches. Keep reading)

MySQL

ulogd (to log to MySQL)

iptables

I have patched the kernel using the Patch-O-Matic from the netfilter source (Downloaded from their CVS). All I added was the quota match.

My kernel is configured with iptables support, and every option in the netfilter configuration set up as a Module.

Then, I just set up my firewall chains, and make sure to include a logging option, and a quota matching option.

Now I'm able to both limit usage of the network by my users, and log all usage so that I can generate meaningful graphs of network usage based on any number of criteria.

I am currently working on getting the CVS version of ulogd, since it has command-line support for custom config files. The current portage version does not.

----------

## Utoxin

Here's an example of the bandwidth usage charts I'm creating using the log data from iptables+ulogd+mysql:

http://www.kydance.net/admin/bandwidth-usage.php

----------

## meyerm

Reeeally nice.  :Smile: 

Now I know what I will play with the next time I'm at work.  :Wink: 

----------

## pjp

 *meyerm wrote:*   

> Now I know what I will play with the next time I'm at work. 

 But what does that have to do with Network Quota stuff?

[/badjoke]

----------

## Utoxin

 *kanuslupus wrote:*   

>  *meyerm wrote:*   Now I know what I will play with the next time I'm at work.  But what does that have to do with Network Quota stuff?
> 
> [/badjoke]

 

They both use iptables.  :Wink: 

The main thing for the quota is using Patch-O-Matic to add the 'QUOTA' match to the kernel.

For the graphing of usage like I have on that page, the key is ulogd (Which is in Portage, BTW.)

----------

