{"id":2575,"date":"2025-09-10T20:20:15","date_gmt":"2025-09-10T19:20:15","guid":{"rendered":"https:\/\/cdblog.cdstealer.com\/?p=2575"},"modified":"2026-01-18T05:24:31","modified_gmt":"2026-01-18T05:24:31","slug":"linux-traffic-shaping","status":"publish","type":"post","link":"https:\/\/cdblog.cdstealer.com\/?p=2575","title":{"rendered":"Linux Traffic Shaping"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Sometimes you just gotta stop people taking all your bandwidth.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below is the process I used to restrict the speed of data on port 22.  Yes scp has a built in limiter, but when people don't respect your authority, you got to break out the big guns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1.&nbsp; Load required kernel modules and set device.<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">modprobe sch_netem act_police cls_flow cls_route cls_matchall cls_basic cls_flower cls_u32 cls_bpf cls_fw sch_htb sch_fq_codel sch_sfq<br><br>DEV=$(ip a | grep \"2:\" | cut -d':' -f2 | sed 's\/\\s\/\/g')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2.&nbsp; Add a qdisc (Queue Discipline)<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">tc qdisc add \\<br>dev \"${DEV}\" \\<br>root \\<br>handle 1: \\<br>htb \\<br>default 30<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3.&nbsp; Create a&nbsp;single top level class which limits total bandwidth<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">tc class add \\<br>dev \"${DEV}\" \\<br>parent 1: \\<br>classid 1:1 \\<br>htb \\<br>rate 1gbit<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4.&nbsp; Create a child class<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">tc class add \\<br>dev \"${DEV}\" \\<br>parent 1:1 \\<br>classid 1:10 \\<br>htb \\<br>rate 20mbit \\<br>ceil 30mbit \\<br>prio 1<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5.&nbsp; Attach a leaf qdisc to the class<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">tc qdisc add \\<br>dev \"${DEV}\" \\<br>parent 1:10 \\<br>sfq<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6.&nbsp;&nbsp;Add filter for priority traffic<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">tc filter add \\<br>dev \"${DEV}\" \\<br>parent 1: \\<br>protocol ip \\<br>prio 1 \\<br>u32 \\<br>match ip dport 22 0xffff \\<br>flowid 1:10<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">To remove the config from the interface, execute the following:<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">tc qdisc del \\<br>dev \"${DEV}\" \\<br>root \\<br>htb<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you just gotta stop people taking all your bandwidth. Below is the process I used to restrict the speed of data on port 22. Yes scp has a built in limiter, but when people don't respect your authority, you got to break out the big guns. Step 1.&nbsp; Load required kernel modules and set &hellip; <a href=\"https:\/\/cdblog.cdstealer.com\/?p=2575\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux Traffic Shaping<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[18,354],"class_list":["post-2575","post","type-post","status-publish","format-standard","hentry","category-gentoo","tag-linux","tag-traffic-shaping"],"_links":{"self":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2575"}],"version-history":[{"count":2,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2575\/revisions"}],"predecessor-version":[{"id":2668,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=\/wp\/v2\/posts\/2575\/revisions\/2668"}],"wp:attachment":[{"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cdblog.cdstealer.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}