Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Ubuntu 12.10 and looking for a way to shape network traffic based on the IP address. I have a LAN, lets say from 192.168.1.2 - 192.168.1.254. The server is at 192.168.1.1. All IPs should have the maximum possible network speeds (all ports, but Samba is the actual culprit). The moment a specific IP or IP range (eg: 192.168.1.100) connects, the full speed should be given to that IP, all other IPs speed should be reduced to the minimum. Once the IPs traffic is finished, the rest of the connected IPs' speed should be restored.

I pretty much have a server and if my own PC connects to it, I want full speed. Only if I'm not using the server, the rest should have full access.

I've found some solutions online with tc, but they all limit specific IPs with a certain speed. I however want all people to have the max speed, except if a certain IP is connected. So basically my IP should have the highest priority and the rest the lowest priority.

Can anyone help me out with a script or maybe a program that already exists?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

tc is the way to go. The trick is to prioritize traffic without limiting it.

http://www.lartc.org/howto/lartc.qdisc.classful.html, section 9.5.3 "The PRIO qdisc"; by default it creates 3 queues but you can ignore the 3rd one. The simplest approach would be:

Create the queue disciplines (qdisc)

tc qdisc add dev eth0 root handle 1: prio

tc qdisc add dev eth0 parent 1:1 handle 10: sfq
tc qdisc add dev eth0 parent 1:2 handle 20: sfq
tc qdisc add dev eth0 parent 1:3 handle 30: sfq

They all have the same queue algorithm; then assign your servers (IP 192.168.1.0-127 in this case) to handle 10: and the rest to 20: :

tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.0/25 flowid 10:
tc filter add dev eth0 protocol ip parent 1:2 prio 2 flowid 20:

(Disclaimer: it's a been a while since I touched this stuff, you may have to experiment with the values after parent and flowid)

Using ranges that are powers of 2 is a lot easier than decimal limits. The /25 after the IP address ignores the last 7 bits of the IP address, hence a range from 0 to 127. Use a /26 to limit the range to 0..63, if necessary.

On the same page, Hierarchical Token Bucket is discussed, which is a more finegrained way of distributing bandwidth. The trick is to create to 2 classes with a skewed bandwidth ratio, say 1:10 (100 mbit vs 1000 mbit). This will leave some bandwidth to your other clients.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.