1

I need to simulate a traffic slow down to a certain service. That means I need to slow connection on a certain port. I have this script that introduces a delay to a certain IP on all ports, but other services run on that system that I cannot slow down.

echo "simulating slowdown infrstructure on interface $DEV to IP:$IP for port:$PORT";
tc qdisc del dev $DEV root
tc qdisc add dev $DEV handle 1: root htb
tc class add dev $DEV parent 1: classid 1:15 htb rate 1000Mbps
tc qdisc add dev $DEV parent 1:15 handle 11 netem delay 4000ms 2000ms distribution normal
tc filter add dev $DEV parent 1:0 prio 1 protocol ip handle 11 fw flowid 1:15
iptables -A OUTPUT -t mangle -d "$IP" -j MARK --set-mark 11

I can't really figure out what the last line here does because it seems to work without it.

((the undo script is here:))

iptables -D OUTPUT -t mangle -d "$IP" -j MARK --set-mark 11
tc qdisc del dev $DEV root
4
  • 1
    It appears to be setting the DSCP value, which is meaningless unless you have something in the path that recognizes the DSCP and has a rule set up to treat the packets based on the value.
    – Ron Maupin
    Jul 13, 2017 at 20:50
  • "It", you're referring to the iptables line? yes, well, it was supose to mark will "11" and the line above it was supposed to apply the rule to all messages with that mark. I think. But tc and iptables are so arcane and the man pages are useless. I can't figure out what any of this means for sure. Edit: I don't know precisely what this script actually does, I found it on the network. But the goal is stated above. Delay traffic to given IP on given Port, exclusively.
    – GreenFox
    Jul 13, 2017 at 20:55
  • You need to look at the HTB manual. luxik.cdi.cz/~devik/qos/htb/manual/userg.htm tc man page will be almost useless to you.
    – hookenz
    Jul 13, 2017 at 22:38

1 Answer 1

1

The last line catch all packets to the specific IP (on all ports), and add a mark on it (inside the kernel only).

Every packets with the mark will be slow down. You just need to specify a destination port in this rule and it should be fine :

iptables -A OUTPUT -t mangle -d "$IP" -p tcp -- dport ${Port} -j MARK --set-mark 11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .