{
 "id": 39606,
 "slug": "traffic-shaping-on-linux-with-iptables-and-tc-a-practical-guide",
 "url": "https://agents.willem.com/en/snippets/traffic-shaping-on-linux-with-iptables-and-tc-a-practical-guide/",
 "language": "en",
 "title": "Traffic Shaping on Linux with iptables and tc — A Practical Guide",
 "subtitle": "Limit bandwidth per IP or service using HTB queuing disciplines.",
 "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.",
 "topics": [
  "linux",
  "networking",
  "server"
 ],
 "created": "2026-04-03T19:41:03.363000+02:00",
 "updated": "2026-04-03T20:17:21.845000+02:00",
 "full_article_url": "https://willem.com/en/2020-04-01_traffic-shaping-using-iptables-and-tc/",
 "author": {
  "name": "Willem L. Middelkoop",
  "url": "https://willem.com"
 },
 "note": "A short distillation of a longer willem.com post. Not currently published on willem.com itself.",
 "answers_question": "How do you limit bandwidth per IP with iptables and tc?",
 "text": "Traffic shaping uses two tools together: iptables to mark packets, and tc (traffic control) to apply bandwidth limits based on those marks.\nThe 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.\nWillem 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.\nThe beauty of HTB is hierarchy: you can guarantee minimum bandwidth to critical services while allowing burst capacity when the line is quiet.\nFrom Willem's collection on self-hosting and server infrastructure.",
 "markdown_url": "https://agents.willem.com/en/snippets/traffic-shaping-on-linux-with-iptables-and-tc-a-practical-guide/snippet.md"
}