Replace WAMP With A Real (Virtual) Server

back to tech articles
VirtualBox 4.3.6

The title of this talk should probably read Virtual CentOS Server With Host-Only NIC & WAN Access On Win 7 64-bit, but who’s gonna Google that, right?!?

Here’s what I wanted:

  • Windows 7 64-bit host.
  • Virtual CentOS 6.5 64-bit guest.
  • WAN access for the CentOS server.
  • Host-only access to the guest (via SSH).

This setup will allow for all of the above, as well as provide traditional connectivity from the host that web developers are familiar with (SSH, FTP, SFTP, MySQL and so on). We can also use a nice deployment method such as Git once it’s all up and running.

VirtualBox – Preferences

For starters, we need to setup VirtualBox correctly. I won’t cover the basic stuff here such as hardware setup – I’m going to assume you already know how to do that side of things. For transparency’s sake, I will tell you that I’m using CentOS’ minimal install 64-bit ISO image at version 6.5.

The settings we are interested in for the scope of this talk revolve around networking, and we need to tinker with the VirtualBox Preferences (File > Preferences). Select Network and click on the Host-only Networks tab.

VirtualBox_Network_Settings_01

In version 4.3.6 of VirtualBox, only one named adapter is listed; VirtualBox Host-Only Ethernet Adapter. Right-click that and choose Edit host-only network. The adapter settings can be left as-is. The IPv4 address is set to 192.168.56.1 and IPv4 Network Mask is at 255.255.255.0.

VirtualBox_Network_Settings_02

Click on the DHCP Server tab and clear the tick next to Enable Server.

VirtualBox_Network_Settings_03

Click OK twice to confirm the change. The reason we are doing this is because we will assign a static IP address to the host-only adapter from CentOS and we don’t want DHCP interfering with our settings.

VirtualBox – The Network Adapters

Next, highlight your virtual machine and choose Settings. We are going to add 2 network adapters, each of which will provide a level of connectivity for our setup. First, we enable Adapter 1 and set it to NAT. This adapter will provide the WAN access we need to get to the internet from the guest machine.

VirtualBox_Network_Settings_04

Next, we need to enable a second adapter and set it to Host-only Adapter. This will give us the local connectivity we want so that this server resides in our own private (local) network.

VirtualBox_Network_Settings_05

Adapters 3 and 4 we do not enable. VirtualBox is now configured and we are ready to move on and configure the guest. Fire it up.

Install CentOS

Once you have configured the hardware, go ahead and install CentOS to the virtual machine. Once that is done, login using your username and password that you chose and shutdown selinux and iptables:

1
2
3
$ /etc/init.d/iptables stop
$ chkconfig iptables off
$ vi /etc/selinux/config

In the selinux config file, you want to set SELINUX to disabled.

1
SELINUX=disabled

Save that and exit the file editor. Hammertime, na na na na. Now that we are without a firewall and the bothersome antics of selinux, we can get to work.

Configure CentOS Adapters

We need to check which network adapters have been assigned in CentOS. We do that by running ifconfig.

1
$ ifconfig

You should get a list of adapters, including eth0, eth1 and probably lo. Those addresses are mapped to the network adapters we selected from VirtualBox. Adapter 1 is mapped to eth0, Adapter 2 is mapped to eth1 and lo is the machine’s localhost loopback.

Your own adapter’s may vary. For example, you may find eth0 and eth3. Don’t worry about the number too much; just substitute your own for the remainder of this tutorial. Remember that the adapters will appear in the same order as they are selected in you VirtualBox settings (Adapter 1 => eth0, Adapter 2 => eth3 and so on).

Now, we want to leave eth0 alone (since it’s automatically been configured to connect to the internet) apart from a single setting; ONBOOT.

1
$ vi /etc/sysconfig/network-scripts/ifcfg-eth0

Set the ONBOOT parameter to yes.

1
ONBOOT=yes

Save and exit. Now we want to configure our host-only adapter at eth1. We need to edit the config file for that adapter:

1
$ vi /etc/sysconfig/network-scripts/ifcfg-eth1

Match the contents of the file to the following, substituting your own HWADDR and UUID parameters, of course:

1
2
3
4
5
6
7
8
9
DEVICE=eth1
HWADDR=08:12:27:A9:5B:F3
TYPE=Ethernet
UUID=403fe2bd-a2b1-4c1c-941b-113ge3ed10
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.56.10
NETMASK=255.255.255.0

Notice we are setting a static IP address of 192.168.56.10. This address will be available on a private network, along with our host machine.

Conclusion

Now that our settings are in place, all that is left to do is restart the virtual machine. Once we are up and running again, test your internet connectivity by running

1
$ yum update

If all is well, you will be offered some packages for update and you are ready to go. Your machine is available from the host machine at the IP address 192.168.56.10. We can test that by running ping 192.168.56.10 from a command prompt on the host.

To make life a little easier for you, add an entry to the host file and use a domain name.

At the end of your C:\Windows\System32\drivers\etc\hosts file, add the following:

1
192.168.56.10    local

Happy coding sports fans.