Well, I don't like answering my own questions, but I found a good answer in another question here, and I thought I'll share:
I was looking for an easy way to work with the virtual machine.
Since creating un orthodox ports (I couldn't forward port 80 of the host to port 80 of the guest, since VirtualBox doesn't allow that yet) is not an easy and comfortable way I couldn't accept any answer that said to do that, as it's not what I asked for.
So one of the answers I found in the list here to the right, said I can just create not one, but TWO network interfaces in VirtualBox for the relevant virtual machine, and then I would have one (NAT) for the host to access the VM, and another (Host-Only) for the VM to access the internet.
This way:
- preserves the guest machine security as it's not on the same network as the host
- gives me the ability to create a hostname for the guest ip, on my host machine - for easy access, without any need to use port forwarding from the host to the guest
- and - gives me access to the internet for the guest machine
Since I tried different options, I had to manually setup the interfaces on the guest ubuntu server machine.
It made me encounter some problems which were pretty annoying so I thought I share one of them:
Make the first interface (eth0) the host-only interface (the one for connecting between the host and the guest), and the second interface (eth1) the NAT interface.
If you won't do so, you might have a problem with the guest machine trying to access the internet using the Host-only interface.
This issue might have been caused by something completely different, and the order may not have any relation to it, but that's what happened to me, so I share with anyone who reads this, in case you encounter such a problem.
Thank you for helping out!
EDIT: Just saw @Goyuix posted a link to the question that helped me out as well. Thanks @Goyuix.
One option is to change the network adaptor of the virtual machine to bridged mode; you should then be able to access the virtual server from the other machines on the network, by providing your guest's IP address.
Edit:
For practical aspects, look at the VirtualBox documentation on Virtual networking. Your options are to use bridged networking
With bridged networking, VirtualBox uses a device driver on your host
system that filters data from your physical network adapter. This
driver is therefore called a "net filter" driver. This allows
VirtualBox to intercept data from the physical network and inject data
into it, effectively creating a new network interface in software.
When a guest is using such a new software interface, it looks to the
host system as though the guest were physically connected to the
interface using a network cable: the host can send data to the guest
through that interface and receive data from it. This means that you
can set up routing or bridging between the guest and the rest of your
network.
or port forwarding:
As the virtual machine is connected to a private network internal to
VirtualBox and invisible to the host, network services on the guest
are not accessible to the host machine or to other computers on the
same network. However, like a physical router, VirtualBox can make
selected services available to the world outside the guest through
port forwarding. This means that VirtualBox listens to certain ports
on the host and resends all packets which arrive there to the guest,
on the same or a different port.
So, in case of a NAT port forwarding, you should use the following command:
VBoxManage modifyvm "VM name" --natpf1 "guesthttp,tcp,,80,,80"
Best Answer
There are at least three separate components at play here, each of which need to be configured correctly.
Rails binding address
When Rails (or another server application) opens to receive network connections, it will bind to both an IP and port. If an incoming request doesn't match both of these, it won't accept the connection. From
rails server --help
:So by default, Rails will only accept requests sent to its
localhost
(loopback) network adapter (calledlo
). Since this adapter is only accessible from within the same computer, the only requests it will accept will be from within the Debian VM itself: good and secure for testing, but not useful for production, or even testing from a different computer.If you want your Rails to be accessible from any other computer (including your Windows 7 host), you will need to tell Rails to bind to whichever IP address Debian has that is accessible from the outside (see below).
However, an easier way is to tell Rails to bind to the special IP address
0.0.0.0
, which means any network adapter. So, starting your Rails server like so:will make your website accessible to anyone who can see your VM on the network.
This is likely what has still messed you up even if you had the other two components working.
VM IP address
You need to point your browser at the Debian virtual machine, which is its own discrete computer.
The rule of thumb with
localhost
is that it always refers to the same computer. However, for networking purposes, your Debian VM is its own separate computer. If you're using a web browser in your Windows 7 host,localhost
will always refer to your Windows 7 and nothing else.You have two options here:
Set the VirtualBox VM adapter to Bridge mode (as you mentioned in your question). This will put your Debian directly on the same outside/home/work network as your Windows 7 host. You can then determine your Debian VM's IP by running
ifconfig
. Look for the IP of youreth0
oreth<something>
adapter. Plug this into your browser's address bar.Use a NAT adapter and VirtualBox port forwarding. IMO this is more complicated.
Debian firewall
It's been a while since I've worked on Debian so I don't know what the current defaults are, but if the above two things don't work then this might be worth looking into. If Debian is running a firewall, you'll need to open any ports you wish to access from another machine.
Hope this helps :)