When designing a virtual test lab you will most probably think of having more than one network so you can test technologies more accurately. This part is about showing you one of the possible methods to make devices from different networks talk to each other, as by default 2 networks cannot pass traffic from one to the other without help from a specialized device called a router. The router’s job is to route packets from one of it’s interfaces to another one that it knows leads to the destination network.
Before beginning this part please make sure that you have at leats 2 private networks, a network that is connected to your physical network adapter and that the adapter is connected to the internet.
Let’s see what a router is and how to configure a virtual machine to act as one.
What is a router
Networked devices like computers, printers and others don’t know how to send data to other LANs other than their own; this is the way networks work. In order for a computer to communicate with another one from a different network it would need help to get the data out of its network to the destination one. Linking 2 or more networks together is done with a specialized device called a router. It has 2 or more network ports with a different network connected to each of them. When the router receives a packet on one of its ports it analyzes the destination IP address and based on that establishes on which network port to forward it in order to reach the destination device. More of such devices can be connected to each other to form more complex links between networks (for example the internet).
As this is not a networking course we will be using one router to connect al of our networks in Hyper-V because the actual functionality is the same. The actual device will be a virtual machine installed with CentOS which is a Linux distribution. Yes you read right: we will be using Linux on the aboutwinserver.com blog.
In this example I will be connecting only 2 networks (the 2 ones created in Part 4) and will be using a 3rd Hyper-V switch connected to the internet to install some tools on CentOS. The NIC with the internet connection will be deleted from the VM after everything is finished.
Here is how my Hyper-V switch manager looks like with the 3 switches created:
On each of the 2 private networks we will be able to connect VMs using their NICs. The machine that will host the router will have in this case 2 network adapters each connected to one of the private switches. Like this it will be able to forward traffic from one to the other when needed. The logical topology for this setup can be seen below:
From this image we deduce that the router VM has a connection to both virtual switches and every packet that needs to get from 192.168.1.0 to 192.168.2.0 or viceversa will pass through it. More switches can be added to the virtual machine and the functionality will remain the same. Here is how this topology looks at the VM level:
I did not include the third NIC with the internet access in these diagrams because it is temporary and needed just to make configuring the router more easy. Let’s begin with installing the router virtual machine.
Installing the router
To begin this step you need to first download CentOS. The easiest way to do this is search on Google for “Download CentOS” and the first site should be the CentOS official site. I recommend getting the Minimal ISO because it saves download time. The normal ISO just contains tools that we do not need in this case.
- Name: Router
- Generation: 1
- Memory: 1024 (Dynamic enabled)
- Network: Priv – 192.168.1.0 (or one of your private switches; do not use the External switch now)
- Virtual HDD: 8 GB (the rest configure as you like or let the defaults)
- Install operating system: Select the installation from the CentOS ISO file
After creating the virtual machine we need to change some settings:
- In Memory: Set Maximum RAM to 1024
- Add a Network Adapter and connect it to Priv – 192.168.2.0 or whatever name your other private Hyper-V switch has (repeat this step if you have more private switches)
- Add a Network Adapter and connect it to Internet (the External switch)
Next comes the installation of the OS. Turn on the virtual machine and let’s begin.
Select Install CentOS 7 and press Enter. Wait for the GUI to load.
Select your preffered language and click continue in the lower right corner.
Now click on Installation Destination and in the next screen press Done in the upper left corner.
Another thing to set up is networking. Go to Network & Host Name and enable all network cards. After all have the ON switch set you can press Done.
The Internet enabled NIC should already receive an IP address from your home router after setting it to ON.
Now you can press on Begin Installation.
A mandatory task for OS installation completion is to set a password for the root user. Click on ROOT PASSWORD and set one on the next screen.
After the installation is done press Reboot.
Configuring the router
After reboot you have to login. For the localhost login enter root, press Enter and enter the root password. Now you are in.
Next we need to install a text editor from the internet. Use the following command to download and install the nano editor:
yum -y install nano
At the end you should see this:
Next we will enable the IP forward feature which actually does the routing job. This is done by adding a line in a text file.
In the text file write: net.ipv4.ip_forward=1 and after that press CTRL+X, Y and ENTER. The first part is done.
Next comes the configuration of the NICs. To see a list of all adapters run the command:
ip addr show
We can see that the NICs are named eth<number> with the numbers being assigned in the order the interfaces were added in Hyper-V. So in my case eth0 is associated to Priv – 192.168.1.0 and eth1 with Priv- – 192.168.2.0. If you want more networks and added them in the beggining, they will be shown here. The last one is the Internet NIC which will be removed.
Each network card has a configuration file which has to be edited with the IP address, network mask and other info. Let’s see what the eth0 file has to look like. First open the configuration file with nano:
Make sure you edit the file so it looks like the picture below. Put what IP and NETMASK you need and delete what lines are not used.
Save the file and repeat the procedure for eth1 and any other network card you use. I will do this task for eth1 and set the 192.168.2.254 IP on it for the second network.
After setting the IPs we need to restart the network service so the settings can take effect. Do this by running:
systemctl restart network
What is left to be done is the removal of the NIC with access to the internet (not mandatory). Just shut down the VM and from the NIC settings remove it.
Now turn on the virtual machine again and you have yourself a router for the test lab.
This was all for the Build a virtual test lab series. With the router in place you are free to connect your VMs as you need and test different technologies and scenarios.