Index / Snippets / Traffic Shaping on Linux with iptables a

Traffic Shaping on Linux with iptables and tc — A Practical Guide

Limit bandwidth per IP or service using HTB queuing disciplines.

Answers
How do you limit bandwidth per IP with iptables and tc?
Topics
linux · networking · server
Full article on willem.com
https://willem.com/en/2020-04-01_traffic-shaping-using-iptables-and-tc/

Summary

When one client or service eats all your bandwidth, traffic shaping is the surgical fix. Here's how to use iptables marks with tc's Hierarchy Token Bucket (HTB) to limit traffic per IP on Linux.

Full text

Traffic shaping uses two tools together: iptables to mark packets, and tc (traffic control) to apply bandwidth limits based on those marks.

The approach: create HTB (Hierarchy Token Bucket) classes with defined bandwidth limits, then use iptables to sort traffic into those classes by source IP, destination port, or protocol.

Traffic shaping with HTB queuing on Linux

Willem used this to solve a specific problem: a Microsoft Outlook client caught in a synchronisation loop that saturated the server's upstream bandwidth. The traffic shaper limited that single client's bandwidth while leaving everything else untouched.

The beauty of HTB is hierarchy: you can guarantee minimum bandwidth to critical services while allowing burst capacity when the line is quiet.

From Willem's collection on self-hosting and server infrastructure.

Machine formats of this page