Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: [SOLVED] Limiting upload speed for non-local connections

  1. #11
    Join Date
    Jun 2007
    Location
    Melbourne, AU
    Beans
    211
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Limiting upload speed for non-local connections

    Just to help simplify this...

    Firstly, remove the third tc filter, this is wrong, you shouldnt need to specify you public IP address anywhere.

    next, if you want to limit you UPLOAD speed then you shouldnt be specifying the "ip src .... " you should be specifying the "ip dest .... " because on outbound connections the src will be 192.168.2.100 (i.e, your server) no matter what.

    so it looks a bit more like this
    Code:
    tc qdisc add dev eth0 root handle 1: htb default 12
    tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
    tc class add dev eth0 parent 1:1 classid 1:10 htb rate 500kbit ceil 500kbit
    tc class add dev eth0 parent 1:1 classid 1:12 htb rate 50mbit ceil 100mbit
    tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 0.0.0.0/0  flowid 1:10
    tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst  192.168.2.0/24 flowid 1:12
    tc qdisc add dev eth0 parent 1:10 handle 20: sfq perturb 10
    tc qdisc add dev eth0 parent 1:12 handle 30: sfq perturb 10
    Then, run some tests from inside and outside your LAN, see how that helps. if it doesnt, post your config back, and maybe ill finally have a look at the tc man page. The tc man page seems a lot more interesting than this mock exam im doing atm thats for sure!! lol
    Ubuntu 8.04 Hardy Heron User

  2. #12
    Join Date
    Jun 2008
    Beans
    13

    Re: Limiting upload speed for non-local connections

    Thanks a lot fwre01,

    I'll have a look at this first thing in the morning. Looks like you have a point there.

    Good night (for me at least),
    spr

  3. #13
    Join Date
    Aug 2008
    Location
    Washington DC
    Beans
    2,186
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Limiting upload speed for non-local connections

    Quote Originally Posted by fwre01 View Post
    Just to help simplify this...

    Firstly, remove the third tc filter, this is wrong, you shouldnt need to specify you public IP address anywhere.

    next, if you want to limit you UPLOAD speed then you shouldnt be specifying the "ip src .... " you should be specifying the "ip dest .... " because on outbound connections the src will be 192.168.2.100 (i.e, your server) no matter what.

    so it looks a bit more like this
    Code:
    tc qdisc add dev eth0 root handle 1: htb default 12
    tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
    tc class add dev eth0 parent 1:1 classid 1:10 htb rate 500kbit ceil 500kbit
    tc class add dev eth0 parent 1:1 classid 1:12 htb rate 50mbit ceil 100mbit
    tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 0.0.0.0/0  flowid 1:10
    tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst  192.168.2.0/24 flowid 1:12
    tc qdisc add dev eth0 parent 1:10 handle 20: sfq perturb 10
    tc qdisc add dev eth0 parent 1:12 handle 30: sfq perturb 10
    Then, run some tests from inside and outside your LAN, see how that helps. if it doesnt, post your config back, and maybe ill finally have a look at the tc man page. The tc man page seems a lot more interesting than this mock exam im doing atm thats for sure!! lol
    I just woke up.. Thanks fwre01 I did mix up src and dst. I really didn't expect it work out of the box -- I spend few days a couple of months ago with head in tc.

    The third queue should remain its the default queue.

    delete the queues:
    Code:
    tc qdisc del dev eth0 root
    print your queues:
    Code:
    tc filter show dev eth0
    To see what is going with the queues:
    Code:
    tc -s -d qdisc show dev eth0
    tc -s -d class show dev eth0
    Last edited by iponeverything; October 14th, 2008 at 12:40 PM.

  4. #14
    Join Date
    Aug 2008
    Location
    Washington DC
    Beans
    2,186
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Limiting upload speed for non-local connections

    Firstly, remove the third tc filter, this is wrong, you shouldnt need to specify you public IP address anywhere.
    The third rule is optional -- not "wrong" -- It is quite handy for watching packet flow rates.

  5. #15
    Join Date
    Jun 2008
    Beans
    13

    Re: Limiting upload speed for non-local connections

    Alright! I got it working. I'm sorry to say that the script won't work without the filter with my public IP.
    Thanks to iponeverything and fwre01!

    Oh, and don't look at the comments and echoes, just makes it look like it's doing something.

    Code:
    #!/bin/sh
    # Traffic shaping script
    # ---------------------------------------------------------------------
    # Limits upload speed to the outside world to 560kbit/s, leaving speeds
    # within the LAN unaffected
    # Only include the filter with the public IP if you access the machine
    # through the LAN with its public IP
    # ---------------------------------------------------------------------
    # Thanks to iponeverything and fwre01
    # ---------------------------------------------------------------------
    
    # Starting with a clean slate
    echo Removing any previously set rules...
            sudo tc qdisc del root dev eth0
    
    echo Setting root qdisc...
            sudo tc qdisc add dev eth0 root handle 1: htb default 12
    
    echo Setting bandwidth classes...
            sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
            sudo tc class add dev eth0 parent 1:1 classid 1:10 htb rate 560kbit ceil 560kbit
            sudo tc class add dev eth0 parent 1:1 classid 1:12 htb rate 50mbit ceil 100mbit
    
    # Only include the filter with the public IP if you access the machine through the LAN with its public IP
    echo Creating filters...
            sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst YOUR.PUBLIC.IP.HERE/24 flowid 1:12
            sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.2.0/24 flowid 1:12
            sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 0.0.0.0/0  flowid 1:10
    
    echo Finishing...
            sudo tc qdisc add dev eth0 parent 1:10 handle 20: sfq perturb 10
            sudo tc qdisc add dev eth0 parent 1:12 handle 30: sfq perturb 10

  6. #16
    Join Date
    Jun 2008
    Beans
    13

    Re: [SOLVED] Limiting upload speed for non-local connections

    Oh, and do I call this script only once or at every boot?

  7. #17
    Join Date
    Jun 2007
    Location
    Melbourne, AU
    Beans
    211
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: [SOLVED] Limiting upload speed for non-local connections

    Well done, Im glad you solved it. (and marked it as solved)

    iponeverything, you may be right about the public.ip filter, could you explain how this works? i cant see a situation where the server will ever address packets with a destination of public.ip? the server will never see that address anywhere. also, why does it has a /24 mask? (that may just be a typo)
    Ubuntu 8.04 Hardy Heron User

  8. #18
    Join Date
    Aug 2008
    Location
    Washington DC
    Beans
    2,186
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: Limiting upload speed for non-local connections

    This is the basics as I understand it -- My main block in trying to learn this was thinking in pools and queues rather than streams.

    Code:
                          _____ 1:10
                         /
                1: -----1:1
                         \_____
                                1:12
    Create the root:
    Code:
    tc qdisc add dev eth0 root handle 1: htb default 12
    Define the Queues --
    First the pool:
    Code:
    tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
    Then the Queues:
    Code:
    tc class add dev eth0 parent 1:1 classid 1:10 htb rate 560kbit ceil 560kbit
    tc class add dev eth0 parent 1:1 classid 1:12 htb rate 50mbit ceil 100mbit
    Put the packets into the correct Queue:
    Code:
    tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.2.0/24 flowid 1:12
    tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 0.0.0.0/0  flowid 1:10

    Define my Queue algorithms:
    Code:
    tc qdisc add dev eth0 parent 1:10 handle 20: sfq perturb 10
    tc qdisc add dev eth0 parent 1:12 handle 30: sfq perturb 10
    Last edited by iponeverything; October 14th, 2008 at 11:40 AM.

  9. #19
    Join Date
    Aug 2008
    Location
    Washington DC
    Beans
    2,186
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: [SOLVED] Limiting upload speed for non-local connections

    Quote Originally Posted by spr- View Post
    Oh, and do I call this script only once or at every boot?
    Yes call it once at boot time is all that you need.

    I would just call it from /etc/rc.local -- but there are a lot of folks out there that will give there scripts more regal places to be invoked from.

    Don't quite understand the thinking, it seems to imply *NIX politically correctness.. and any one that spent some time on some of the commercial flavors will realize that there is no such thing

    BTW -- If you are calling it from rc.local, you will not need the "sudo"'s -- it will be ran as root.
    Last edited by iponeverything; October 14th, 2008 at 11:59 AM.

  10. #20
    Join Date
    Jul 2009
    Beans
    571
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: [SOLVED] Limiting upload speed for non-local connections

    Obviously this only works if you DO NOT have a Squid Server, File Server, Web Server, and other apps in your server, right?
    It's OK, everything we know will become obsolete at some time.

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •