This post is intended to be a dummy guide, best practices, or whatever you call it… about setting up a network while working with virtual boxes on a desk- or laptop. I was setting up a virtual box environment with several Virtual Boxes on my laptop, and as I’m not a network – specialist, I came across a few annoying things, challenges if you like. And when I was googling around, it appeared to be I’m not the only one, so I felt the urge to share some experiences.
What I want is the following environment and some elements smells like a subset of the real life:
1. Connect from my laptop to my virtual box through ssh and sqlplus, with fixed ip-address.
2. Simulate a private network, a network between the virtual boxes, also with fixed ip-addresses.
3. Occasionally connect to the internet from within the virtual boxes. To performs a ‘yum update’ and that kind of stuff.
In a picture it looks like this:
My laptop is a Windows-7 machine, the two virtual boxes are equipped with Oracle Linux 6.5 with Oracle database 12c on it.
For general understanding, needed later on in this post, my network configuration on my laptop, performing an ‘ipconfig’ on o.s.-level:
My ip-address is apparently 192.168.178.10, and through a wireless connection. The default gateway of 192.168.1 is my internet router.
More important for configuring the first connection: there’s also a virtual, host-only network with a ip-address of 192.168.56.1:
I’ll come back to this in the next chapter.
There will be an explanation per connection for the purpose of this post. In real life it’s much faster to configure the three networks all together at once.
1. Connection from the laptop to the Virtual Boxes.
To connect with the Virtual Boxes, I used the ‘Host-only’ network interface (Bridged is also possible, this will be explained later on). When installing Virtual Box on a computer there’s already one default installed, and visible on your o.s., in this case the 192.168.56.1. This can be compared as a loop-back interface. The configuration can be found on the Virtual Box Manager (not on a virtual box itself !). Choose ‘file’, ‘preferences’, ‘network’. Then the tab ‘host-only interfaces’. In my cases it looks like this (unfortunately my virtual box has been installed in Dutch language, sorry for that):
Double-clicking the last one, the default one without a number:
This interface has also been configured as a DHCP-server, clicking on the other tab:
But what I want is a fixed ip-address in another range (not necessary, but for the purpose of this post to point things out), e.g. 192.168.188.100. You can also use the default host-only interface.
For this post, we’ll add another one. Remember, my own ip-addres is 192.168.178.10.
For the purpose of this post, you will create a new host-only interface. I created a second one in the virtual box manager:
You will see that a virtual network has been made on the guest-system. It shows like this:
Now I’m going to create a Virtual Box, named ‘rac1-ol6-121’. In the network configuration, Adapter 1, choose ‘host-only adapter’, and then the VirtualBox Host-Only Ethernet Adapter #2, like this:
Virtual Box has been created, now it’s time to install Linux on it, what I will not cover in this post. After Linux has been installed you’ll have to configure the interface ‘eth0’ in the following way.
Through the gui: ‘System’, ‘Preferences’, ‘Network connections’, edit ‘system eth0’, tab ‘Ipv4 Settings’:
Alternatively, you can accomplish the same on Linux OS commandline:
# cd /etc/sysconfig/network-scripts
# vi ifcfg-eth0
# service network restart
Should look like this:
Be sure that ONBOOT has been set on yes.
This should do the trick. While I was configuring the network on commandline I noticed that the GUI was not catching up with the updates I made. Be aware of that. It will be synchronised by rebooting the server, not yet figured out how to synchronise the GUI – network configuration with the updates I made on the commandline without rebooting. When updating through the GUI, the ifcfg-eth0 will be modified correctly.
So now it should be possible to connect to your Virtual Box from your laptop or desktop, in my case through the fixed ip-address 192.168.188.100. This ip-address can be configured in my host-file on my windows machine to connect by a fixed name.
When you still got trouble connecting to your virtual box, be sure to look into iptables and selinux.
For the purpose of this post, you could decide to stop iptables and disable selinux
service iptables stop
chkconfig iptables off
vi /etc/selinux/config : disabled (Needs a reboot)
2. Simulating a private network between Virtual Boxes.
To connect between virtual boxes and nothing more, is quite straight forward. Within the Virtual Box manager this is a separate adapter called ‘Internal Network’.
Before starting your Linux Virtual Box, configure your second adapter (the first was for host-only networking) like this:
The above picture has been taken while the VirtualBox was running, so that’s why the box ‘Switch on Network adapter’ has been greyed out.
I gave the network a name: ‘neta’ . The rest will be left default.
In Linux this adapter will be defined as ‘eth1’, and the ip-address I gave is ‘192.168.190.200. Gateway is not necessary.
Now I’ve got 192.168.187.xxxx as physical addres, 192.168.188.xxx as host-only (public interface?) and 192.168.190.xx as internal network.
And when you create another Virtual Box with also an internal adapter in it (e.g. 192.168.190.210) with the name ‘neta’, they should see each other.
3. From Virtual Box to internet.
For the occasional connection to the internet, we’ll add another interface to the virtual boxes.
In Virtual Box there are two interfaces which can connect to the phyisical interface and thus are able to connect to the internet (and your desk- /laptop): NAT en Bridged.
Bridged: Uses an ip-address in the same range as your physical network, either fix or through dhcp. We’ll use fixed later on. This provides your virtual boxes with an interface as if they are directly connected to the internet, as your laptop/desktop.
NAT: Provides an ip-address in the 10.x.x.x range. This ip-address will be translated on your laptop.
See. https://www.virtualbox.org/manual/ch06.html for more information about VirtualBox networking
Bridged (using dhcp) and NAT has a quite annoying side-effect. I was working with DNS-resolving, and the NAT-interface had the habit to overwrite my settings in resolv.conf. I know there are ways to overcome this, but decided nevertheless to go for ‘bridged’….
Before starting your Linux Virtual Box, configure a Bridged adapter through your Virtual Box manager:
Important in this configuration: the name of the adapter is not just a name, but the physical interface: your –wired – network card, or your wifi. In this case my wifi (Centrino Advanced…). Once I used my laptop on a wired network during the day, and tried to connect to internet through the Virtual Box when I was at home, connected to my wifi. The name of this virtual adapter was changed to the wired adapter, so I had to close the virtual box, reconfigure it to the ‘Centrino Advanced’- wifi, and it worked again…. Bit annoying.
Within Linux the adapter is the equivalent of eth2 (the third adapter configured in Virtual Box):
Ip-address should be in the range of your LAN or home network (In my case 192.168.178.xxx). Gateway is my router at home.
For DNS I filled in the google DNS Server addresses. Should not be necessary I think, but I messed up my home DNS a bit, and now I am a bit more confident DNS works (at least for internet stuff).
On Linx commandline:
Doing a ping to google.nl:
As DNS it’s using 22.214.171.124, so I messed up my DNS server (as well he was down at that moment ) using DNS from the outside world. Working though now…
Note: It’s just as secure as your laptop connection to the internet, so be careful with a bridged connection. You can leave it default off (ONBOOT=no in ifcfg-eth2), and switch it on when needed.
Virtual box documentation: https://www.virtualbox.org/manual/ch06.html
Ed Stevens, configure the Virtual Box network: http://edstevensdba.wordpress.com/2012/12/15/configure-the-virtualbox-network-2/