Hi to all,
I was having a problem on my network at home, where I have the following setup:
1) My desktop (Slackware 12.1) which is also sort of a file server
2) My wife's desktop (Slackware 12.0) with a large number of documents
3) My notebook from my job (Windows XP, but with Cygwin) with a huge amount of files I cannot afford to lose.
4) My two kids' desktops with some files
I have several scripts running to synchronize directories with rsync so that each important file is saved on at least two computers.
Example: my wife's computers has a script in cron that syncs her files to my desktop (almost always on-line), etc...
The problem: sometimes there is a lot to synchronize and then my network gets clogged and I cannot access anything else (like browsing the internet).
With rsync I could limit the use of bandwith with the --bwlimit option, but then if two computers are syncing at the same time, it still gets clogged.
So I started looking for a better solution, trying to do some "traffic-shaping". The solution was using "cbq", which is included with Slackware. Since it was a bit of a hassle to get it working, I decided to write a little HOW-TO here:
1) Setting up cbq
cbq is a script that is included with iproute2.
We have to copy it to /sbin and make it executable:
Code:
cp /usr/doc/iproute2-2.6.16-060323/examples/cbq.init-v0.7.3 /sbin/cbq
chmod +x /sbin/cbq
cbq expects its configuration files in /etc/sysconfig/cbq
If this directory doesn't exist, create it:
Code:
mkdir /etc/sysconfig/cbq
2) Creating the rules-file
cbq reads files in /etc/sysconfig/cbq with the following names:
cbq-nnnn.yyy where:
- nnnn: is a hexadecimal number from 0002 to ffff
- yyy: is the name of your network interface, like eth0, eth1, etc
In my case, the network interface for my local network is eth1, so I created "
cbq-0002.eth1"
Here is the contents of my file:
Code:
DEVICE=eth1,100Mbit,10Mbit
RATE=5000Kbit
WEIGHT=500Kbit
PRIO=5
RULE=192.168.1.110:873,192.168.1.0/24
BOUNDED=no
ISOLATED=no
Some explanations:
- DEVICE: the interface you want to limit, with its real speed and its weight (1/10 of the max. speed)
- RATE: the bandwith you want to offer for this particular application / port / address
- WEIGHT: 1/10 of the RATE
- PRIO: Priority setting. 5 is default
- RULE: source,destination --> in my case 192.168.1.110 is my desktop, 873 is the port rsync uses
- BOUNDED: Default no, used if you have other filters
- ISOLATED: 'no' means that the rate can be used by other traffic if not in use
3) Starting the bandwith-limiting
Use
cbq compile to prepare the new filters or after you alter your cbq-nnnn.yyy files.
Then use
cbq start to start your traffic-shaping!
To always start cbq, include it in your rc.local script.
You can monitor your results with iptraf
More information can be found using "man tc-cbq".