Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 03-03-2015, 09:42 AM   #1
LQ Newbie
Registered: Mar 2015
Distribution: Ubuntu
Posts: 2

Rep: Reputation: Disabled
Setting up a virtual (local) network with artificial latencies for testing purposes


In order to test an application I am trying to set up some sort of virtual network on my machine. Essentially I will have several programs running and would like them to be able to communicate with each other using TCP given some IP address and port. For testing purposes I would like all of this to happen on a single machine and with latencies that I can control.

I've found out that latencies can be added to interfaces quite easily with the 'tc' commands (so e.g.: 'tc qdisc add dev eth0 root netem delay 100ms'). If I had only two parties in this scenario I could quite easily add some delay to the loopback interface and simple have my applications listen on e.g. and

However, I would like to have several applications sending requests back and forth, all of them with different latencies on their respective connections between one another. So I thought I could get myself some virtual interfaces (essentially additional loopback ones) to then assign those different IP addresses and have applications listen on those respective addresses (and whatever ports are currently convenient). In theory I could then use the tc command to adjust latencies for those interfaces.

Now I am having trouble getting this to work in reality. I've tried various things, one of the more promising ones (I thought) was creating tun/tap interfaces (in the simplest case with 'vde_switch -t tap0 -t tap1 ...'), assigning those an IP address each and then adding the latency. However, when I ping any of those addresses, the request seems to go via the lo interface - not the tun/tap ones. This could probably be fixed with some iptables rules, although I haven't gotten that far yet. If I try specifying the interface with the -I option of ping and try to ping a different one of my tun/tap interfaces (so say I ping tap1 via tap0), I only get "Destination Host Unreachable".

Am I approaching this the right way? This seems like something that shouldn't be too difficult. How can I set up such a virtual network?

I hope I am making some sense!

Many thanks in advance!

Old 03-04-2015, 02:25 PM   #2
Senior Member
Registered: Apr 2009
Posts: 1,868

Rep: Reputation: 162Reputation: 162
The tun/tap isn't real interface, just simulating network device in different layer. You can try alias interface to get different IP.

Assuming that your eth0 IP is and you would like to create an alias eth0:0 with IP Type the following command:

sudo ifconfig eth0:0 up
Old 04-21-2015, 05:27 AM   #3
LQ Newbie
Registered: Mar 2015
Distribution: Ubuntu
Posts: 2

Original Poster
Rep: Reputation: Disabled

Thank you nini09 for your response and sorry for the long silence!

Unfortunately I couldn't get different latencies for eth0:0, eth0:1, etc. to work - they all had the same latency as eth0.

However, I did find a solution in the end so I'll share it in case someone else has a similar problem. It's a bit of a workaround but it does the job - if anyone comes up with something more elegant (particularly without requiring a VM), let me know.

This uses VMware Workstation (note that Player is not sufficient). I used Ubuntu Desktop and Ubuntu Server as host and guest OS, respectively.

Workstation has a 'virtual network editor' (separate application packaged with Workstation). With that you can create additional virtual network interfaces and it turns out that you can assign virtual latencies to those independently. Create additional vmnetX interfaces as you need (mine were of type host-only) and you can add new network adaptors to your VM, manually specifying the corresponding network interfaces. If you're using linux you probably also need to add the new adaptors to /etc/network/interfaces in the guest OS.

Now you should have several different interfaces/networks available that are shared between host and guest. Introduce latency to those interfaces by using something like the following (google this command for more details, this is just one example):
sudo tc qdisc add dev vmnet1 root netem delay 20ms
I ended up introducing the delay in the guest OS (using the eth0, eth1, ... interfaces) instead of the host, as it is shown in the example above. I don't think it should make a massive difference, though.

Be aware that this is only a quick & dirty and not very generic description of how I got it to work. If you want to do something similar you might have to change a couple of details.

Last edited by Jocbe; 04-21-2015 at 05:29 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [ANNOUNCE] eudev for Slackware 14.1 is available for testing purposes Didier Spaier Slackware 90 11-04-2014 08:03 PM
immutable ip address for testing purposes? stateless Linux - Networking 3 02-13-2014 02:34 PM
duplicating http-traffic for testing purposes pretos Linux - Server 1 01-20-2011 05:58 AM
Testing web server on local network with ports... how to use with hosts file? raisinlove Linux - Server 4 06-08-2009 01:39 PM
virtual host for local testing tr3s Red Hat 1 09-02-2003 12:50 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:48 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration