Friday, September 15, 2017

How to enable LAN network to access to web server hosted in Oracle VirtualBox

There are 2 ways, one is fully setup in Oracle VirtualBox, the other way is setups in both host and VirtualBox. These methods might not limited for access to the web server in virtual machine, but probably also to access samba server in virtual machine and etc. I haven't tested with other services though. To keep it simple, we'll use a simple httpd service in the VirtualBox machine.

Requisites
1. httpd is running in virtual machine.
2. firewall rule in virtual machine allow the access to the http service
3. a test web page is created for the httpd run.

To test the web service is working fine in the virtual machine, run the following in virtual machine.



OK, let's get started. Power off your virtual machine. Launch the Settings of your virtual machine in VirtualBox Manager.

Bind the virtual machine with the host.

Set as below:



The Host-only Adapter allows the access from your host machine to this virtual machine. With only this setting, your host machine is able to access to the web service.

As I started my virtual machine, and run ip addr, I'll get an IP address allocated for this interface.

Snippet of the ip addr result.


Test result from host machine.


To bind virtual machine with host's interface

We'll need to use Bridged Adapter for this purpose.


So, now if you are accessing the web service using your host IP or host name after starting your virtual machine, it will display the same page.

In case it is not, you might need to check your network setting in your virtual machine. My connection for this interface is not enabled by default. Not sure why. If you run ip addr, you'll find out that the new interface doesn't have IP assigned to it. nmcli con show will show the connection is not up. Bring up the connection with nmcli command, you'll see it's working now.

Next, we want to do port forwarding to allow external (LAN) user to access to the web service hosted in your virtual machine.

First way : setup in host machine

My host machine is Windows 7. So, I'll run netsh in command prompt to allow the port forwarding.  As this is not my personal machine, I am not sure how sensitive is my host IP, so I'm hiding it. :)


You can use another machine in the same LAN to test it out. Use the host machine IP / name to access to the web page. I tested this, it works!

To remove this port forwarding setup, you just do a reset.


Second way : setup in VirtualBox setting

You'll need to use NAT adapter for this.


In additional to this, you'll need to add port forwarding rule. See below screenshot for details.


This works the same way as the netsh commands in host machine!

I am going to try for Samba server/iscsi target setup next!

Oh, btw, the virtual machine is running on CentOS 7.



No comments:

Post a Comment