Go to root and follow:
making directory:
1.# mkdir /usr/src/niceshaper
2.# cd /usr/src/niceshaper
geting archives:
3.# wget http://niceshaper.jedwabny.net/files/niceshaper{version}.tar.bz2
4.# bunzip2 niceshaper{version}.tar.bz2
5.# tar xf niceshaper{version}.tar.bz2
compile and install binary in /usr/local/bin by install.sh script:
6.# chmod u+x install.sh
7.# ./install.sh
If you haven't config dir yet:
9.# cp -R etc/niceshaper0.6 /etc
if yes, you need to be sure that there are no notation different between old and new version.
- NiceShaper has 2 important files: /etc/niceshaper0.6/config oraz /etc/niceshaper0.6/class.
- include file /full/path attached next ones
.
- configure uses "directives" and one or list of "values". eg:
rate 128kb/s
debug iptables iproute
- there can be situation that we have "dyrectives" with many "parameters". eg:
stats unit kB/s file
/var/www/stats/nsstats.txt
- each above situation can be write in two way, if parameters and values belongs to one directives they can be group or split to one/many lines.
- but beware! you can't split iface and class one, and each line must start with directive. eg.:
stats unit kB/s
stats file /var/www/stats/nsstats.txt
debug iptables
debug iproute
- proper bandwidth units are bit, bps, b/s, B, Bps and B/s where you can add 'k|m' if needed. default is b/s.
- '#' char is using for comment rest of line.
- ';' char is end of line equivalent, it give you way to minimalize length of config files.
- remember, all examples are only examples and can be not optimal for you.
- main configuration file /etc/niceshaper0.6/config file, is divided on sections,
one called global, and free number of sections for shape on appointed interfaces.
- for each section ( except global one ) there will be one process in system which will control attached classes.
<global>
run download upload
support mark-on eth0
stats unit kB/s
stats file /var/www/stats/nsstats.txt
stats owner root group root mode 644
</global>
<download>
iface eth1 match dstip 192.168.0.0/24
iface eth2 match dstip 192.168.1.0/24
section speed 512kB/s
section shape 450kB/s
default low 10kB/s
default ceil 100kB/s
default htb-prio 5
default htb-scheduler sfq
default hold 30s
iptables-hook POSTROUTING
reload 3s
</download>
global section directives:
run - list of configured sections you want to run.
support - additional funcjonalitis.
mark-on - list of interfaces on which run fw filter in place of u32.
packets outs by this interfaces will be marked by iptables mark destination.
it's needed for control upload within network using private IP addresses and NATs outgoing packets, or to use advanced filters.
stats - statistics.
unit - bandwidth units for stats.
file - automatic dump statistics to appointed file ( none for off ).
owner - set system owner for stats file ( default is root ).
group - set system group for stats file ( default is root ).
mode - set chmod for stats file ( default is 644 ).
lang - messages language {en|pl}.
your section directives:
iface interface match filter
- define work space for section, it's natural to place here your local network.
- define on which interface use HTB for this one, keep in mind that HTB can manage only outgoing packets on interface,
so be sure you define here interface which packets going out not arrive.
- you can use niceshaper filters notation or for this case simple:
iface eth1 dst network 192.168.0.0/24
and for manage upload:
iface eth0 src network 192.168.0.0/24
- iptables and iproute don't know interface aliases so put here only real interface part and it will work good.
- vlans uses notation like in linux OS - ethX.vid.
- for example:
eth1 - real eth1 interface or equivalent of eg. eth1:1, eth1:10 and so on aliases.
eth1.100 - on real interface eth1 vlan with vid 100.
section - parameters of section (in most cases bandwidth of your internet access).
speed - bandwidth of your internet access.
shape - value smaller about 10-20% than speed of your link.
- if it is too high you will see lags for interactive services.
- NiceShaper will reduce your users rates when summary load is higher than this value.
default - default parameters for each defined classes. all classes can override this default settings.
reload - how frequency renew HTB configuration.
4s is default, save and good working on each not so old machine.
smaller values can give better working but make bigger load of processor.
this parameter must be between 0.1s to 600s with step not smaller than 0.1s.
mode - if you don't know iptables, you don't need to know, that this section will use:
download - POSTROUTING chain
upload - PREROUTING chain
remember this is only simple name alias for:
iptables-hook - the same like mode but better to understand what will happend.
iptables-hook-insert - section main filters will be inserted into given chain.
iptables-hook-append - section main filters will be appended to given chain. ( this is identical like iptables-hook do ).
debug - echoes system commands before execute it.
iptables - echoes anything before send to iptables.
iproute - echoes anything before send to tc ( HTB ).
do-not-shape - this class give tool to not shape localhost traffic e.g. localhost file server.
still this class will compute rate and show in stats.
virtual - like before but on top of that packets match this class will be only compute for stats,
and continue working with next classes.
wrapper - next similar but there you can set maximum rate for this class,
it's good if you have slow local network like 2.4ghz WLAN, and do not want to have overload.
class definition
class is starting with header and ending with next class header or end of file.
class section interface classname
section - section to which class will be attached.
interface - interface on which HTB for this class will be working.
classname - name of class for stats.
one simple class:
class download eth1 Mariusz
match dstip 192.168.0.77
or in one line notation ( in future i will use only first way for better looking ):
class download eth1 Mariusz ; match dstip 192.168.0.77
Each class need one parameter which is filter:
match test
- filter define which packets should go to class.
- class can have unlimited number of filters.
class parameters
low - minimal rate ( default 0 ).
ceil - maximal rate ( default is equal section shape ).
rate - static rate ( low = ceil = rate ).
hold - time of no active is needed to remove class from HTB ( default 10 ).
iptables-return - packets for class with this option will be returning to PREROUTING/POSTROUTING chain,
as RETURN destination is set instead of ACCEPT.
htb-prio - priority for htb class, value between 0 - 7 , where 0 is highest ( default is 5 ).
htb-scheduler - qdisc type for HTB class {none|sfq|esfq}.
sfq - sfq scheduler configuration if using.
perturb - set sfq perturb parameter ( default 10 ).
esfq - esfq scheduler configuration if using.
perturb - set esfq perturb parameter ( default 10 ).
hash - esfq hash {classic|src|dst} ( default classic )
There is no need to write this line for each class if their are identical, use default instead, and overwrite selected if needed.
simple filters
proto - protocol ( tcp, udp or icmp ), default all.
srcip - source ip address or network.
dstip - destination ip address or network.
srcport|sport - source port ( it needs proto too ).
dstport|dport - destination port ( it needs proto too ).
from localhost - it's need to proper work filters points packets going from localhost.
to localhost - it's need to proper work filters points packets going to localhost.
srcip and dstip can point one ip address or network with mask.
mask can be not continuous ( eg. 255.255.128.255 ) but in this case use packet marking.
for example:
all packets going to 192.168.0.77:
match srcip 192.168.0.77
pop3 from interia.pl going to network 192.168.0.0/29:
match srcip 217.74.65.69 srcport 110 dstip 192.168.0.0/29 proto tcp
filters working only with packets marking on interface
Iptables netfilter can use many more matching criteria with their modules, but U32 filter can't.
Here are filters you can use but need support mark-on for proper work.
state - state of packet {new|established|related|invalid|untracked }.
tos - Type of Service field in the IP header.
ttl - time to live field in the IP header.
ttl-lower - TTL less than the given value.
ttl-greater - TTL greater than the given value.
mark - packets with given mark value.
example config file with imq:
<download>
iface eth1 match dstip 192.168.0.0/24
iface eth2 match dstip 192.168.1.0/24
iface imq5 match dstip 10.10.5.0/24
default imq-redirect
...
</download>
and class:
class download imq5 ip5_55
match dstip 10.10.5.55