Bobcares

Limit cPanel bandwidth using mod_cband

by | Mar 9, 2021

Wondering how to Limit cPanel bandwidth using mod_cband? We can help you.

At times some websites may consume huge bandwidth. For servers using Apache2, we can use the mod_cband module to limit data transfer for a website.

mod_cband helps us to set user’s and VirtualHost’s bandwidth quota and limit requests per second speed.

It can also set maximal download speed and the maximum number of simultaneous IP connections.

Here at Bobcares, we often fix bandwidth issues as a part of our Server Management Services.

Today let’s see how our Support Engineers fix them for our customers.

Steps to limit cPanel bandwidth using mod_cband

To configure the mod_cband module on CentOS/RedHat/Fedora we need apxs installed first.

We can do this with the following command:

yum install httpd-devel

Also, we need to have executable permission for the directory in which we wish to install mod_cband.

The option “CBandExceededSpeed”, in the mod_cband module allows us to bring down the speed and the maximum number of connections per second.

We can also keep a track of all the connections by creating a scoreboard (database) i.e “/home/user/domains/website.com/public_html/scoreboard“.

It has also got an option for splitting up the bandwidth usage per week.

We can add the following codes in the VirtualHost directory section.

CBandLimit 6G
CBandPeriod 4W
CBandPeriodSlice 1W
CBandSpeed 500kbps 10 30

It means that 6GB is split up in 4-week slices, so we can get 1.5GB of bandwidth per week. And the maximum speed is 500kbps, with 10 requests/second and a max of 30 connections.

Next, we can download and install mod_cband  using the following commands:

# cd /tmp
# wget http://pkgs.fedoraproject.org/repo/pkgs/mod_cband/mod-cband-0.9.7.4.tgz/ff635d7b55bf7ca648d319247dfb45e3/mod-cband-0.9.7.4.tgz
# tar xzvf mod-cband-0.9.7.4.tgz
# cd mod-cband-0.9.7.4
# ./configure
# make
# make install
# vi /etc/httpd/conf/httpd.conf

Check if we can find a line like the one given below:

LoadModule cband_module /usr/lib64/httpd/modules/mod_cband.so

(If this line is not present, add it manually)

Finally restart Apache:

# /etc/init.d/httpd restart

Common installation error

One of the common error looks like the one given below:

Error: apxs:Error: Command failed with rc=65536

Sometimes, we will get this error while executing make.

apxs -Wc,-Wall -Wc,-DDST_CLASS=3 -c src/mod_cband.c
/usr/local/apr/build-1/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache/include -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-1 -Wall -DDST_CLASS=3 -c -o src/mod_cband.lo src/mod_cband.c && touch src/mod_cband.slo
src/mod_cband.c: In function 'mod_cband_create_traffic_size':
src/mod_cband.c:1046: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c:1046: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c:1050: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c:1050: warning: comparison with string literal results in unspecified behavior
src/mod_cband.c: In function 'mod_cband_get_dst':
src/mod_cband.c:1325: error: 'conn_rec' has no member named 'remote_ip'
src/mod_cband.c: In function 'mod_cband_get_remote_host':
src/mod_cband.c:1354: error: 'struct conn_rec' has no member named 'remote_ip'
src/mod_cband.c:1355: error: 'struct conn_rec' has no member named 'remote_ip'
src/mod_cband.c:1357: error: 'struct conn_rec' has no member named 'remote_addr'
apxs:Error: Command failed with rc=65536
.
make: *** [src/.libs/mod_cband.so] Error 1

On Source Directory

# ls
AUTHORS conf config.status doc libpatricia.copyright Makefile src
Changes config.log configure INSTALL LICENSE Makefile.in

Open mod_cband.c file under src folder.

# vim mod_cband.c

1. First we must change the variable name “remote_ip” to “client_ip”
2. After search and change the given below line.

else
addr = c->remote_addr->sa.sin.sin_addr.s_addr;
to
else
addr = c->client_addr->sa.sin.sin_addr.s_addr;

Save and exit the file.

Now try to compile the program from the mod_cband root directory.

# make
# make install

We must keep in mind that even though mod_cband is a useful module to throttle bandwidth usage, it can sometimes turn weird if the website that we are trying to throttle has got MP3 downloads.

 [Still facing issue? – We can help you]

Conclusion

To conclude, we saw how our Support Techs limit cPanel bandwidth using mod_cband.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.