I'm trying to simulate different network condition based on factors such as latency, bandwidth and so on. I found that Netem is the best way to simulate different network condition. So my desired network setup would be as below.

enter image description here

So Netem box should have two NIC and it must bride two ethernet connection(eth0 and eth1). I have few questions need to clarify.

1) Can we use a cross cable connection with the server to Netem box? or is it a different VLAN. 2) As per my understanding,the client will access eth0 and Netem box will forward all the packets to eth1 and same for the server to Netem box communication. So I want to clarify whether the client can directly connect to server IP(Same network) or client only talks to Netem box Ip, so that it will forward packets to the server?


I'm assuming you are referring to this tutorial.

With linux bridge, you are going to use your netem box as a switch, without even an ip but for management. This way, the client is going to communicate straight to your server.

As long as you don't specify subinterfaces (eg eth0.101), your switch will forward all vlan tagged traffic as-is.


I actually just had to figure this out a few weeks ago. I did it using the netem box as a router, but I don't think that actually matters much.

Basically, the netem function that you want (there's more than just that) will tell your nic to hold onto the traffic for some user-determined amount of time. It is not concerned with how the traffic gets to the nic, which is why I think that you can use a bridge as you described.

One thing I did not understand from your question was which direction you wanted to delay the traffic in, or both directions. It doesn't really matter that much, but you will have to issue the netem command at least once for each "outbound" nic - that is, for each direction that traffic is flowing. By default, netem will only affect outbound traffic, not inbound.

That said, here is the command that you want:

tc qdisc add dev eth0 root handle 1:0 netem delay 25ms

That command will introduce a delay of 25 ms to all packets leaving the host through eth0. You can, of course, adjust the eth(x) number to the appropriate nic and the 25 ms to your desired delay. There's a gotcha, though: note in the command that there is NO SPACE between the "25" and the "ms". That's important; it will error out if you put the space in.

There's actually more you can do with delay, though. You can put in a second value, like this:

tc qdisc add dev eth0 root handle 1:0 netem delay 25ms 10ms

That will delay the traffic by an average of 25 ms, but each packet will actually be delayed by a random number of ms between 15ms and 35ms (25 ms +/- 10 ms)

To "turn off" netem, issue the same command, but change "add" to "del".

There's lots more you can do with netem too, including packet reordering, packet dropping, packet corruption, and packet duplication, all of it either random or actually correlated to previous packets. Lots more than I can go into here. For more info, check out www.linuxfoundation.org/collaborate/workgroups/networking/netem or the man page for netem, "man netem".

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.