Score:0

Traffic shaping and artificial latency per IP in a LAN network using tc/netem

za flag

for the last few days I have been trying to setup traffic shaping and artificial latency in a local network. Currently I have an Ubuntu 20.04 PC with 2 NICs, where one is connected to the company network and the other shares the connection with an arbitrary number of clients(all with static IPs) through a switch. Currently I have gotten as far as successfully sharing the connection with the clients, introducing latency and shaping the download speeds using netem. Here comes the problem, I can't seem to shape the upload traffic the same way as download traffic. What I have tried so far:

  • sudo tc qdisc add dev enp4s0 root handle 1: prio
  • sudo tc filter add dev enp4s0 protocol ip parent 1: prio 1 u32 match ip dst {CLIENT IP} flowid 1:2 (down)
  • sudo tc filter add dev enp4s0 protocol ip parent 1: prio 1 u32 match ip src {CLIENT IP} flowid 1:2(up, doesn't seem to work)
  • sudo tc qdisc add dev enp4s0 parent 1:2 handle 20: netem delay 50ms rate 100mbit

Furthermore, while I was looking for solutions I found here that the default number of bands is 3, so this means that by default I can have 3 netem qdiscs to shape traffic with. Apparently if I change the number of bands in the first line using the argument bands X I need to edit the priomap too, but after doing it, it seems that everything works just like before. I sadly can't seem to find an answer as to why this works like that.

Is my approach to the problem correct? Would this be scalable? I don't think I will ever need to account for more than 20 clients at once so I assume it can be automated pretty well with some scripts later on. On the other hand is there a better way to achieve what I need, that I'm not aware of. I am very new to this topic so any advice is appreciated, thank you in advance.

A.B avatar
cl flag
A.B
check this UL SE Q/A: https://unix.stackexchange.com/questions/421462/simulation-of-packet-loss-on-bridged-interface-using-netem .
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.