LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 10-10-2010, 03:26 PM   #1
MathX
LQ Newbie
 
Registered: Oct 2010
Distribution: archlinux
Posts: 3

Rep: Reputation: 0
Limit bandwidth of a network interface : tc and iptables doesn't work ?


Hi,

I try to limit the bandwidth of my eth0 interface. I have read several articles about it and i have tried the followings commands :
Quote:
tc qdisc add dev eth0 root handle 1: htb default 30
tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbit
tc filter add dev eth0 parent 1:0 prio 1 protocol ip handle 5 fw flowid 1:1
iptables -A INPUT -t mangle -j MARK --set-mark 5
But it doesn't work. I have tried several others scripts too, again without success.
I'm running on Archlinux and I test the download speed with wget after these commands, but I always arrive at the maximum speed of my ADSL connection, and not the restricted speed.

My script is correct ? In all cases, it doesn't return an error. Or is it something else ?

Thanks.
 
Old 10-11-2010, 08:16 AM   #2
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
You police ingress (inbound) and shape(limit) egress (outbound). There is not much in the way of policing short of just dropping packets. If eth0 is your WAN/ISP uplink, you can try something like this to see if you get the results you expect...

Code:
# clear it
/sbin/tc qdisc del dev eth0 ingress 
# police it
/sbin/tc qdisc add dev eth0 handle ffff: ingress
/sbin/tc filter add dev eth0 protocol ip parent ffff: prio 50 u32 match ip \
     src 0.0.0.0/0 police rate 128kbit burst 15k drop flowid :1
Where 128 is the number, in Kilobits, you want to police incoming traffic.
 
1 members found this post helpful.
Old 10-11-2010, 11:04 AM   #3
MathX
LQ Newbie
 
Registered: Oct 2010
Distribution: archlinux
Posts: 3

Original Poster
Rep: Reputation: 0
It works fine, thanks !

But I've two others questions :
- It works with virtual interfaces (like with eth0:1 par example) ?
- Is there a method to restrict the uplink and the downlink together at 128kbit ? It works well for the down, but not for the up.

Thank you again

EDIT : I have readed this article which says
Quote:
For traffic accepted on an interface, the ingress qdisc is traversed. With its limited utility, it allows no child class to be created, and only exists as an object onto which a filter can be attached. For practical purposes, the ingress qdisc is merely a convenient object onto which to attach a policer to limit the amount of traffic accepted on a network interface.
If I understand correctly, the police on ingress limits the uplink too ? So I made a mistake in my uplink tests ?

Last edited by MathX; 10-11-2010 at 04:45 PM.
 
Old 10-12-2010, 08:44 AM   #4
rayfordj
Member
 
Registered: Feb 2008
Location: Texas
Distribution: Fedora, RHEL, CentOS
Posts: 488

Rep: Reputation: 78
Quote:
Originally Posted by MathX View Post
- It works with virtual interfaces (like with eth0:1 par example) ?
I do not know.

Quote:
Originally Posted by MathX View Post
- Is there a method to restrict the uplink and the downlink together at 128kbit ?
No, but you may limit them separately at the same rate. Personally, I don't use iptables' MARK. For a quick test you could try something like...

Code:
# clear it
/sbin/tc qdisc del dev eth0 root
# shape it
/sbin/tc qdisc add dev eth0 root handle 1: htb default 1
/sbin/tc class add dev eth0 parent 1: classid 1:1 htb rate 128kbit \
     quantum 3000 burst 15k
/sbin/tc qdisc add dev eth0 parent 1:1 handle 10: sfq perturb 10


Quote:
Originally Posted by MathX View Post
If I understand correctly, the police on ingress limits the uplink too ? So I made a mistake in my uplink tests ?
police on ingress limits the incoming (download) on that interface. shaping on egress is what will limit the outgoing (upload) on that interface.
 
1 members found this post helpful.
Old 10-12-2010, 02:41 PM   #5
MathX
LQ Newbie
 
Registered: Oct 2010
Distribution: archlinux
Posts: 3

Original Poster
Rep: Reputation: 0
Works fine too, thanks !

Last edited by MathX; 10-12-2010 at 02:46 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bandwidth Limit for the Hosts on the Network !! wanas Linux - Networking 4 10-01-2010 12:14 PM
Network bandwidth limiting - how to limit the whole network sKAApGIF Linux - Networking 2 01-07-2010 04:12 PM
Limit the speed of a network interface. exodist Linux - Networking 8 08-15-2008 10:37 PM
Vsftpd - how to limit download bandwidth but unlimited upload bandwidth? mpls mikeg Linux - Software 3 08-13-2005 01:52 PM
limiting bandwidth on a specific network interface. Passive Linux - Networking 3 05-01-2002 04:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration