OpenVZ Forum


Home » General » HowTo » Traffic Limiting
Traffic Limiting [message #1671] Sun, 19 February 2006 12:54 Go to next message
atomic is currently offline  atomic
Messages: 8
Registered: January 2006
Junior Member
Hi,

i like to introduce a small and dirty script to limit the traffic amount for a vps. Besides iptables, the ipt_quota module is needed, its not included in the official ovz kernel, so you have to build you own from vanilla sources and patch it with the ovz enhancements.

Linux 2.6.8: http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.8.tar. bz2
OVZ Patches: http://download.openvz.org/kernel/022stab064.1/patches/patch -022stab064-combined.gz

(Actual version on http://openvz.org/download/kernel/)

Download, extract and patch the Kernel source (2.6.8) with the combined ovz patch, then copy a ovz configfile for the desired system to /usr/src/linux/.config. Now, you'll need the ipt_quota module which is shipped with the netfilter patch-o-matic.

Note: ipt_quota is available for uniprocessor systems without SMP support only at the moment.

Grab patch-o-matic here: ftp://ftp.netfilter.org/pub/patch-o-matic-ng/
Grab netfilter sources here: ftp://ftp.netfilter.org/pub/iptables/

Extract patch-o-matic and the iptables sources. Now execute "runme" + Module in the patch-o-matic source directory. You will be asked for the kernel and iptables source directory.

./runme quota
Hey! KERNEL_DIR is not set.
Where is your kernel source directory? [/usr/src/linux]
Hey! IPTABLES_DIR is not set.
Where is your iptables source code directory? [/usr/src/iptables]


After patching the ipt_quota module, customize and compile your kernel with the module "ipt_quota".

Via .config file directly:

CONFIG_IP_NF_MATCH_QUOTA=m


Via menuconfig:

Device Drivers  --->
  Networking support  --->
    Networking options  --->
      Network packet filtering (replaces ipchains)  ---> 
        IP: Netfilter Configuration  ---> 
           <M> quota match support


Note: I had some serious problems compiling the 2.6.8 Kernel with a actual version of gcc/cpp but it worked fine with gcc-Version 3.3.2 20031022. Thats the gcc version shipped with fc1, the ovz rpm kernels are build against that gcc version too.

You get this specific version of gcc and cpp here:
http://mirrors.kernel.org/fedora/core/1/i386/os/Fedora/RPMS/ gcc-3.3.2-1.i386.rpm
http://mirrors.kernel.org/fedora/core/1/i386/os/Fedora/RPMS/ cpp-3.3.2-1.i386.rpm

Compile, install and boot the patched kernel.

When the new kernel is loaded you should be able to modprobe ipt_quota to load the module (if it has not been loaded automaticly).
Check with lsmod:

ip_tables   20624  11   ipt_quota,ipt_length,ipt_ttl,ipt_tcpmss,ipt_TCPMSS,iptable_mangle [...]


Now you are able to set network traffic quotas for each ip adress on your system (a vps may have more than one ip adress).

I use this crapy piece of iptables configuration to limit the traffic:

iptables -N vn1-virtual01
iptables -A vn1-virtual01 -m quota --quota 107374182400 -j ACCEPT
iptables -A vn1-virtual01 -d vps.ipa.ddr.ess -j REJECT --reject-with host-prohib
iptables -A vn1-virtual01 -s vps.ipa.ddr.ess -j REJECT --reject-with host-prohib

iptables -A INPUT -d vps.ipa.ddr.ess -j vn1-virtual01
iptables -A OUTPUT -s vps.ipa.ddr.ess -j vn1-virtual01
iptables -A FORWARD -s vps.ipa.ddr.ess -j vn1-virtual01


Asuming that the VPS "vn1-virtual01" has the IP "vps.ipa.ddr.ess", this script monitors the traffic that is recieved, sent and forwarded by the VPS. The quota is set to 107374182400Bytes which is equivalent to 100GBytes. If the traffic limit is reached, all connections to/from the VPS will be terminated and rejected with the ICMP message "Host prohibited".

I'm looking forward to your comments and suggestions for improvement.

martin

[Updated on: Sun, 19 February 2006 13:02]

Report message to a moderator

Re: Traffic Limiting [message #2035 is a reply to message #1671] Wed, 15 March 2006 23:26 Go to previous messageGo to next message
RapidVPS is currently offline  RapidVPS
Messages: 32
Registered: January 2006
Member
Seems like a good job. Could we get something like this added to vzctl and vz-scripts/veid.conf? This is highly useful.



Re: Traffic Limiting [message #2541 is a reply to message #1671] Sun, 09 April 2006 10:02 Go to previous messageGo to next message
Julian is currently offline  Julian
Messages: 4
Registered: April 2006
Location: Darmstadt, Germany
Junior Member

Hi,

a very interesting approach.

But as the patch says: "KNOWN BUGS: this does not work on SMP systems.", it's not going to work for me Sad

Best regards,

Julian Haupt

[Updated on: Sun, 09 April 2006 10:05]

Report message to a moderator

Re: Traffic Limiting [message #2555 is a reply to message #2541] Mon, 10 April 2006 06:34 Go to previous messageGo to next message
dev is currently offline  dev
Messages: 1693
Registered: September 2005
Location: Moscow
Senior Member

Julian, I suppose this module can be fixed quite easily to work on SMP. I see no obstacles for this.

Also, you can create a simple patch for venet to limit traffic.
in venet_xmit() we have a flag ve->disable_net() being checked. You simply need to set it to 1, when VPS overusedd its limit.


http://static.openvz.org/userbars/openvz-developer.png
Re: Traffic Limiting [message #29565 is a reply to message #1671] Thu, 17 April 2008 07:49 Go to previous message
SoftDux is currently offline  SoftDux
Messages: 55
Registered: November 2007
Location: Johannesburg, South Afric...
Member
I'm not to fond of patching / hacking kernels on productions servers. So, my question is, how well have you tested this approach in a CentOS 5.1 system? I use yum update to update the PAE kernel (8GB RAM on a i386 machine), which works well.

Will this patch need to be applied everytime I update the kernel?
Previous Topic: Howto setup Asterisk within a VE for recording a podcast over the Internet
Next Topic: Script to install yum on CentOS VE
Goto Forum:
  


Current Time: Sat Apr 27 17:16:55 GMT 2024

Total time taken to generate the page: 0.02443 seconds