48

I have installed Ubuntu Server 12.04 LTS on my laptop via VirtualBox. I have installed LAMP, OpenSSH, Mail server.

As I logged in, I ran ifconfig. It gave me the inet address as 192.168.0.3.

So, this should be the address through which I should be able to access the server right? But I am not able to access it via browser.. server is up on VirtualBox all the time-- but still, its not working on other browsers, or my mobile. What do I have to do to make it accessible to the public?

2 Answers 2

64

By default a guest machine in VirtualBox is configured to use so called NAT networking - the guest's network adapter's IP is in a "virtual" subnet which includes the guest and the parent VirtualBox application which acts as a gateway. For the guest it looks like it accessing internet via something like an ordinary DSL modem, but the guest can't be accessed from anywhere, just like you can't access machines in your local network from Internet without specifically configuring your modem to allow such access.

VirtualBox documentation has the following list of networking modes:

Each of the eight networking adapters can be separately configured to operate in one of the following modes:

Not attached

In this mode, VirtualBox reports to the guest that a network card is present, but that there is no connection -- as if no Ethernet cable was plugged into the card. This way it is possible to "pull" the virtual Ethernet cable and disrupt the connection, which can be useful to inform a guest operating system that no network connection is available and enforce a reconfiguration.

Network Address Translation (NAT)

If all you want is to browse the Web, download files and view e-mail inside the guest, then this default mode should be sufficient for you, and you can safely skip the rest of this section. Please note that there are certain limitations when using Windows file sharing (see the section called “NAT limitations” for details).

Bridged networking

This is for more advanced networking needs such as network simulations and running servers in a guest. When enabled, VirtualBox connects to one of your installed network cards and exchanges network packets directly, circumventing your host operating system's network stack.

Internal networking

This can be used to create a different kind of software-based network which is visible to selected virtual machines, but not to applications running on the host or to the outside world.

Host-only networking

This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface (similar to a loopback interface) is created on the host, providing connectivity among virtual machines and the host.

Generic networking

Rarely used modes share the same generic network interface, by allowing the user to select a driver which can be included with VirtualBox or be distributed in an extension pack.

If you need to access your guest from outside, you need to configure bridged networking, which will give your guest its own IP in your local network. The configuration is done in VirtualBox settings, not in the guest OS.

To be able to access the server from your mobile (i.e. from outside of your LAN), after configuring the networking you additionally will need to set up port forwarding on your DSL modem.

7
  • 3
    +1 for mentioning the default NAT configuration and suggesting bridged. Jan 7, 2013 at 21:14
  • +1 for teaching me something new, helpful, and relevant to my situation. Thanks! Jan 7, 2013 at 21:40
  • Thanks for the reply, but, don't i need to install DNS on my server inorder to make it accessible to others over internet ?
    – Chins
    Jan 7, 2013 at 23:19
  • @Chins: No you definitely don't need to install DNS on your server. Everything we've discussed so far does not involve DNS at all.
    – Sergey
    Jan 7, 2013 at 23:25
  • 1
    @Sergey - I configured my vm with Bridged Adapter. The ip address displayed on executing ifconfig is 10.210.x.x but I still cannot putty my vm from the host machine. What could be wrong? Sep 24, 2014 at 6:12
10

To provide a little more information, these are the actual steps to take to setup a bridged network:

To enable bridged networking, all you need to do is to open the Settings dialog of a virtual machine, go to the "Network" page and select "Bridged network" in the drop down list for the "Attached to" field. Finally, select desired host interface from the list at the bottom of the page, which contains the physical network interfaces of your systems. On a typical MacBook, for example, this will allow you to select between "en1: AirPort" (which is the wireless interface) and "en0: Ethernet", which represents the interface with a network cable.

Source

I then restarted the virtual machine and was able to connect to it externally.

2
  • Keep in mind, on Mac os 10.1.11 at least, for example, it's not allowed to bridge the wifi adapter directly, but one must first create a 'bridge adapter' in the network settings
    – twicejr
    Feb 24, 2016 at 18:08
  • 1
    but how do things like static IP addresses work in bridged mode? Is everything on the same connection then? Would a web server on the VM be at localhost instead of some IP address? Are the ports forwarded 1:1? So if Tomcat is on the VM at localhost:8080 does the host machine just type localhost:8080 into its browser to see the VM? Mar 29, 2016 at 17:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .