Professional Documents
Culture Documents
Linux HTTP Outgoing Traffic Shaping (Port 80 Traffic Shaping)
Linux HTTP Outgoing Traffic Shaping (Port 80 Traffic Shaping)
Linux HTTP Outgoing Traffic Shaping (Port 80 Traffic Shaping)
Computing Linux CentOS Debian / Ubuntu Ubuntu Linux Suse RedHat and Friends Slackware Linux UNIX AIX Mac OS X FreeBSD FreeBSD Jails (VPS) Openbsd Solaris See all tutorial topics Blog About Contact us Forum Linux Scripting Guide RSS/FEED
and it is called traffic shaping: 1. When traffic is shaped, its rate of transmission is under control, in other words you apply some sort of bandwidth allocation for each port or or so called Linux services. Shaping occurs on egress. 2. You can only apply traffic shaping to outgoing or forwarding traffic i.e. you do not have any control for incoming traffic to server. However, tc can do policing controls for arriving traffic. Policing thus occurs on ingress. This FAQ only deals with traffic shaping.
1. 2. 3. 4.
The TB filter puts tokens into the bucket at a certain rate. Each token is permission for the source to send a specific number of bits into the network. Bucket can hold b tokens as per shaping rules. Kernel can send packet if you've a token else traffic need to wait.
Sample outputs:
q d i s cp f i f o _ f a s t0 :r o o tb a n d s3p r i o m a p 1222120011111111 S e n t2 7 3 2 1 0 8b y t e s1 0 7 3 2p k t( d r o p p e d0 ,o v e r l i m i t s0r e q u e u e s0 ) r a t e0 b i t0 p p sb a c k l o g0 b0 pr e q u e u e s0
Sample outputs:
P I N Gc y b e r c i t i . b i z( 7 4 . 8 6 . 4 8 . 9 9 )5 6 ( 8 4 )b y t e so fd a t a . 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 1t t l = 4 7t i m e = 3 0 4m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 2t t l = 4 7t i m e = 3 0 4m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 3t t l = 4 7t i m e = 3 0 4m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 4t t l = 4 7t i m e = 3 0 4m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 5t t l = 4 7t i m e = 3 0 4m s
6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 6t t l = 4 7t i m e = 3 0 4m s
Sample outputs:
P I N Gc y b e r c i t i . b i z( 7 4 . 8 6 . 4 8 . 9 9 )5 6 ( 8 4 )b y t e so fd a t a . 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 1t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 2t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 3t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 4t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 5t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 6t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 7t t l = 4 7t i m e = 5 0 5m s 6 4b y t e sf r o mt x v i p 1 . s i m p l y g u i d e . o r g( 7 4 . 8 6 . 4 8 . 9 9 ) :i c m p _ s e q = 8t t l = 4 7t i m e = 5 0 5m s ^ C -c y b e r c i t i . b i zp i n gs t a t i s t i c s8p a c k e t st r a n s m i t t e d ,8r e c e i v e d ,0 %p a c k e tl o s s ,t i m e7 0 0 6 m s r t tm i n / a v g / m a x / m d e v=5 0 4 . 4 6 4 / 5 0 5 . 3 0 3 / 5 0 6 . 3 0 8 / 0 . 9 4 9m s
Sample outputs:
q d i s cn e t e m8 0 0 1 :r o o tl i m i t1 0 0 0d e l a y2 0 0 . 0 m s S e n t1 7 5 5 4 5b y t e s5 4 0p k t( d r o p p e d0 ,o v e r l i m i t s0r e q u e u e s0 ) r a t e0 b i t0 p p sb a c k l o g0 b0 pr e q u e u e s0
TBF Example
To attach a TBF with a sustained maximum rate of 1mbit/s, a peakrate of 2.0mbit/s, a 10kilobyte buffer, with a prebucket queue size limit calculated so the TBF causes at most 70ms of latency, with perfect peakrate behavior, enter:
#t cq d i s ca d dd e ve t h 0r o o tt b fr a t e1 m b i tb u r s t1 0 k bl a t e n c y7 0 m sp e a k r a t e2 m b i t m i n b u r s t1 5 4 0
Define a class with limitations i.e. set the allowed bandwidth to 512 Kilobytes and burst bandwidth to 640 Kilobytes for port 80:
#/ s b i n / t cc l a s sa d dd e ve t h 1p a r e n t1 : 0c l a s s i d1 : 1 0h t br a t e5 1 2 k b p sc e i l6 4 0 k b p sp r i o0
Please note that port 80 is NOT defined anywhere in above class. You will use iptables mangle rule as follows:
#/ s b i n / i p t a b l e sAO U T P U Ttm a n g l ept c ps p o r t8 0jM A R Ks e t m a r k1 0
To test download speed use lftp or wget command line tools. References: Read tc, tc-tbf and tc-htb command man pages. Linux Advanced Routing & Traffic Control TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us! Featured Articles: 30 Cool Open Source Software I Discovered in 2013 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X Top 30 Nmap Command Examples For Sys/Network Admins 25 PHP Security Best Practices For Sys Admins 20 Linux System Monitoring Tools Every SysAdmin Should Know 20 Linux Server Hardening Security Tips Linux: 20 Iptables Examples For New SysAdmins Top 20 OpenSSH Server Best Security Practices Top 20 Nginx WebServer Best Security Practices 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors 15 Greatest Open Source Terminal Applications Of 2012 My 10 UNIX Command Line Mistakes Top 10 Open Source Web-Based Project Management Software Top 5 Email Client For Linux, Mac OS X, and Windows Users The Novice Guide To Buying A Linux Laptop
{ 4 comments read them below or add one } 1 Catalin(ux) M. BOIE April 15, 2010 at 5:51 am For nice ncurses display of classes, you can use lqdump from lqkit (I am the author). RPM, tgz, source: http://kernel.embedromix.ro/us/ Screenshot: http://kernel.embedromix.ro/us/lqkit/ss/lqdump_ss1.png Reply 2 Guy Egozy November 4, 2010 at 11:26 pm For simplicity sake you may also want to check out trickle. Ive successfully used it in bash scripts for upload capping but it should also work for services. Reply 3 ute May 24, 2012 at 10:29 pm What happens if a rule like this: tc qdisc add dev eth0 root handle 1: htb tc class add dev eth0 parent 1: classid 1:1 htb rate 24kbps ceil 128kbps tc class add dev eth0 parent 1: classid 1:2 htb rate 24kbps ceil 128kbps tc filter add dev eth0 parent 1:0 prio 1 protocol ip handle 5 fw flowid 1:1 tc filter add dev eth0 parent 1:0 prio 1 protocol ip handle 6 fw flowid 1:2 iptables -A OUTPUT -t mangle -p tcp -o etho -m iprange src-range 192.168.0.100192.168.0.200 sport 80 -j MARK set-mark 5 iptables -A OUTPUT -t mangle -p tcp -o eth0 -m iprange src-range 192.168.0.100192.168.0.200 sport 443 -j MARK set-mark 6 Is the above rules will limit the range of 1 ip in iptables are trying to access port 80 and 443 at 24 kbps up to 128kbps in mark 5 and 6 with iptables if possible . Or any ip within range will fight for a bandwidth of 24128kbps? Please give me a simple explanation. Reply 4 rahul June 23, 2012 at 12:19 pm hello, I have a cent os 6 server. i created a vlan in my server. so it is possible that ithis tc configurations run on vlans properly. Thanks. Reply
Tagged as: Arch Linux Shape Traffic, bandwidth allocation, CentOS Linux Shape Traffic, Debian Linux Shape Traffic, Fedora Linux Shape Traffic, Linux shape port 80 traffic, Linux tc throttle http, Linux tc throttle port 80 traffic, maximum rate, OpenSuse Linux Shape Traffic, Redhat Linux Shape Traffic, RHEL Linux Shape Traffic, Slackware Linux Shape Traffic, Suse Linux Shape Traffic, tc command, token bucket, Ubuntu Linux Shape Traffic Previous Faq: Linux: Set OR Change The Library Path Next Faq: UNIX / Linux: PGP TarBall File Signature Keys Verification
nixCraft
Follow
+ 10,579
+1
Related Faqs
CentOS / RHEL: Install iftop To Display Bandwidth Usage Per interface By Host
axfr-get: fatal: unable to parse AXFR results: protocol error and Solution
nixCraft
Like
Tweets
nixCraft Linux Blog @nixcraft
Follow 11 Mar
Awesome! I just lost like an hour to this game gabrielecirulli.github.io/2048/ #evilgame Expand nixCraft Linux Blog @nixcraft [Updated] Linux Add a Swap File Without Creating New Partitions cyberciti.biz/faq/linux-add- Expand nixCraft Linux Blog @nixcraft Linux / Unix: chroot Command Examples cyberciti.biz/faq/unix-linux Expand nixCraft Linux Blog @nixcraft
9 Mar 10 Mar 11 Mar
Minify and Compress CSS and Javascript files at a Linux/Unix shell prompt without using online tools cyberciti.biz/faq/linux-unix Expand nixCraft Linux Blog @nixcraft
9 Mar
Tweet to @nixcraft
Subscribe to nixCraft
Learn something new about Linux/Unix by email Enter your email address:
Subscribe
2000-2014 nixCraft. All rights reserved. Privacy Policy - Terms of Service - Questions or Comments - We are proudly powered by Linux + Nginx + WordPress. The content is copyrighted to nixCraft and may not be reproduced on other websites.