# Divide Bandwith



## serjaomendes (Jan 4, 2010)

Hi,

I'm brazilian, sorry for my english.

I have two LAN and need divide the bandwith.

LAN 2 need have at most 50%, and more the percentual not used by LAN1.

LAN 1 have no limits.

Somebody recommend some program to make this ?


----------



## phospher (Jan 4, 2010)

What is the reasoning behind dividing the bandwidth? Are you trying to throttle certain types of traffic? Have you looked at Quality of Service or web proxies?


----------



## serjaomendes (Jan 4, 2010)

My Internet is divided for 2 peoples.

No need divided by specifics type, only the full bandwith.


----------



## phospher (Jan 4, 2010)

I would set static IP's then use traffic shaping/QoS on a router. I use FreeBSD for my firewalls and servers but I use vyatta for my routers which is capable of doing what you want (rate limiting). What are you using for your router?


----------



## mix_room (Jan 5, 2010)

PF does queueing.
Documentation here : http://www.openbsd.org/faq/pf/queueing.html


----------



## dennylin93 (Jan 5, 2010)

I'd suggest using PF and ALTQ for bandwidth control. Set the limit for one of the interfaces to 50%, with the "borrow" option.

The man pages are also a good place to start:

pf.conf()
pfctl()


----------



## serjaomendes (Jan 5, 2010)

```
ext_if="sis0"
lenke="rl0"
wmw="rl1"

####CONTROLE DE TRAFEGO PARA A INTERFACE ext_if
#altq on $ext_if cbq bandwidth 1Mb qlimit 150 \
#	queue {lenke,wmw,http}
#	queue lenke bandwidth 50% priority 3 qlimit 150 cbq(default red)
#    #queue http bandwidth 20% priority 2 cbq (borrow)
#  	queue wmw bandwidth 50% priority 1 qlimit 150 cbq(red)
#  
#nat on sis0 from rl0:network to any -> sis0       # 189.16.21.140

altq on $ext_if bandwidth 1000Kb hfsc queue { lenke, wmw }
   queue lenke bandwidth  50% priority 3 qlimit 500 hfsc (default)
   queue wmw bandwidth 50% priority 2 qlimit 500 hfsc #(realtime 40%)


####FILTRAGEM
#pass in quick on rl1 from 189.16.21.160 to any tag WMW queue wmw
pass in quick on rl1 to any tag WMW queue wmw
pass out quick on sis0 tagged WMW queue wmw
#pass in quick on sis0 from any to 189.16.21.160 tag WMW queue wmw
pass in quick on sis0 from any tag WMW queue wmw
pass out quick on rl1 tagged WMW queue wmw

pass in quick on rl0 from 189.16.21.130 to any tag LENKE queue lenke
pass out quick on sis0 tagged LENKE queue lenke
pass in quick on sis0 from any to 189.16.21.130 tag LENKE queue lenke
pass out quick on rl0 tagged LENKE queue lenke
#pass out quick on $lenke inet proto tcp from  port 80 to $ext_if keep state queue (http)
```

is ok ?
how to test this ?


----------



## DutchDaemon (Jan 5, 2010)

`# pfctl -sq -vv`
sysutils/pftop (pftop, option 8)


----------



## serjaomendes (Jan 5, 2010)

Thanks for all.


```
queue  lenke on sis0 bandwidth 500Kb priority 3 qlimit 500 hfsc( default )
  [ pkts:        289  bytes:      54037  dropped pkts:      0 bytes:      0 ]
  [ qlength:   0/500 ]
  [ measured:     8.0 packets/s, 12.16Kb/s ]
queue  wmw on sis0 bandwidth 500Kb qlimit 500
  [ pkts:       2514  bytes:     219266  dropped pkts:      0 bytes:      0 ]
  [ qlength:   0/500 ]
  [ measured:    67.5 packets/s, 46.86Kb/s ]
```

What signific this statistics ?


----------



## DutchDaemon (Jan 5, 2010)

Seems rather self-explanatory ... what don't you understand about it?


----------



## serjaomendes (Jan 5, 2010)

sorry, 

in this case, the speed of interfacew wmw is faster then interface lenke ?

I need lenke have always all bandwith not used and at least 50%
wmw interface at most 50%


----------



## DutchDaemon (Jan 5, 2010)

The statistics only indicate how the queues are being used. The 'pkts' and the 'bytes' counters show how much traffic has been handled by the queues, and the 'packets/s' and 'Kb/s' counters show how much traffic is passing these queues right now. Since both queues are nowhere near full, this will not 'prove' that they will both share the 1Mbit/sec link. If you keep [cmd=]pfctl -sq -vv[/cmd] running for some time, you will see the first two counters rise, and the last two counters will show the current bandwidth usage. When there's a lot of traffic, you should see neither of these queues rise over 500 Kbit/sec. When a queue is full, you will see packets being dropped once there are more than 500 packets waiting to be processed.


----------



## serjaomendes (Jan 5, 2010)

Ok, with TCPDUMP or PF have any way to see the bandwith total used by interface ?


----------



## DutchDaemon (Jan 5, 2010)

[cmd=]netstat -I sis0 1[/cmd] gives you bandwidth comsumption every second. Replace sis0 with rl0 or rl1 for the other interfaces.


----------



## serjaomendes (Jan 5, 2010)

Im comparing traffic in rl0 rl1 and sis0
and the sum of values not equal sis0...

is another way, or tool to easy compare traffic ?


----------



## DutchDaemon (Jan 5, 2010)

sysutils/pfstat is quite useful for all kinds of statistics and graphs, but it is a bit finicky to set up. Another one is net/ntop, but the level of detail it provides is likely overkill.


----------



## serjaomendes (Jan 5, 2010)

Thanks a lot again.

I Haved install cacti, butt show this message when i try to access:

FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php' 

the file include/config.php not exists :S


----------



## DutchDaemon (Jan 5, 2010)

That's an entirely different matter and certainly not on-topic


----------



## serjaomendes (Jan 5, 2010)

ok, thanks again.


----------

