Well, I've already gone through How can I do traffic shaping in Linux by IP?
on serverfault
& what I'm trying to achieve is pretty much same.
Internet--------Linux Router----Switch-----Clients
I've followed Julien Vehent's tutorial and could restrict the traffic originating from Linux router
to client IP
at 36.7KB/s
but the whenever I'm copying any file from client
to server
I'm getting 6.0MB/s
What I'm trying to achieve is
Internet------------------------>Client @ 1.0MB/s
i.e if I download any file from Internet
to client machine
it
will be @1.0MB/s
Below is the script I have followed
#! /bin/bash
NETCARD=eth1
MAXBANDWIDTH=10000
# reinit
tc qdisc del dev $NETCARD root handle 1
tc qdisc add dev $NETCARD root handle 1: htb default 9999
# create the default class
tc class add dev $NETCARD parent 1:0 classid 1:9999 htb rate $(( $MAXBANDWIDTH ))kbit ceil $(( $MAXBANDWIDTH ))kbit burst 5k prio 9999
# control bandwidth per IP
declare -A ipctrl
# define list of IP and bandwidth (in kilo bits per seconds) below
ipctrl[10.239.107.15]="256" ##MY CLIENT MACHINE IP##
#ipctrl[192.168.1.2]="128"
#ipctrl[192.168.1.3]="512"
#ipctrl[192.168.1.4]="32"
mark=0
for ip in "${!ipctrl[@]}"
do
mark=$(( mark + 1 ))
bandwidth=${ipctrl[$ip]}
# traffic shaping rule
tc class add dev $NETCARD parent 1:0 classid 1:$mark htb rate $(( $bandwidth ))kbit ceil $(( $bandwidth ))kbit burst 5k prio $mark
# netfilter packet marking rule
iptables -t mangle -A INPUT -i $NETCARD -s $ip -j CONNMARK --set-mark $mark
iptables -t mangle -A INPUT -i $NETCARD -d $ip -j CONNMARK --set-mark $mark
# filter that bind the two
tc filter add dev $NETCARD parent 1:0 protocol ip prio $mark handle $mark fw flowid 1:$mark
echo "IP $ip is attached to mark $mark and limited to $bandwidth kbps"
done
#propagate netfilter marks on connections
iptables -t mangle -A POSTROUTING -j CONNMARK --restore-mark