Windows Server How-To
How To Use Windows Server as a Network Router
Link up virtual machines without the need of physical hardware.
Recently a client asked me to write a whitepaper about IP address management. At first the assignment seemed completely routine. But as I began looking at the details I realized that I was going to have to deploy dozens of Hyper-V virtual machines and that those virtual machines would need to span several different subnets. Since I needed all these VMs to be able to talk to one another and to be able to access the Internet, I was going to need to set up a router. Because the entire environment was virtual I decided to set up a Windows Server 2012 R2 virtual server to act as a router rather than using a physical server.
Since I needed my lab environment to mimic a physical network, I started out by creating a series of Hyper-V switches. As you may know, Hyper-V allows you to create external, internal or private switches. I created three of my switches as internal, meaning that those switches have no access to the physical network. Internal switches can only be used for communications between VMs. A fourth Hyper-V switch was configured as external. External switches have access to the physical network. I am using this virtual switch to provide Internet access to my virtual machines. You can see the virtual switch setup in Figure 1.
Once all of my virtual switches were in place and I had created a few VMs and linked them to the appropriate virtual switch, it was time to create a router. As previously stated, my router was a Hyper-V virtual machine running Windows Server 2012 R2.
In order to be able to route traffic between the various subnets, the router needs access to all of the virtual switches. I started out by creating a bunch of virtual network adapters and linking each one to a different virtual switch. When I booted the VM however, I realized that it was difficult to tell which virtual network adapter was connected to which virtual switch. This was a bit of a problem because I wanted to assign a static IP address to each virtual network adapter and I had to make sure to use an address within the appropriate subnet.
Although it was a little bit of work, I shut down the VM and removed all but one of the virtual network adapters. I then booted the VM and assigned an address that corresponded to the range used by the other VMs sharing the virtual switch. At that point, I shut down the VM and added another virtual network adapter. I then booted the VM and assigned an address based on the virtual switch to which this adapter was connected. I repeated the process until all of my virtual network adapters were in place. You can see the virtual network adapters in Figure 2.
The next step in the process was to install the Routing and Remote Access Service onto my VM that would be acting as a router. This was accomplished by opening the Server Manager and installing the Remote Access role. The Remote Access Role is made up of three different role services and the only one of these role services that needed to be installed was the Routing service. Selecting the Routing service causes the DirectAccess and VPN (RAS) role service to be selected and also requires a number of different role specific features to be installed.
Once all of the required components had been installed, it was time to configure the server to act as a router. This was a relatively simple task. I launched the Routing and Remote Access console by selecting the Routing and Remote Access option from the Server Manager's Tools menu. When the console opened, I right-clicked on the name of my server and selected the Configure and Enable Routing and Remote Access option. This caused Windows to launch the Routing and Remote Access Server Setup Wizard.
I clicked Next to bypass the wizard's Welcome screen and was then taken to the screen shown in Figure 3, where I selected the Custom Configuration option.
Clicking Next caused Windows to display a list of components that could be enabled. I chose the LAN Routing option, shown in Figure 4. In many cases the NAT option will also need to be selected in order for the network endpoints to be able to access the Internet. I then clicked Next, followed by Finish to complete the wizard. Upon completion, Windows displays a dialog box containing a Start Service button that you must click in order to enable routing.
As you can see, Windows Server can be used as a router in situations in which purchasing a hardware router is not a practical option. Using the Windows Server router can be especially effective in virtualized environments in which virtual machines reside on a number of different virtual networks.
Brien Posey is a 16-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site at.