4

I'm having an issue with a bandwidth script that I've been using for a while to limit the outgoing bandwidth on a port.

It worked fine at the beginning until I wanted to change the outgoing port speed. I switched it to a higher number ( 200mbit to 400mbit ) and I restarted the script. For some reason the new bandwidth limit didn't take and the old limit is still there. I have the script set-up as an init service. This is what part of the code looks like.

# Interface
interface=eth0

# Define the upload, follow units can be
upload_limit=400mbit

start() {
    # Start the tc configuration and set all packets default to 10
    /sbin/tc qdisc add dev $interface root handle 1:0 htb default 10

    # Set default speed for all packets
    /sbin/tc class add dev $interface parent 1:0 classid 1:10 htb rate 1000mbit ceil 1000mbit prio 0
    # Set speeds for packets marked with 20
    /sbin/tc class add dev $interface parent 1:0 classid 1:20 htb rate $upload_limit ceil $upload_limit prio 0

    # Mark packets for port 182 to 20 so that tc can handle the traffic.
    /sbin/iptables -A OUTPUT -t mangle -p tcp --sport 182 -j MARK --set-mark 20
    /sbin/service iptables save

    # Assign it to appropriate qdisc
    tc filter add dev $interface parent 1:0 prio 0 protocol ip handle 20 fw flowid 1:20
}

stop() {
    /sbin/tc qdisc del dev $interface root
}

Can anyone offer me any suggestions?

1

IMHO, the reason for the old rule still being in place is that the iptables rule that causes "the magic" is still there, as you have a line that adds it and no line to remove it. Check your iptables rules file. You should have a bunch of lines similar to the old version (port) of "iptables -D OUTPUT -t mangle -p tcp --sport 182 -j MARK --set-mark 20". (as everytime the script is executed, you create a new one and save it afterwards)

Try to put an Iptables command on stop() function to clean the mangle table rules. Something like this: /sbin/iptables -D OUTPUT -t mangle -p tcp --sport 182 -j MARK --set-mark 20 /sbin/service iptables save

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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