{"id":1747,"date":"2026-02-11T10:52:03","date_gmt":"2026-02-11T02:52:03","guid":{"rendered":"https:\/\/www.yeetrack.com\/?p=1747"},"modified":"2026-02-11T10:57:29","modified_gmt":"2026-02-11T02:57:29","slug":"linux%e4%bd%bf%e7%94%a8tc%e5%91%bd%e4%bb%a4%e8%bf%9b%e8%a1%8c%e7%bd%91%e7%bb%9c%e9%99%90%e9%80%9f","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=1747","title":{"rendered":"linux\u4f7f\u7528tc\u547d\u4ee4\u8fdb\u884c\u7f51\u7edc\u9650\u901f"},"content":{"rendered":"<p>\u516c\u53f8\u6709\u51e0\u4e2a\u72ec\u7acb\u7684\u5de5\u5382\uff0c\u4e00\u822c\u6bcf\u4e2a\u5de5\u5382\u90fd\u4f1a\u6709\u81ea\u5df1\u672c\u5730\u7684\u673a\u623f\uff0c\u7528\u6765\u90e8\u7f72\u672c\u5730\u7684\u751f\u4ea7\u7cfb\u7edf\u3002\u8fd9\u4e9b\u7cfb\u7edf\u90fd\u662f\u72ec\u7acb\u8fd0\u884c\uff0c\u6709\u81ea\u5df1\u7684\u6570\u636e\u5e93\u3001\u4e2d\u95f4\u4ef6\u3001\u4e0a\u5c42\u670d\u52a1\u7b49\uff0c\u4e3a\u4e86\u9632\u6b62\u673a\u623f\u6545\u969c\uff0c\u4f1a\u6bcf\u5929\u628a\u91cd\u8981\u6570\u636e\u5907\u4efd\u4e0b\u6765\uff0c\u7136\u540e\u5b58\u5230\u5f02\u5730\uff08\u6bd4\u5982\u516c\u6709\u4e91\uff09\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5907\u4efd\u4efb\u52a1\u8dd1\u4e86\u5f88\u4e45\u4e86\uff0c\u6ca1\u51fa\u73b0\u95ee\u9898\uff0c\u4f46\u662f\u6700\u8fd1\u6709\u4eba\u53cd\u9988\u6bcf\u5929\u51cc\u6668\uff0c\u5de5\u5382\u7f51\u7edc\u4f1a\u5361\uff0c\u68c0\u67e5\u4e86\u4e00\u4e0b\u7f51\u7edc\u76d1\u63a7\uff0c\u662f\u56e0\u4e3a\u5f02\u5730\u5907\u4efd\u7684\u65f6\u5019\uff0c\u628a\u516c\u7f51\u5e26\u5bbd\u6253\u6ee1\u4e86\uff0c\u9700\u8981\u5bf9\u5907\u4efd\u4efb\u52a1\u8fdb\u884c\u9650\u901f\u3002  <\/p>\n<ol>\n<li>\n<p>\u5907\u4efd\u8f6f\u4ef6\u9650\u901f<br \/>\n\u5982\u679c\u6ca1\u6709\u5e95\u5c42\u64cd\u4f5c\u7cfb\u7edf\u3001\u4ea4\u6362\u673a\u7684\u6743\u9650\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u5907\u4efd\u8f6f\u4ef6\u81ea\u5df1\u7684\u9650\u901f\uff0c\u6211\u4eec\u4f7f\u7528\u7684\u662f\u767e\u5ea6\u516c\u6709\u4e91BOS\uff0c\u4f7f\u7528bcecmd\u547d\u4ee4\u8fdb\u884c\u5907\u4efd\uff0c\u867d\u7136bcecmd\u63d0\u4f9b\u9650\u901f\u6307\u4ee4\uff0c\u4f46\u4ec5\u9002\u7528\u4e8e\u4e91\u7aefbucket\u4e4b\u95f4\uff0c\u5e76\u4e0d\u63d0\u4f9b\u672c\u5730\u5230\u4e91\u7aef\u7684\u9650\u901f\uff0c\u6b64\u8def\u4e0d\u901a\u3002  <\/p>\n<pre><code>https:\/\/cloud.baidu.com\/doc\/BOS\/s\/kmcn3zrup\n--traffic-limit:\u5bf9\u4e8e\u4e0a\u4f20\u4e0b\u8f7d\uff0c\u5355\u4f4d\u4e3aKB\/s\uff0c\u6ca1\u6709\u8303\u56f4\u9650\u5236\uff1b\u5bf9\u4e8eBOS\u5230BOS\u4e4b\u95f4\u7684\u6570\u636e\u62f7\u8d1d\uff0c\u9650\u901f\u503c\u7684\u53d6\u503c\u8303\u56f4\u4e3a819200~838860800\uff0c\u5355\u4f4d\u4e3abit\/s\uff0c\u5373100KB\/s~100MB\/s\u3002<\/code><\/pre>\n<\/li>\n<li>\n<p>\u9632\u706b\u5899\u9650\u901f<br \/>\n\u5982\u679c\u6709\u5e95\u5c42\u8bbe\u5907\u7684\u6743\u9650\uff0c\u53ef\u4ee5\u64cd\u4f5c\u5de5\u5382\u9632\u706b\u5899\uff0c\u6307\u5b9a\u5bf9\u67d0\u4e2aIP\u8fdb\u884c\u9650\u901f\u3002<\/p>\n<\/li>\n<li>\n<p>\u64cd\u4f5c\u7cfb\u7edf\u9650\u901f<br \/>\n\u5f53\u7136\u65b9\u4fbf\u7684\u8fd8\u662f\u64cd\u4f5c\u7cfb\u7edf\u5c42\u9762\u8fdb\u884c\u9650\u901f\uff0c\u9650\u5236\u67d0\u4e2a\u7f51\u5361\u7684\u51fa\u53e3\u901f\u5ea6\uff0c\u4f7f\u7528tc\u547d\u4ee4\u5373\u53ef\uff1b\u9650\u5236\u67d0\u4e2a\u7f51\u5361\u5230\u67d0\u4e2aIP\u7684\u6700\u5927\u5e26\u5bbd\u3002  <\/p>\n<pre><code>#!\/bin\/bash\n# Purpose: Limit outgoing traffic to a specific IP using tc HTB\n\nIFACE=$(ip route | awk '\/default\/ {print $5}')\nTARGET_IP=\"XX.XX.XX.XX\"\nRATE=\"100mbit\"\nCEIL=\"100mbit\"\nBURST=\"2m\"\n\nGATEWAY=$(ip route | awk '\/default\/ {print $3}') # \u7b49\u5f85\u7f51\u5173\u53ef\u8fbe\nuntil ping -c1 \"$GATEWAY\" &>\/dev\/null; do\n    echo \"Waiting for gateway $GATEWAY...\"\n    sleep 5\ndone\n\n# 1&#xfe0f;&#x20e3; \u5220\u9664\u5df2\u6709\u6839\u961f\u5217\uff08\u5982\u679c\u5b58\u5728\uff09\nsudo tc qdisc del dev $IFACE root 2>\/dev\/null || true\n\n# 2&#xfe0f;&#x20e3; \u6dfb\u52a0\u6839\u961f\u5217\nsudo tc qdisc add dev $IFACE root handle 1: htb default 30\n\n# 3&#xfe0f;&#x20e3; \u6dfb\u52a0\u9650\u901f\u5b50\u7c7b\nsudo tc class add dev $IFACE parent 1: classid 1:10 htb rate $RATE ceil $CEIL burst $BURST\n\n# 4&#xfe0f;&#x20e3; \u6dfb\u52a0\u9ed8\u8ba4\u5b50\u7c7b\uff0c\u4fdd\u8bc1\u5176\u4ed6\u6d41\u91cf\u4e0d\u53d7\u5f71\u54cd\nsudo tc class add dev $IFACE parent 1: classid 1:30 htb rate 1gbit ceil 1gbit\n\n# 5&#xfe0f;&#x20e3; \u6dfb\u52a0\u8fc7\u6ee4\u5668\uff0c\u5c06\u53d1\u5f80\u76ee\u6807 IP \u7684\u6d41\u91cf\u5339\u914d\u5230\u9650\u901f\u5b50\u7c7b\nsudo tc filter add dev $IFACE protocol ip parent 1:0 prio 1 u32 match ip dst $TARGET_IP\/32 flowid 1:10\n\necho \"Bandwidth limiting applied: $IFACE  $TARGET_IP \u2192 $RATE\"<\/code><\/pre>\n<p>\u4e0a\u9762\u7684\u811a\u672c\uff0c\u53ef\u81ea\u52a8\u83b7\u53d6\u9ed8\u8ba4\u7f51\u5361\uff0c\u7136\u540e\u53ea\u9650\u5236\u5230\u67d0\u4e2aIP\u7684\u6700\u5927\u5bbd\u5e26\u4e3a100Mb\/s\uff0c\u4e0d\u9650\u5236\u5176\u4ed6IP\u5730\u5740\u3002<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u516c\u53f8\u6709\u51e0\u4e2a\u72ec\u7acb\u7684\u5de5\u5382\uff0c\u4e00\u822c\u6bcf\u4e2a\u5de5\u5382\u90fd\u4f1a\u6709\u81ea\u5df1\u672c\u5730\u7684\u673a\u623f\uff0c\u7528\u6765\u90e8\u7f72\u672c\u5730\u7684\u751f\u4ea7\u7cfb\u7edf\u3002\u8fd9\u4e9b\u7cfb\u7edf\u90fd\u662f\u72ec\u7acb\u8fd0\u884c\uff0c\u6709\u81ea\u5df1\u7684\u6570\u636e\u5e93\u3001\u4e2d\u95f4\u4ef6\u3001\u4e0a\u5c42\u670d\u52a1\u7b49\uff0c\u4e3a\u4e86\u9632\u6b62\u673a\u623f\u6545\u969c\uff0c\u4f1a\u6bcf\u5929\u628a\u91cd\u8981\u6570\u636e\u5907\u4efd\u4e0b\u6765\uff0c\u7136\u540e\u5b58\u5230\u5f02\u5730\uff08\u6bd4\u5982&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[34],"tags":[11],"class_list":["post-1747","post","type-post","status-publish","format-standard","hentry","category-software","tag-linux"],"views":211,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1747"}],"version-history":[{"count":2,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1747\/revisions"}],"predecessor-version":[{"id":1749,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1747\/revisions\/1749"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}