A short guide to networking in Virtual Box with Oracle Linux inside.

12

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:

image

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:

image

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:

image

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):

image

Double-clicking the last one, the default one without a number:

image

This interface has also been configured as a DHCP-server, clicking on the other tab:

image

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:

image

No DHCP-server:

image

You will see that a virtual network has been made on the guest-system. It shows like this:

image

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:

image

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’:

image

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:

image

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:

image

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.

image

On o.s.-level:

image

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:

image

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):

image

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:

image

Doing a ping to google.nl:

image

A nslookup:

image

As DNS it’s using 8.8.8.8, so I messed up my DNS server (as well he was down at that moment Smile ) 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.

Sources

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/

Share.

About Author

12 Comments

  1. Thank you so much for this post..I was trying to get the internet working on the VM, but could not. Now followed your postand it’s working fine.Thanks again

  2. ***************************************************************************************************************************
    Hi I would like to add here a problem I faced. I did all as suggested but it did not work. Then a friend of mine suggested to check for the network card installation it self on the virtual box machine. Then I re-imported the appliance with PCnet Fast 111 network card rather than the default one Intel PRO / 1000 MT Desktop if you are doing Oracle Virtual Box Linux as PCnet Fast 111 is for linux if Virtual Box machine is for windows then leave it as default. After that I applied the settings on this site and was able to get through smoothly.
    ———————————————————————————————————————————————–
    And a problem before I got was that my virtual adapter did not get installed. so when you are installing Virtual Box itself make sure you run as administrator the installation.

    Best Regards
    Suhail

    ****************************************************************************************************************************

  3. Lucas Jellema on

    Hi Job,

    I have been struggling with setting up networks with VirtualBox for a long time. Basically I resorted to trying out all options and or trying to apply things I vaguely seem to remember from the past that worked at some point in time. Your article will put a stop to that: now I know what will work for which purposes and why!

    Thanks for taking the time to write it down. Very, very useful.

    kind regards,

    Lucas

  4. Hello from Austin, Texas in the US!

    Thank you for taking the time to explain this in such detail! This post has been very helpful in sorting out a process that usually involves a lot of trial and error + frustration.

    Nice Work

    -Michael

  5. Absolutely, wonderful, brilliant post – the 1st I’ve ever found in the last 4 years that clearly explains how to set up this type of networking, in a manner which is understandable to non-networking people.

    I’ve set up several Oracle GI clusters on vBox / VMWare over the last 4 years and have always just muddled through the networking pieces – this post finally explains to me what I’ve been doing and what I need to do going forwards.

    Thank you so much

  6. Hi
    I have configured IP’s as you suggested above
    one is Hostonly and second one is Bridged netowk with static IP but i can’t connect to the internet.
    route -n
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 3.xx.xx.x 0.0.0.0 UG 0 0 0 eth2
    3.xx.xx.x 0.0.0.0 255.255.255.0 U 1 0 0 eth2
    192.168.56.0 0.0.0.0 255.255.255.0 U 1 0 0 eth3
    ###ifconfig -a
    eth2 Link encap:Ethernet HWaddr 08:00:27:4C:03:60
    inet addr:3.2xx.1xx.x Bcast:3.2xx.1xx.255 Mask:255.255.255.0
    inet6 addr: fe80::a00:27ff:fe4c:360/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:11523 errors:0 dropped:0 overruns:0 frame:0
    TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:1102549 (1.0 MiB) TX bytes:17052 (16.6 KiB)

    eth3 Link encap:Ethernet HWaddr 08:00:27:9F:88:34
    inet addr:192.168.56.106 Bcast:192.168.56.255 Mask:255.255.255.0
    inet6 addr: fe80::a00:27ff:fe9f:8834/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:40 errors:0 dropped:0 overruns:0 frame:0
    TX packets:63 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:6218 (6.0 KiB) TX bytes:9870 (9.6 KiB)
    ##cat /etc/resolv.conf
    nameserver 127.0.0.1 (Earlier i have provided DNS servers here.but it doesn’t work
    )
    [root@oraclelinux6 network-scripts]# cat ifcfg-eth2
    DEVICE=”eth2″
    IPADDR=3.2xx.1xx.x
    GATEWAY=3.2xx.1xx.x
    BOOTPROTO=”none”
    IPV6INIT=”no”
    NM_CONTROLLED=”yes”
    ONBOOT=”yes”
    TYPE=Ethernet
    PREFIX=24
    DNS1=3.xx.xx.xx
    DNS2=3.xx.xx.xx
    DNS3=3.xx.xx.xx
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    NAME=”System eth2″
    UUID=3a73717e-65ab-93e8-b518-24f5af32dc0d
    HWADDR=08:00:27:4C:03:60
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
    LAST_CONNECT=1398691328

    i am able to connect virtual machine from PUTTY but unable to connect internet.Can you please assist

  7. Nice write up but you made it a bit more complicated than necessary.

    In 4.3 a new networking mode was added, NatNetwork. That is all you need. So your setup above would only need one adapter per VM. They would have a private network between them using a shared NatNetwork. The VM’s will all have access to whatever the host can reach. You can easily setup port mappings for inbound traffic to any VM.

    Much easier to manage.

    /Mikael

Leave a Reply