{"id":76175,"date":"2013-03-23T13:09:08","date_gmt":"2013-03-23T06:09:08","guid":{"rendered":"http:\/\/www.icez.net\/blog\/?p=76175"},"modified":"2013-05-06T00:17:25","modified_gmt":"2013-05-05T17:17:25","slug":"0154-script-limit-bandwidth-udp","status":"publish","type":"post","link":"https:\/\/www.icez.net\/blog\/76175\/0154-script-limit-bandwidth-udp","title":{"rendered":"0154 | script limit bandwidth UDP"},"content":{"rendered":"<p>\u0e40\u0e2d\u0e32 script \u0e0a\u0e32\u0e27\u0e1a\u0e49\u0e32\u0e19\u0e21\u0e32\u0e14\u0e31\u0e14\u0e41\u0e1b\u0e25\u0e07\u0e19\u0e34\u0e14\u0e2b\u0e19\u0e48\u0e2d\u0e22\u0e2e\u0e30 \u0e15\u0e49\u0e19\u0e09\u0e1a\u0e31\u0e1a shape \u0e15\u0e32\u0e21 IP \u0e41\u0e15\u0e48\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e41\u0e01\u0e49\u0e43\u0e2b\u0e49\u0e1a\u0e35\u0e1a\u0e40\u0e09\u0e1e\u0e32\u0e30 UDP<br \/>\nhttp:\/\/www.iplocation.net\/tools\/traffic-control.php<\/p>\n<p>\u0e0b\u0e36\u0e48\u0e07\u0e42\u0e14\u0e22\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e1b\u0e01\u0e15\u0e34\u0e21\u0e31\u0e19\u0e44\u0e21\u0e48\u0e08\u0e33\u0e40\u0e1b\u0e47\u0e19\u0e15\u0e49\u0e2d\u0e07\u0e43\u0e0a\u0e49 UDP \u0e40\u0e22\u0e2d\u0e30\u0e2d\u0e30\u0e44\u0e23\u0e02\u0e19\u0e32\u0e14\u0e19\u0e35\u0e49\u0e2d\u0e22\u0e39\u0e48\u0e41\u0e25\u0e49\u0e27 \u0e01\u0e47\u0e1e\u0e2d\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e0a\u0e48\u0e27\u0e22\u0e01\u0e31\u0e19\u0e01\u0e32\u0e23\u0e22\u0e34\u0e07 udp \u0e2d\u0e2d\u0e01\u0e44\u0e14\u0e49\u0e2d\u0e22\u0e39\u0e48\u0e2b\u0e19\u0e48\u0e2d\u0e22\u0e19\u0e36\u0e07<\/p>\n<pre lang=\"bash\">\r\n#!\/bin\/bash\r\n#\r\n# udplimiter This script limit the bandwidth for udp traffic\r\n#\r\n# chkconfig: - 13 87\r\n\r\n### BEGIN INIT INFO\r\n# Provides: $udplimiter\r\n# Required-Start: $network\r\n# Required-Stop: $network\r\n# Default-Start:\r\n# Default-Stop: 0 1 2 3 4 5 6\r\n# Short-Description: start|stop|status|restart Bandwidth Limiter\r\n# Description: This script limit the bandwidth for udp traffic\r\n### END INIT INFO\r\n\r\n\r\n#  tc uses the following units when passed as a parameter.\r\n#  kbps: Kilobytes per second\r\n#  mbps: Megabytes per second\r\n#  kbit: Kilobits per second\r\n#  mbit: Megabits per second\r\n#  bps: Bytes per second\r\n#       Amounts of data can be specified in:\r\n#       kb or k: Kilobytes\r\n#       mb or m: Megabytes\r\n#       mbit: Megabits\r\n#       kbit: Kilobits\r\n#  To get the byte figure from bits, divide the number by 8 bit\r\n#\r\n\r\n#\r\n# Name of the traffic control command.\r\nTC=\/sbin\/tc\r\n\r\n# The network interface we're planning on limiting bandwidth.\r\nIF=eth0             # Interface\r\n\r\n# Bandwidth limit (in mega bits)\r\nBWLIMIT=5mbit          # DOWNLOAD Limit\r\n\r\n# Filter options for limiting the intended interface.\r\nU32=\"$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32\"\r\n\r\nstart() {\r\n\r\n# We'll use Hierarchical Token Bucket (HTB) to shape bandwidth.\r\n# For detailed configuration options, please consult Linux man\r\n# page.\r\n\r\n    $TC qdisc add dev $IF root handle 1: htb default 30\r\n    $TC class add dev $IF parent 1: classid 1:1 htb rate $BWLIMIT\r\n    $U32 match ip protocol 17 0xff flowid 1:1\r\n\r\n# The first line creates the root qdisc, and the next two lines\r\n# create two child qdisc that are to be used to shape download\r\n# and upload bandwidth.\r\n#\r\n# The 4th and 5th line creates the filter to match the interface.\r\n# The 'dst' IP address is used to limit download speed, and the\r\n# 'src' IP address is used to limit upload speed.\r\n\r\n}\r\n\r\nstop() {\r\n\r\n# Stop the bandwidth shaping.\r\n    $TC qdisc del dev $IF root\r\n\r\n}\r\n\r\nrestart() {\r\n\r\n# Self-explanatory.\r\n    stop\r\n    sleep 1\r\n    start\r\n\r\n}\r\n\r\nshow() {\r\n\r\n# Display status of traffic control status.\r\n    $TC -s qdisc ls dev $IF\r\n\r\n}\r\n\r\ncase \"$1\" in\r\n\r\n  start)\r\n\r\n    echo -n \"Starting bandwidth shaping: \"\r\n    start\r\n    echo \"done\"\r\n    ;;\r\n\r\n  stop)\r\n\r\n    echo -n \"Stopping bandwidth shaping: \"\r\n    stop\r\n    echo \"done\"\r\n    ;;\r\n\r\n  restart)\r\n\r\n    echo -n \"Restarting bandwidth shaping: \"\r\n    restart\r\n    echo \"done\"\r\n    ;;\r\n\r\n  show)\r\n\r\n    echo \"Bandwidth shaping status for $IF:\"\r\n    show\r\n    echo \"\"\r\n    ;;\r\n\r\n  *)\r\n\r\n    pwd=$(pwd)\r\n    echo \"Usage: $0 {start|stop|restart|show}\"\r\n    ;;\r\n\r\nesac\r\n\r\nexit 0\r\n<\/pre>\n<p>\u0e40\u0e2d\u0e32\u0e44\u0e1b\u0e40\u0e0b\u0e1f\u0e43\u0e2a\u0e48 \/etc\/init.d\/udplimiter \u0e41\u0e25\u0e49\u0e27\u0e2a\u0e31\u0e48\u0e07 \/etc\/init.d\/udplimiter start \u0e44\u0e14\u0e49\u0e40\u0e25\u0e22 \u0e16\u0e49\u0e32\u0e08\u0e30\u0e43\u0e2b\u0e49\u0e17\u0e33\u0e07\u0e32\u0e19\u0e15\u0e2d\u0e19\u0e40\u0e1b\u0e34\u0e14\u0e40\u0e04\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e2d\u0e31\u0e15\u0e42\u0e19\u0e21\u0e31\u0e15\u0e34\u0e14\u0e49\u0e27\u0e22\u0e01\u0e47 chkconfig udplimiter on<\/p>\n<p>\u0e2d\u0e49\u0e2d \u0e2d\u0e22\u0e48\u0e32\u0e25\u0e37\u0e21\u0e41\u0e01\u0e49\u0e0a\u0e37\u0e48\u0e2d interface \u0e14\u0e49\u0e27\u0e22\u0e19\u0e30\u0e04\u0e23\u0e31\u0e1a \u0e15\u0e23\u0e07 IF=eth0 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0e40\u0e2d\u0e32 script \u0e0a\u0e32\u0e27\u0e1a\u0e49\u0e32\u0e19\u0e21\u0e32\u0e14\u0e31\u0e14\u0e41\u0e1b\u0e25\u0e07\u0e19\u0e34\u0e14\u0e2b\u0e19\u0e48\u0e2d\u0e22\u0e2e\u0e30 \u0e15\u0e49\u0e19\u0e09\u0e1a\u0e31\u0e1a shape \u0e15\u0e32\u0e21 IP \u0e41\u0e15\u0e48\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e41\u0e01\u0e49\u0e43\u0e2b\u0e49\u0e1a\u0e35\u0e1a\u0e40\u0e09\u0e1e\u0e32\u0e30 UDP http:\/\/www.iplocation.net\/tools\/traffic-control.php \u0e0b\u0e36\u0e48\u0e07\u0e42\u0e14\u0e22\u0e01\u0e32\u0e23\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e1b\u0e01\u0e15\u0e34\u0e21\u0e31\u0e19\u0e44\u0e21\u0e48\u0e08\u0e33\u0e40\u0e1b\u0e47\u0e19\u0e15\u0e49\u0e2d\u0e07\u0e43\u0e0a\u0e49 UDP \u0e40\u0e22\u0e2d\u0e30\u0e2d\u0e30\u0e44\u0e23\u0e02\u0e19\u0e32\u0e14\u0e19\u0e35\u0e49\u0e2d\u0e22\u0e39\u0e48\u0e41\u0e25\u0e49\u0e27 \u0e01\u0e47\u0e1e\u0e2d\u0e40\u0e2d\u0e32\u0e21\u0e32\u0e0a\u0e48\u0e27\u0e22\u0e01\u0e31\u0e19\u0e01\u0e32\u0e23\u0e22\u0e34\u0e07 udp \u0e2d\u0e2d\u0e01\u0e44\u0e14\u0e49\u0e2d\u0e22\u0e39\u0e48\u0e2b\u0e19\u0e48\u0e2d\u0e22\u0e19\u0e36\u0e07 #!\/bin\/bash # # udplimiter This script limit the bandwidth for udp traffic # # chkconfig: &#8211; 13 87 ### BEGIN INIT INFO # Provides: $udplimiter # Required-Start: $network # Required-Stop: $network # Default-Start: # Default-Stop: 0 1 2 3 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,50],"tags":[5905,2849,157],"class_list":["post-76175","post","type-post","status-publish","format-standard","hentry","category-network","category-linux","tag-linux","tag-tc","tag-traffic"],"_links":{"self":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/76175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/comments?post=76175"}],"version-history":[{"count":3,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/76175\/revisions"}],"predecessor-version":[{"id":79126,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/76175\/revisions\/79126"}],"wp:attachment":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/media?parent=76175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/categories?post=76175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/tags?post=76175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}