4.1. Set traffic control (tcset command)

tcset is a command to add traffic control rule to a network interface (device).

You can delete rule(s) from a network interface by Delete traffic control (tcdel command).

4.1.1. tcset command help

usage: tcset [-h] [--version] [--tc-command | --tc-script] [--debug | --quiet]
             [--stacktrace] (-d DEVICE | -f CONFIG_FILE)
             [--overwrite | --change | --add] [--rate BANDWIDTH_RATE]
             [--delay NETWORK_LATENCY] [--delay-distro LATENCY_DISTRO_TIME]
             [--loss PACKET_LOSS_RATE] [--duplicate PACKET_DUPLICATE_RATE]
             [--corrupt CORRUPTION_RATE] [--reordering REORDERING_RATE]
             [--shaping-algo {htb,htb}] [--iptables]
             [--direction {outgoing,incoming}] [--network DST_NETWORK]
             [--src-network SRC_NETWORK] [--port DST_PORT]
             [--src-port SRC_PORT] [--ipv6]
             [--exclude-dst-network EXCLUDE_DST_NETWORK]
             [--exclude-src-network EXCLUDE_SRC_NETWORK]
             [--exclude-dst-port EXCLUDE_DST_PORT]
             [--exclude-src-port EXCLUDE_SRC_PORT]

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --tc-command          display tc commands to be executed and exit. these
                        commands are not executed.
  --tc-script           generate a script file that described tc commands
                        which equivalent with execution tcconfig command. the
                        script can be execute without tcconfig package
  --debug               for debug print.
  --quiet               suppress execution log messages.
  -d DEVICE, --device DEVICE
                        network device name (e.g. eth0)
  -f CONFIG_FILE, --config-file CONFIG_FILE
                        setting traffic controls from a configuration file.
                        output file of the tcshow.
  --overwrite           overwrite existing traffic shaping rules.
  --change              change existing traffic shaping rules to the new one.
                        this option reduces the shaping rule switching side
                        effect (such as traffic spike) compared to --overwrite
                        option. note: the tcset command fail when there are no
                        existing shaping rules.
  --add                 add a traffic shaping rule in addition to existing

  --stacktrace          print stack trace for debug information. --debug
                        option required to see the debug print.

Traffic Control Parameters:
  --rate BANDWIDTH_RATE, --bandwidth-rate BANDWIDTH_RATE
                        network bandwidth rate [bit per second]. valid units
                        are either: K/M/G/Kbps/Mbps/Gbps e.g. --rate 10Mbps
                        round trip network delay. the valid range is from 0ms
                        to 60min. valid time units are: m/min/mins/minute/minu
                        if no unit string found, considered milliseconds as
                        the time unit. (default=0ms)
  --delay-distro LATENCY_DISTRO_TIME
                        distribution of network latency becomes X +- Y (normal
                        distribution). Here X is the value of --delay option
                        and Y is the value of --delay-dist option). network
                        latency distribution is uniform, without this option.
                        valid time units are: m/min/mins/minute/minutes/s/sec/
                        onds/us/usec/usecs/microsecond/microseconds. if no
                        unit string found, considered milliseconds as the time
                        round trip packet loss rate [%]. the valid range is
                        from 0 to 100. (default=0)
                        round trip packet duplicate rate [%]. the valid range
                        is from 0 to 100. (default=0)
                        packet corruption rate [%]. the valid range is from 0
                        to 100. packet corruption means single bit error at a
                        random offset in the packet. (default=0)
  --reordering REORDERING_RATE
                        packet reordering rate [%]. the valid range is from 0
                        to 100. (default=0)
  --shaping-algo {htb,htb}
                        shaping algorithm. defaults to htb (recommended).
  --iptables            use iptables to traffic control.

  --direction {outgoing,incoming}
                        the direction of network communication that impose
                        traffic control. 'incoming' requires Linux kernel
                        version 2.6.20 or later. (default = outgoing)
  --network DST_NETWORK, --dst-network DST_NETWORK
                        target IP-address/network to control traffic
  --src-network SRC_NETWORK
                        set a traffic shaping rule to specific packets that
                        routed from --src-network to --dst-network. this
                        option required to execute with the --iptables option
                        when you use tbf. the shaping rule only affect to
                        outgoing packets (no effect to if you execute with "--
                        direction incoming" option)
  --port DST_PORT, --dst-port DST_PORT
                        target destination port number to control traffic.
  --src-port SRC_PORT   target source port number to control traffic.
  --ipv6                apply traffic control to IPv6 packets rather than
  --exclude-dst-network EXCLUDE_DST_NETWORK
                        exclude a shaping rule for a specific destination IP-
  --exclude-src-network EXCLUDE_SRC_NETWORK
                        exclude a shaping rule for a specific source IP-
  --exclude-dst-port EXCLUDE_DST_PORT
                        exclude a shaping rule for a specific destination
  --exclude-src-port EXCLUDE_SRC_PORT
                        exclude a shaping rule for a specific source port.

Issue tracker: https://github.com/thombashi/tcconfig/issues

4.1.2. Basic usage

Examples of outgoing packet traffic control settings are as follows. e.g. Set a limit on bandwidth up to 100Kbps

# tcset --device eth0 --rate 100k e.g. Set network latency

You can use time units (such as us/sec/min/etc.) to designate delay time. Set 100 milliseconds network latency

# tcset --device eth0 --delay 100ms Set 10 seconds network latency

# tcset --device eth0 --delay 10sec Set 0.5 minutes (30 seconds) network latency

# tcset --device eth0 --delay 0.5min e.g. Set 0.1% packet loss

# tcset --device eth0 --loss 0.1 e.g. All of the above at once

# tcset --device eth0 --rate 100k --delay 100 --loss 0.1 e.g. Specify the IP address of traffic control

# tcset --device eth0 --delay 100 --network e.g. Specify the IP network and port of traffic control

# tcset --device eth0 --delay 100 --network --port 80

4.1.3. Advanced usage Traffic control of incoming packets

Execute tcset command with --direction incoming option to set incoming traffic control. Other options are the same as in the case of the basic usage. e.g. Set traffic control both incoming and outgoing network

# tcset --device eth0 --direction outgoing --rate 200K --network
# tcset --device eth0 --direction incoming --rate 1M --network Requirements

Incoming packet traffic control requires additional ifb module, Which need to the following conditions:

  • Equal or later than Linux kernel version 2.6.20
  • Equal or later than iproute2 package version 20070313 Set latency distribution

Latency setting by --delay option is a uniform distribution. If you are using --delay-distro option, latency decided by a normal distribution. e.g. Set 100ms +- 20ms network latency with normal distribution

# tcset --device eth0 --delay 100 --delay-distro 20 Multiple traffic shaping rules per interface

You can set multiple shaping rules to a network interface with --add option.

tcset --device eth0 --rate 500M --network
tcset --device eth0 --rate 100M --network --add Using IPv6

IPv6 addresses can be used at tcset/tcshow commands with --ipv6 option.

# tcset --device eth0 --delay 100 --network 2001:db00::0/24 --ipv6
# tcshow --device eth0 --ipv6
    "eth0": {
        "outgoing": {
            "dst-network=2001:db00::/24, protocol=ipv6": {
                "delay": "100.0",
                "rate": "1G"
        "incoming": {}
} Get tc commands

You can get tc commands to be executed by tcconfig commands by executing with --tc-command option (no tc configuration have made to the execution server by this command).

# tcset --device eth0 --delay 10 --tc-command
tc qdisc add dev eth0 root handle 1f87: htb default 1
tc class add dev eth0 parent 1f87: classid 1f87:1 htb rate 1000000kbit
tc class add dev eth0 parent 1f87: classid 1f87:2 htb rate 1000000Kbit ceil 1000000Kbit
tc qdisc add dev eth0 parent 1f87:2 handle 2007: netem delay 10.0ms
tc filter add dev eth0 protocol ip parent 1f87: prio 1 u32 match ip dst flowid 1f87:2 Generate a tc script file

--tc-script option generates an executable script which includes tc commands to be executed by tcconfig commands. The created script can execute at other servers where tcconfig not installed (however, you need the tc command to run the script).

# tcset --device eth0 --delay 10 --tc-script
[INFO] tcconfig: written a tc script to 'tcset_eth0.sh'
# ./tcset_eth0.sh