In my quest to find a way to limit outgoing bandwidth for a running instance of bitcoind, I came across this guide that explains how to rate limit traffic to a particular destination IP:
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit tc class add dev $DEV parent 1: classid 1:1 cbq rate 512kbit allot 1500 prio 5 bounded isolated tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip dst 220.127.116.11 flowid 1:1
I'm not trying to limit traffic to a certain destination IP, though, but to and from a specific port, so I found this guide which tells me how to match traffic by source and destination port:
tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match ip dport 22 0xffff flowid 10:1 tc filter add dev eth0 protocol ip parent 10: prio 1 u32 match ip sport 80 0xffff flowid 10:1
The combination of the first script with the port matching of the second script leads me to the following set of commands that should limit outgoing traffic to port 21 to 160 kbit/s. I'm testing the setup using FTP first, because limiting bitcoind, which uses port 8333, isn't optimal for testing since I can't decide when traffic is sent.
tc qdisc add dev eth0 root handle 1: cbq avpkt 1000 bandwidth 800kbit tc class add dev eth0 parent 1: classid 1:1 cbq rate 160kbit allot 1500 prio 5 bounded isolated tc filter add dev eth0 parent 1: protocol ip prio 16 u32 match ip dport 21 0xffff flowid 1:1
As far as I can see, this should limit outgoing traffic to port 21 on the eth0 interface with an outgoing bandwidth of 800kbit/s to 160kbit/s, but it's not working:
NetHogs version 0.8.0 PID USER PROGRAM DEV SENT RECEIVED 23653 rune filezilla eth0 102.609 2.978 KB/sec
The FTP connection consists of two connections to port 21:
$ netstat -n|grep "21 " tcp 0 0 192.168.1.33:59967 18.104.22.168:21 ESTABLISHED tcp 0 0 192.168.1.33:59974 22.214.171.124:21 ESTABLISHED
What am I doing wrong?
I'm running Ubuntu Raring, in case that's relevant.