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 *

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF