Using a virtual router for your lab and test environment
12/13/2012 9:29 AM
When build lab and proof-of-concept solutions in a virtual environment it's very useful to also have a virtual router to enable multiple networks to connect, and to simulate a larger environments.
Depending on virtualization platform you can use built-in network configurations to route, and bandwidth-limit network traffic. In this article you learn about creating a virtual router that works with all modern virtual platforms. You have two different options in this article:
- Option 1 is using a Windows Server 2012 based router.
- Option 2 is using a Linux (Vyatta) based router.
The step-by-step guides in this article configure a virtual router for the fictive ViaMonstra network. For a full IP plan for ViaMonstra network, see http://viamonstra.com/?page_id=25
ViaMonstra has the following three local networks:
New York: 192.168.1.0/24
In addition ViaMonstra also have Internet access. In a real world (physical) network you would have many routers, but in a virtual environment where all virtual machines are running on the same host you only need one router. This also means that in this guide there are three internal virtual networks (virtual switches in Hyper-V), and one external. In the step-by-step guides I assume you have created the following virtual networks:
Create the following virtual networks (virtual switches)
- External (connected to physical network adapter of your host)
- New York (Internal network)
- Stockholm (Internal network)
- Liverpool (Internal network)
Create a virtual machine named GW01 with four network adapters (1 GB RAM and 60 GB disk) and use following network configuration
- Connect network adapter #1 to the External virtual network
- Connect network adapter #2 to the New York virtual network
- Connect network adapter #3 to the Stockholm virtual network
- Connect network adapter #4 to the Liverpool virtual network
On the virtual machine settings, make a note of the Mac Address for each network adapter. In my setup I had the following:
- Adapter #1 (External): 00:15:5D:83:40:21
- Adapter #2 (New York): 00:15:5D:83:40:22
- Adapter #3 (Stockholm): 00:15:5D:83:40:23
- Adapter #4 (Liverpool): 00:15:5D:83:40:24
GW01 created with four network adapters.
Option 1 - Using a Windows Server 2012 VM with Routing and Remote Access.
- Install Windows Server 2012 on GW01 and set the computer name to GW01.
Using Network Connections, configure the networks to the following (use the Mac Address noted earlier to find correct adapter):
- Name: Internet
- IP Address: DHCP
- Name: New York (192.168.1.0)
- IP Address: 192.168.1.1/24
- Name: Stockholm (192.168.2.0)
- IP Address: 192.168.2.1/24
- Name: Liverpool (192.168.3.0)
- IP Address: 192.168.3.1/24
Networks configured in Network Connections.
- Using Server Manager, add the Remote Access role. Accept the default settings, but on the Role services page also select Routing.
- Using Routing and Remote Access, right-click GW01 (local), and select Configure and Enable Routing and Remote Access.
Use the following settings for the Configure and Enable Routing and Remote Access Setup Wizard:
- Network address translation (NAT)
NAT Internet Connection:
Select the Internet network interface.
Selecting the Internet network interface.
- Network Selection:
- Select the New York network
Name and Address Translation Services
- I will set up name and address services later
Option 2 - Using the Vyatta 6.5 Open Source Router.
You can download the free version of Vyatta Open Source Router fon vyatta.org (http://www.vyatta.org/downloads) and a community fork (VyOS) on http://vyos.net/wiki/Main_Page. Note that the free version does not come with a UI for configuring the router, only command line and config files.
Credit goes to Stefan Stranger for writing the initial guide (for version 4.0).
- If you want you can reduce the GW01 virtual machine memory to 128 MB. 1 GB is really overkill for Vyatta J
- As far as disk goes you can run Vyatta on 1 GB drive (Vyatta recommends 2 GB for production), but I normally keep the 60 GB disk anyway.
- Install Vyatta 6.5 by booting the GW01 virtual machine on the vyatta-livecd-virt_VC6.5R1_i386.iso file
Booting the GW01 virtual machine on the vyatta-livecd-virt_VC6.5R1_i386.iso file
- Log on as vyatta, using the vyatta password.
Start the installation by running the following command (was install-system in earlier versions)
- install system
- The setup options are quite self-explanatory, but say No to create a RAID volume (Vyatta thinks you have two drives, when you really only have one).
- Once setup is completed, shutdown the VM, eject the CD, and restart the GW01 virtual machine.
The command for shutdown is: poweroff
- Note: You did shutdown the VM and eject the CD, right? (otherwise any changes made later will be lost)
Login and configure the network adapters by running the following commands:
- set interfaces ethernet eth0 address dhcp
- set interfaces ethernet eth1 address 192.168.1.1/24
- set interfaces ethernet eth2 address 192.168.2.1/24
- set interfaces ethernet eth3 address 192.168.3.1/24
Now you can review the network adapters by running the following commands
- sudo ifconfig | more
- Show interfaces Ethernet
Configure the NAT configuration by running the following commands:
- set nat source rule 10 outbound-interface eth0
- set nat source rule 10 source address 192.168.1.0/24
- set nat source rule 10 translation address masquerade
Happy Routing / Johan