WAN Emulation using WANEm

Let's say that we have to test some application, that can be a web application, a TCP/IP application or any other kind of connection, in an environment that simulates the WAN.

First of all we have to design the network environment.

Most times, I use a Hyper-V environment to do setup the machines and networks needed for the test.

Lets say that we've already setup a server and a client as virtual machines with names SERVERVM and CLIENTVM respectively. Each has one virtual network adapter.

Now we need to create two new virtual networks, let's name them SERVERNET and CLIENTNET. We connect the client's adapter to the CLIENTNET and server's adapter to SERVERNET.

The next thing we have to do is create the WAN emulation virtual machine. I prefer to user the WANEm emulator. So grab a copy of the ISO and create a new VM. If you are using Hyper-V, remove the Virtual Network Adapter from the VM and add two new Legacy Network Adapters. Connect the adapters to the networks we created earlier. In order not to get confused with the networks and the adapters, write down the MAC addresses from the hypervisor.

When the VM finishes booting, you will have to configure the IP addresses for the interfaces. I always use static addresses here. Usually the eth0 adapter is the first adapter in the list of Hyper-V. You can check it though with ifconfig and the MAC addresses you got earlier. An other way to check is to connect only one network adapter and ping the emulator from another machine.

After you have setup the VM with the IP addresses, you have to configure the routing on the SERVERVM and CLIENTVM. Depending on your network set you may not have to do this. I on the other hand, prefer to use different subnets for the two networks. In that case, you may use the emulator IPs as gateways on the other vms or just add routes on them.

If you can ping the emulator from both vms and one vm from the other, you're all set. The next thing to do is configure the emulation rules.

You can configure these by opening the website of the emulator which is http://<emulatorip>/WANEm. Notice that the "WANEm" part is case sensitive. You may then apply emulation rules on each adapter (You have these written down, right?).

I use the above frequently to do POCs and troubleshoot may things and one problem that comes up is the connection to the internet. In order to connect the networks to the internet we have to connect the emulator to a network with internet access and setup NAT for the other networks.

To do this I add a new Legacy Virtual Network Adapter and connect it to the local ethernet. I assign IP addresses just like we did before and then setup routing on the emulator just like in any other linux.

In order to setup NAT you may use the following commands:
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth1 -j ACCEPT

where eth0 is the adapter that is connected to the network with internet access and eth1 and eth2 are the adapters connected to the other networks.

A very useful article on this is this.

One last thing, you have to use the emulator as default gateway on the machines that are connected to the private networks for NAT to work. If you want to access these networks from other machines that do not have the emulator as default gateway, just add routes on them.

Popular posts from this blog

Syslog Message Collection for OMS from sources that do not support the agent

How to Configure Message Forwarding on a Mailbox Level

IIS Client Certificate Revocation Check Disable