My job is almost completely reliant upon my ability to perform work in lab of virtual machines. Almost every action plan I write is tested locally. When I need to troubleshoot an issue for a client one of the most common first steps I'll perform is attempting to recreate the issue in a virtual environment so I can work on it there without the risk of impacting client data. I believe that having a place to test and grow your skills is an absolute necessity for anyone working in the IT field today regardless of your specialization, even if you're an IT generalist. But every now and then I hear about individuals who have issues with their virtual machines or with the virtual environment provided by their employer, so I figured this was a good time to share my method of creating a virtual lab. More specifically, one that allows you to do virtual work on a commodity laptop, one that won't break down if you lose connectivity, one that won't be interfered with if you connect to a restrictive VPN. We're going to build 2 CentOS 6 virtual machines on a virtual NAT network using Oracle VirtualBox. Before you begin, all you're going to need is the installer for VirtualBox for your host machine and an ISO of CentOS 6 (64 bit). The first thing we're going to do once VirtualBox is installed is setup a NAT network . The most common application of NAT networking is likely the usage of home broadband internet 'routers'. This takes the single IP you get from your ISP and allows multiple machines to interface with it. We're going to use this concept to build a NAT network in your virtual environment that your virtual machines will connect to. By internalizing the network structure I will be able to interact with my virtual machines and allow my virtual machines to interact with one another regardless of whether my PC is connected to a network or not. This can be really handy if you're having a networking problem, if you're traveling, or if you're inheriting a restrictive networking policy from a client's soft VPN connection, etc. Regardless of what happens, if you can turn on your machine you can work in your lab of virtual machines.
SETTING UP YOUR NAT NETWORK
For this tutorial I've installed VirtualBox version 5.0.4 on my local machine. A Nat Network is already setup by default, but you can verify this by going to File -> Preferences -> Network (on the left menu bar). On the Nat Networks tab you will likely see an network called 'LocalNat'. You can click on the edit button (the little screwdriver icon) to see the network configuration. If you don't have a Nat Network by default, create one by hitting the icon that looks like a network card with a ‘+’ symbol over it, then select it and click the edit button.![PSVMImage1](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage2](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
CREATING THE FIRST VIRTUAL MACHINE
The network is setup and we're ready to create our first virtual machine! Click on new and this will take you to the 'Create Virtual Machine' window. The first option will be to name your virtual machine. In this case I am going to name my first virtual machine 'CentVM1' and, will use type 'Linux' and Version 'Red Hat (64-Bit)'.![PSVMImage3](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage4](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage5](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage6](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage7](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage8](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage9](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage10](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage11](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage12](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage13](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
Install OS / Configure networking
You should install CentOS as you normally would in any other circumstance. However, I would suggest that you consider a minimal installation when given the option of what installation you would like to use. You don't know what you will or won't have available to you on a client system, so I strongly prefer to have a virtual machine where I can't assume anything and will need to install packages on an as needed basis. This will allow you to troubleshoot and be ready for issues you may face on a client system.![PSVMImage14](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
DEVICE="eth0" #this is the default, do not change
HWADDR="08:00:27:F6:B3:84" #this is going to be the mac address of the VM's network interface, do not change
NM_CONTROLLED="yes" #this is the default, do not change
ONBOOT="yes" #set to yes. This is what sets the network interface to start at boot
BOOTPROTO="none" #Since we are using a static IP, we don't want any boot networking protocol like dhcp or bootp to run
IPADDR=10.0.2.6 #The IP address of your virtual machine. I typically start my first machine with 6 and then move up from there. This is a matter of personal preference
NETMASK=255.255.255.0 #This netmask matches the /24 subnet notation we set for the Nat Network earlier
GATEWAY=10.0.2.2 #As stated earlier, VirtualBow reserves the .2 IP in the subnet for gateway
DNS1=8.8.8.8 #The DNS server you want to use. Personal preference.
![PSVMImage15](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage16](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMimage17](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
Snapshots
At this point the machine is able to perform its basic functions. Note that you can't SSH to the server yet, we'll get to that. This is where you will want to put any finishing touches on the virtual machine and create your first snapshot. Before creating my first snapshot I will typically take the following steps.- Stop iptables and remove it entirely from chkconfig so it doesn't start at boot. This is the linux software firewall and hasn't been needed for any work I've ever had to do in a lab. This is typically one of the big things that throws people off when they're trying to establish inbound connectivity for the first time so I recommend disabling it.
- Disable SELINUX.
- Update the OS by running yum update.
![PSVMImage18](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage19](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage20](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
Setting up port forwarding
The last thing you need to do for this VM is make it accessible. You'll notice that if you try to SSH to the machine at 10.0.2.6 you're not going to get very far. The reason for this is because that IP is sitting behind a NAT network, just like your machine does if you are using a router between yourself and your ISP. If your local machine on your local network is 192.168.1.20, no one outside your network is going to be able to ping your machine from the internet, they would have to connect to you using your public facing IP address with a port that you have designated to forward from your router to your local machine. Remember how we mentioned NAT Network port forwarding earlier? We're going to configure that now. Click on File -> Preferences -> Network (on the left menu bar), select your NAT network (LocalNat) and click the screwdriver icon to the right to edit like we did before when confirming the networking settings for the NAT network. This will bring you back to the NAT networking details window, click on the 'port forwarding' button. You'll need to setup a rule to forward a port on your local machine to the port of your virtual machine. In this example we're going to setup an SSH port forward. We'll use the following options... Name: CentVM1SSH Protocol: TCP Host IP: <blank> Host Port: 61022 Guest IP: 10.0.2.6 Guest Port: 22![PSVMImage21](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage22](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage23](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
Cloning your virtual machine
In the VM VirtualBox Manager, right click on your first virtual machine and click on clone.![PSVMImage24](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage25](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage26](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage27](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage28](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
![PSVMImage29](https://static.hsstatic.net/BlogImporterAssetsUI/ex/missing-image.png)
[root@cent2 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=cent2.localhost
[root@cent2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="08:00:27:7E:A7:A5"
NM_CONTROLLED="yes"
ONBOOT="yes"
BOOTPROTO="none"
IPADDR=10.0.2.7
NETMASK=255.255.255.0
GATEWAY=10.0.2.2
DNS1=8.8.8.8
[root@cent2 ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key. #Delete below this line before reboot
# PCI device 0x8086:0x100e (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:7e:a7:a5", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
At this point you're good to go. Shut down your second virtual machine. Take an OS load snapshot of it and you're all set. You can power on both virtual machines and they should be able to communicate with one another with no additional configuration. Don't forget to set up another port forward so you can SSH directly to your second virtual machine, and additional ports as needed to connect to services like MySQL.
This virtual machine setup is as compact as you would like it to be, while being effective and will remain available to you so long as you can power your machine on. Enjoy! Oh, and also, everything written in this tutorial was tested using virtual machines.
Good day!
Discover more about Pythian and our technical expertise.
Share this
Previous story
← Windows containers: installing SQL server
Next story
Oracle 12c - adaptive query optimization →
You May Also Like
These Related Stories
How to move or clone a Microsoft Azure virtual machine?
![](https://www.pythian.com/hubfs/Imported_Blog_Media/blogimg.png)
How to move or clone a Microsoft Azure virtual machine?
Dec 19, 2017
3
min read
Build an EBS 12.1.3 Sandbox in VirtualBox in 1 Hour
![](https://www.pythian.com/hubfs/Imported_Blog_Media/Technical-Track.png)
Build an EBS 12.1.3 Sandbox in VirtualBox in 1 Hour
Nov 29, 2012
34
min read
Adding Networks to Exadata: Fun with Policy Routing
Adding Networks to Exadata: Fun with Policy Routing
Oct 15, 2012
4
min read
No Comments Yet
Let us know what you think