5 Minutes Guide To Linux Traffic Shaping
6 Apr2006

If you have your own home network with two or more computers, you definitely know all of the problems with concurrent access to internet channel. Most annoying problem is bandwidth sharing: when you are trying to use remote ssh connection to some server, and at the same time your wife/brother/friend decided to watch some new and very cool video clip at Google Video or YouTube, your connection will be stalled and you can forget about comfortable work. In this small article I will give you a simple solution for this problem and you will be able to do anything without worrying about traffic sharing problems!

First of all, you need to be connected to internet via Linux server. If your connection is some dumb hardware router, you can not use described advice.

If your server is Linux-driven, then use following instructions to make your life easier. My internet channel is connected to eth0 and LAN is on the eth1, and my channel is symmetrical 512Kbit/s cable connection, so all examples are based on this facts:

  1. Download htb.init script from sourceforge.
  2. Extract it, place htb.init file to /sbin/htb.init and change its permissions to make it executable:

    # chmod +x /sbin/htb.init
    

  3. Create htb.init configuration and cache directories:

    # mkdir -p /etc/sysconfig/htb
    # mkdir -p /var/cache/htb.init
    

  4. Go to htb.init configuration directory and create following configuration files for outgoing traffic:
    • File ‘eth0′ with following content:

      DEFAULT=30
      R2Q=100
      

    • File ‘eth0-2.root’ with following content:

      # root class containing outgoing bandwidth
      RATE=512Kbit
      

    • File ‘eth0-2:10.ssh’ with following content:

      # class for outgoing ssh
      RATE=256Kbit
      CEIL=512Kbit
      LEAF=sfq
      RULE=*:22
      PRIO=10
      

    • File ‘eth0-2:30.default’ with following content:

      # default class for outgoing traffic
      RATE=256Kbit
      CEIL=512Kbit
      LEAF=sfq
      PRIO=30
      

  5. Next, create following configuration files for incoming traffic:
    • File ‘eth1′ with following content:

      DEFAULT=30
      R2Q=100
      

    • File ‘eth1-2.root’ with following content:

      # root class containing incoming bandwidth
      RATE=512Kbit
      

    • File ‘eth1-2:10.ssh’ with following content:

      # class for incoming ssh
      RATE=256Kbit
      CEIL=512Kbit
      LEAF=sfq
      RULE=*:22,
      PRIO=10
      

    • File ‘eth1-2:20.mytraf’ for your home computer IP with following content:

      # class for my incoming traffic
      RATE=256Kbit
      CEIL=512Kbit
      LEAF=sfq
      RULE=192.168.0.2 # this is my ip
      PRIO=20
      

    • File ‘eth1-2:30.default’ with following content:

      # default class for outgoing traffic
      RATE=256Kbit
      CEIL=512Kbit
      LEAF=sfq
      PRIO=30
      

  6. And last your step will be compile and run traffic control rules:

    # /sbin/htb.init start
    #
    

If all described steps was successfully completed, you can use your connection to connect to any ssh host or to download files or to browse your favorite sites… Your connection will be divided between you and all other home network members. If you are alone in network now, you can use full bandwidth, if your neighbours will try to download something, bandwidth will be divided between you and them, but you connections will be as fast as when you were alone.

If you want to know more, you can use following resources: