4

How to delay some localhost traffic? (the computer is a VM, but hopefully that won't matter)

The following creates a new interface and tries to apply tc to it:

ifconfig lo:1 127.0.10.10 netmask 255.0.0.0 up
tc qdisk add dev lo:1 root netem delay 200ms

This also limited traffic for the normal loopback interface:

$ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=400 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=400 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=400 ms

The same delay appeared for 127.0.10.10 and when pinging the device's IP address.

How to delay only a part of localhost traffic? (f.ex. to a specific IP address?)

UPDATE: Removing the tc qdisk, creating a new interface using ip link add link lo name lo30 type dummy and setting tc on it did not delay any traffic. Seems like all traffic to the local computer is automatically routed to lo.

3
  • 1
    Do you absolutely require that it is for the lo interface and the 127/8 subnet? The former may be special, and the latter may certainly be special. You could set up a small subnet carved out of RFC 1918 space with no external routing to achieve pretty much the exact same effect, but if you need to use 127/8 that's obviously not an option.
    – user
    Commented Aug 11, 2017 at 8:31
  • @MichaelKjörling: Any local address would be ok. The above usage of tc also affected the local IP. Is that avoidable?
    – M K
    Commented Aug 11, 2017 at 9:09
  • For simulating delays on your traffic, you should have a look at the NetEm framework (see man tc-netem).
    – Qeole
    Commented Dec 4, 2017 at 23:39

1 Answer 1

2

tc qdisc can control any ip and ports traffic:

sudo tc qdisc add dev lo root handle 1: prio bands 4
sudo tc qdisc add dev lo parent 1:4 handle 40: netem delay 200ms
sudo tc filter add dev lo parent 1: protocol ip prio 4 basic match "cmp(u8 at 16 layer network eq 127)
                            and cmp(u8 at 17 layer network eq 0)
                            and cmp(u8 at 18 layer network eq 0)
                            and cmp(u8 at 19 layer network eq 1)" flowid 1:4
1
  • Could you please give some explanation to the command? (also per community guidance)
    – renyuneyun
    Commented Sep 20, 2022 at 9:54

You must log in to answer this question.

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