If you manage a Linux server or home router, uncontrolled bandwidth usage can cripple your network. Video streams saturate your upload, large downloads kill latency, and interactive sessions become unusable. Traffic shaping and Quality of Service (QoS) tools solve this by prioritizing critical traffic, capping bandwidth hogs, and eliminating bufferbloat.
Commercial QoS appliances cost thousands. This guide covers three powerful self-hosted, open-source alternatives that give you enterprise-grade traffic control on any Linux machine.
What Is Traffic Shaping?
Traffic shaping (also called packet shaping) is the practice of controlling network traffic to optimize performance, reduce latency, and ensure fair bandwidth allocation. Unlike simple rate limiting, traffic shaping uses sophisticated queuing algorithms to:
- Prioritize interactive traffic (VoIP, gaming, SSH) over bulk transfers
- Cap bandwidth for specific users, services, or applications
- Eliminate bufferbloat — the latency spike caused by oversized network buffers
- Enforce fair usage across multiple users on shared connections
Linux implements traffic shaping through the Traffic Control (tc) subsystem, which uses queuing disciplines (qdiscs) like FQ-CoDel, CAKE, HTB, and TBF. The tools below provide different interfaces to this underlying system.
Comparison Table
| Feature | SQM Scripts | tc-gui | Wondershaper |
|---|---|---|---|
| Stars | 273+ | 181+ | 6+ (fork) |
| Language | Shell/Shell | Python | Shell |
| Web UI | No (CLI/LuCI) | Yes (Flask) | No (CLI) |
| Qdisc | FQ-CoDel, CAKE | HTB, TBF, NetEm | HTB, TBF |
| Bufferbloat Fix | Excellent | Good | Basic |
| Per-IP Shaping | Yes | Yes | No |
| Class-based QoS | Yes | Yes | No |
| OpenWrt Support | Native | No | No |
| Docker Deploy | Limited | Yes | No |
| Best For | Home routers, OpenWrt | Server admin GUI | Quick one-liner setup |
SQM Scripts (Smart Queue Management)
GitHub: tohojo/sqm-scripts (273+ stars)
SQM Scripts is the gold standard for bufferbloat elimination. Created by Toke Høiland-Jørgensen and Dave Täht, it implements the CAKE and FQ-CoDel queuing algorithms that won the Bufferbloat Prize. It’s the default QoS engine in OpenWrt and runs on any Linux system with tc support.
How It Works
SQM Scripts wraps the Linux tc subsystem with intelligent defaults:
| |
The key configuration parameters:
| |
Docker Compose (Limited)
SQM Scripts requires direct access to the host’s tc subsystem, making full containerization impractical. However, you can run it via a privileged container:
| |
When to Use SQM Scripts
- Home routers and OpenWrt devices — it’s the default QoS system
- Bufferbloat elimination — best-in-class CAKE/FQ-CoDel algorithms
- Per-flow fairness — automatically isolates and shapes individual flows
- Zero configuration — works well with just bandwidth limits set
tc-gui (Traffic Control Web GUI)
GitHub: tum-lkn/tcgui (181+ stars)
tc-gui is a lightweight Python Flask web application that provides a graphical interface for Linux Traffic Control (tc). It lets you create, view, and manage traffic shaping rules without memorizing complex tc syntax.
Installation
| |
Docker Compose
| |
Features
- Visual rule creation — set bandwidth limits, priorities, and classes through a web form
- Real-time monitoring — view current queue states and packet counts
- HTB and TBF support — class-based and token bucket shaping
- Persistent rules — save configurations that survive reboots
- No database required — file-based configuration
When to Use tc-gui
- Server administrators who prefer web interfaces over CLI
- Teams managing multiple servers — consistent UI across machines
- Learning tc — visual representation helps understand queuing concepts
- Quick rule prototyping — test shaping rules before committing to scripts
Wondershaper
GitHub: mayfrost/wondershaper (6+ stars, fork of the original)
Wondershaper is the simplest traffic shaper — a single shell script that sets up HTB queuing with minimal configuration. It’s designed for “set it and forget it” scenarios where you just want to cap upload and download speeds on a single interface.
Installation
| |
Usage
| |
Systemd Service
| |
| |
When to Use Wondershaper
- Quick bandwidth capping on a single interface
- VPS servers where you need to limit total bandwidth usage
- Simple setups that don’t need per-flow or per-IP shaping
- Legacy systems where SQM Scripts isn’t available
Why Self-Host Your Traffic Shaping?
Running your own traffic shaping solution has significant advantages over cloud-based or hardware QoS appliances:
No Vendor Lock-In
Commercial QoS appliances from Cisco, Palo Alto, and Fortinet cost $2,000–$10,000+ and lock you into proprietary ecosystems. Open-source tools run on any Linux machine — a $35 Raspberry Pi or an existing server.
Complete Control Over Bufferbloat
Bufferbloat causes lag spikes during file transfers or streaming. SQM Scripts’ CAKE algorithm is proven to reduce latency by 90%+ under load. Cloud providers can’t fix bufferbloat on your last-mile connection — you need local shaping.
Per-Application Prioritization
Self-hosted tools let you define custom traffic classes:
| |
Integration With Existing Infrastructure
Traffic shaping tools integrate with your existing firewall (iptables/nftables), monitoring (Prometheus/Grafana), and configuration management (Ansible).
Network Integration
Traffic shaping works best when combined with other network infrastructure tools. For comprehensive network management, integrate your QoS solution with firewall rules for packet classification and DNS management for traffic routing. Our firewall management guide covers iptables/nftables integration, while DNS load balancing shows how to distribute traffic before shaping it. For advanced packet filtering, see our XDP/eBPF firewall comparison.
Choosing the Right Traffic Shaping Tool
| Scenario | Recommended Tool | Reason |
|---|---|---|
| Home router / OpenWrt | SQM Scripts | Native support, best bufferbloat fix |
| Server with web admin preference | tc-gui | Visual interface, easy rule management |
| Quick VPS bandwidth cap | Wondershaper | One-liner setup, no configuration |
| Enterprise class-based QoS | SQM Scripts + tc | CAKE + custom HTB classes |
| Learning traffic control | tc-gui | Visual representation of tc concepts |
FAQ
What is bufferbloat and why does it matter?
Bufferbloat occurs when network devices (routers, modems) use oversized buffers that fill up during heavy traffic. This causes latency spikes from milliseconds to seconds, making VoIP calls drop, games lag, and web pages stall. SQM Scripts with CAKE or FQ-CoDel actively manages buffer sizes, keeping latency low even under full load.
Can I run traffic shaping in a Docker container?
Partially. The Linux tc subsystem operates at the kernel level. tc-gui can run in a container with --cap-add=NET_ADMIN and network_mode: host. SQM Scripts requires direct host access to tc and network interfaces — it works best as a host service. Wondershaper needs to run on the host since it directly modifies qdisc settings.
How do I determine the correct bandwidth limits?
Set your shaped bandwidth to 90-95% of your actual connection speed. If your ISP provides 100 Mbps download and 50 Mbps upload, configure SQM Scripts with 95,000 kbps downlink and 47,500 kbps uplink. This leaves headroom for the queuing algorithms to work effectively. You can measure actual speeds with iperf3 or speedtest-cli.
Does traffic shaping reduce total throughput?
Slightly, but the tradeoff is worth it. Proper traffic shaping typically reduces maximum throughput by 2-5% while dramatically improving latency and responsiveness under load. A 100 Mbps connection shaped at 95 Mbps will feel faster for interactive use because packets aren’t stuck in bloated queues.
Is SQM Scripts compatible with WiFi networks?
Yes, SQM Scripts works on any network interface, including WiFi. However, WiFi introduces additional variable latency that can make bufferbloat worse. For best results, apply SQM Scripts on the wired WAN interface (the connection to your modem) rather than the WiFi LAN interface.
Can I combine multiple traffic shaping tools?
Not recommended. Multiple tools operating on the same interface will conflict with each other’s qdisc configurations. Choose one tool and configure all your shaping rules through it. You can use Wondershaper on one interface and SQM Scripts on another, but never on the same interface simultaneously.