1

I'm going to simulate a network latency on three different ports of local host by using tc (traffic control for Linux) commands. I run the following code:

!/bin/bash
tc qdisc add dev lo root handle 1: htb 
tc class add dev lo parent 1: classid 1:1 htb rate 1000Mbps
#1:
tc class add dev lo parent 1:1 classid 1:2 htb rate 1000Mbps
tc qdisc add dev lo handle 2: parent 1:2 netem delay 500ms
tc filter add dev lo pref 2 protocol ip u32 match ip dport 7011 0xffff flowid 1:2
#2:
tc class add dev lo parent 1:1 classid 1:3 htb rate 1000Mbps
tc qdisc add dev lo handle 3: parent 1:3 netem delay 1000ms
tc filter add dev lo pref 3 protocol ip u32 match ip dport 7011 0xffff flowid 1:3
#3:
tc class add dev lo parent 1:1 classid 1:4 htb rate 1000Mbps
tc qdisc add dev lo handle 4: parent 1:4 netem delay 100ms
tc filter add dev lo pref 4 protocol ip u32 match ip dport 7012 0xffff flowid 1:4

However, it doesn't appear to be any delay caused by these filters. I even tried to use sport, but also nothing happened. By the way, I can add delay to local host (127.0.0.1) without filters. But when I add filters for ports it doesn't work.

I could not understand where I'm going wrong.

  • Appears to be working. Two things to check: be sure you're using eg 127.0.0.1 not localhost which might become ::1 (ie IPv6 not IPv4). Also netem works on output only, so the delay is one-way: here queries are delayed, not answers. – A.B Jan 5 at 10:22

Your Answer

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

Browse other questions tagged or ask your own question.