开发者

Ubuntu on VirtualBox and Rails server

I have Windows 7. Installed VirtualBox an开发者_Python百科d Ubuntu 11.04 as guest OS. Networking is done by NAT. Everything is fine: I have internet on Ubuntu. I can access Windows from Ubuntu by its ip. But i can't access Ubuntu by it's ip which is shown by ifconfig.

I run rails on Ubuntu.

How can I solve this problem: connect to Ubuntu/Rails server on ort 3000 from my Windows?


By default, VirtualBox's NAT allows the virtual machine to access the Internet ; but doesn't allow the physical machine to access the Virtual one.


The simplest solution would be to use another networking setting than NAT, for your Virtual Machine -- for instance, bridge should work fine (your VM would be visible on your network, though).

Another solution would be to use port forwarding ; about that, this article might help : Howto Access via ssh a Virtualbox Guest machine.


I used to struggle with configuring a similar setup until I found Vagrant. Vagrant makes it very simple to setup, connect to and work with a Linux virtual machine. After Vagrant is configured you can just type vagrant ssh to enter the virtual machine and your account has automatic sudo rights and everything works as expected - you don't even have to deal with logging into the vm. The initial setup for ssh does look to be a little more work under Windows though as you need to configure Putty before you can connect.

There is a simple configuration file in Vagrant that you use to specify which ports from the VM you want forwarded to your machine using a syntax like:

  config.vm.forward_port("rails", 80, 3000)
  config.vm.forward_port("tomcat", 8000, 8080)

and everything is taken care of. Details are here

If, for example, you are using Rails and you start vagrant with the command vagrant up in your Rails project directory than that directory is available on the VM. Since it is the same shared directory between machines, any changes you make in your Rails project directory on your machine using your regular editor is seen on the VM also. This makes testing in other environments very easy.

Instructions for setting Vagrant up with Windows are here and a RailsCast about it is here. Note that Vagrant has nothing to do directly with Rails - you can use it for setup of any virtual machine environment you need.


In short, you can't. It is a local host not a public domain therefore not publicly accessible outside of your virtualbox environment.

Maybe someone has a clever hack for this but why would you want to do this in the first place?

Your solution is to either use firefox to browse to your localhost within your virtualbox linux session or develop on windows.

Personally I work the other way round I run Ubuntu 11.04 and I have virtualbox installations of xp, 2,000, me, vista and 7 so I can test in different environments. Inevitably I end up sharing my project folder from Ubuntu so that I can run the project in whatever OS I am testing for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜