4

I have an Ubuntu 10 box that I'm trying to set up as a bandwidth-shaping router.

The machine has one WAN interface, eth0 and two LAN interfaces, eth1 and eth2. NAT is configured using MASQUERADE as described at InternetConnectionSharing.

I'm mostly concerned with shaping outbound traffic from the LAN interfaces -- in the end, I'd like to end up with a hard 768Kbps limit per-LAN-interface (rather than a limit on eth0 pooled across all interfaces).

I installed HTB.init, and riffing on the examples, tried to set this up on eth1 by putting three files into /etc/sysconfig/htb:

/etc/sysconfig/htb/eth1

DEFAULT=30
R2Q=100

/etc/sysconfig/htb/eth1-2.root

RATE=768Kbps
BURST=15k

/etc/sysconfig/htb/eth1-2:30.dfl

RATE=768Kbps
CEIL=788Kbps
BURST=15k
LEAF=sfq

I can /etc/init.d/htb start and /etc/init.d/htb stats and see information that /seems/ to suggest it's working...but when I try pulling a large file via the WAN interface the shaping clearly isn't in effect.

Any suggestions? My guess is it has something to do with where the shaping falls in the NAT chain, but I really have no idea where to begin troubleshooting this.

---- Update:

Here's my /etc/init.d/htb list output, it seems to make sense -- the default rate for eth1 is 768Kbps?

### eth0: queueing disciplines

qdisc htb 1: root refcnt 2 r2q 100 default 30 direct_packets_stat 0
qdisc sfq 30: parent 1:30 limit 127p quantum 1514b perturb 10sec 

### eth0: traffic classes

class htb 1:2 root rate 768000bit ceil 768000bit burst 1599b cburst 1599b 
class htb 1:30 parent 1:2 leaf 30: prio 0 rate 6144Kbit ceil 6144Kbit burst 15Kb cburst 1598b 

### eth0: filtering rules

filter parent 1: protocol ip pref 100 u32 
filter parent 1: protocol ip pref 100 u32 fh 800: ht divisor 1 
filter parent 1: protocol ip pref 100 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:30 
  match 00000000/00000000 at 12
  match 00000000/00000000 at 16

### eth1: queueing disciplines

qdisc htb 1: root refcnt 2 r2q 100 default 30 direct_packets_stat 0
qdisc sfq 30: parent 1:30 limit 127p quantum 1514b perturb 10sec 

### eth1: traffic classes

class htb 1:2 root rate 768000bit ceil 768000bit burst 1599b cburst 1599b 
class htb 1:30 parent 1:2 leaf 30: prio 0 rate 6144Kbit ceil 6144Kbit burst 15Kb cburst 1598b 
Ben K.
  • 2,149
  • 4
  • 17
  • 15

2 Answers2

0

Try adding this (using your IP) to eth1-2:30.dfl

RULE=192.168.0.0/24
w00t
  • 1,134
  • 3
  • 16
  • 35
  • No luck, still the same result. Let me post my htb config, maybe that will give some clues? – Ben K. Jan 28 '11 at 17:03
0

I have to say, I found this really difficult to figure out with speeds exceeding 100Mbit. In my case I wanted to shape to 2Gbit/s

In the end I adapted a script I found that work. Here it is, adapt it to your needs. Specifically you'll need to adjust rate to something valid. tc understands mbit. So you'll need to put in something like 768kbit or something it can correctly interpret.

#!/bin/sh
#
# Incoming traffic control
#
DEV=eth0
RATE="2000mbit"

tc qdisc del dev $DEV root
tc qdisc add dev $DEV root handle 1: htb default 10
tc class add dev $DEV parent 1: classid 1:1 htb rate ${RATE} burst 15k
tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${RATE} ceil ${RATE} burst 15k
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10

echo;echo "tc configuration for $DEV:"
tc qdisc show dev $DEV
tc class show dev $DEV

#
# Outgoing traffic control
#
DEV=eth2
tc qdisc del dev $DEV root
tc qdisc add dev $DEV root handle 1: htb default 10
tc class add dev $DEV parent 1: classid 1:1 htb rate ${RATE} burst 15k
tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${RATE} ceil ${RATE} burst 15k
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10

echo;echo "tc configuration for $DEV:"
tc qdisc show dev $DEV
tc class show dev $DEV
hookenz
  • 14,132
  • 22
  • 86
  • 142