Establish network connection between the PC and Virtualbox virtual machines

I am not an expert in VirtualBox, but I use it from time to time to test (services especially) and one of the things that bothered me was that if I didn't have the network cable connected, my PC couldn't communicate with the virtual machines.

Of course, there is a very simple solution to achieve this which I was completely unaware of, of course, and I show it below in case the same thing happens to someone.

1.- We open VirtualBox and we are going to File »Preference» Network and add a network Host-Only. It should look like this:

2.- Then we add and configure our virtual machine and in its Network configuration, we select Connected to Host-Only Adapter and in Name We add the virtual card that we added previously. It should look like this:

If we open a terminal and type (in the case of Debian):

$ sudo ifconfig

And we are running the virtual machine, something like this will appear:

Related article:
How to change MySQL root user password by terminal
vboxnet0 Link encap: Ethernet HWaddr 0a: 00: 27: 00: 00: 00 inet addr: 192.168.56.1 Bcast: 192.168.56.255 Mask: 255.255.255.0 inet6 addr: fe80 :: 800: 27ff: fe00: 0/64 Scope: Link UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric: 1 RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0 TX packets: 4 errors: 0 dropped: 0 overruns: 0 carrier: 0 collisions: 0 txqueuelen: 1000 RX bytes: 0 (0.0 B) TX bytes: 328 (328.0 B)

As you can appreciate VirtualBox set the IP 192.168.56.1 for the PC. The virtual machine was assigned an IP by DHCP, in my case 192.168.56.101, We can check this with the command we used previously.

Ready!!


36 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Christopher castro said

    Excellent for ssh connections.

    This and virtualize them in the background.

  2.   Germaine said

    Well, on my machine, the connections were made automatically and every time I open one of the two that I have installed, I navigate between them without problem over the network and use Wi-Fi.

  3.   msx said

    Dear elav, I see that you still use "ifconfig", if it is available in Debian I recommend that you start flirting with iproute2:
    http://linuxaria.com/howto/useful-command-of-iproute2?lang=en

    1.    elav said

      En Debian Testing there is only iproute .. and i have always been comfortable working with ifconfig .. anyway let me take a look at the other one 😀

  4.   VaryHeavy said

    Sorry, but I can't quite understand why the type of adapter you use is a host-only adapter to communicate your native machine with the virtual ones, wouldn't it be useful if you put it as a bridge adapter? So you can give your virtual machine an IP from the same network as your native machine, and they will be able to communicate anyway.
    Is there any special reason to use the host-only adapter type?

    1.    proper said

      Yes, when you are not connected to a router, the bridge option will not work because the machine will not have anything to connect to. This option is useful when you don't have a route to use and you want to create a point-to-point connection (in this case Host-Guest).

    2.    elav said

      Hmm, I didn't try a bridge. I try and tell you 😀

      1.    Hyuuga_Neji said

        when you try a bridge you will see that it is as VaryHeavy says ... by putting it as a bridge you can assign an IP of your subnet to the virtual machine ...

  5.   dhunter said

    Lately I am testing aqemu, a frontend in qt4 to qemu / kvm, my tragedies are over by recompiling the vbox module for my custom kernels, kvm is already in the kernel !! And the performance is great, the network is already by default, I am quite happy.

    1.    msx said

      Very good news, to get to KVM then!

  6.   Fabian said

    I see you have the DHCP server Enabled, is this necessary? how do you configure it? I followed this configuration and even my VM does not recognize the network. unknown network appears. It's Windows 7.

    1.    elav said

      I haven't really configured any DHCP, I let it work by default .. I would have to investigate 😉

  7.   Fabian said

    my virtualbox is mounted on ubuntu

  8.   miniminime said

    Thank you very much men, notice that I am a stump of virtualbox and since I had not noticed I used the output in a bridge plan, so I could only take one and leave the rest in standard without being able to access them, but with this you create 2 or 3 and you enter them comfortably, without having to be connected to anything

    Thanks for the tip 😉

  9.   Danny said

    It served me well!

  10.   Manuel said

    Excellent note. Quite useful.
    I only have a doubt how to make it work with IP's defined by the user, other than DHCP.

    Greetings.

  11.   elkin said

    Hi, your contribution is interesting but I have a problem, when I enter ifconfig the line that shows the ip does not appear, it only shows the inet6 .. Do you know what this problem could be?

    1.    Adrian salcedo said

      That's because the file / etc / sysconfig / network-scritps / ifcfg-eth0, you don't have this card activated. Open the file with vim or another editor and modify two elements

      HWADDR = »» the MAC of the card will appear by default
      NM_CONTROLLED = »yes», set it to «no»
      ONBOOT = »no» // change it to yes
      BOOTPROTO = »static» // sometimes DHCP appears

      IPADDR = 10.10.1.11 // If you want a Fixed IP you assign it here
      NETMASK = 255.255.255.0
      GATEWAY = 10.10.1.1 // default gate
      TYPE = Ethernet

      If you use Centos you just do
      service network restart and the network service is restarted

      then you do ifconfig and it should appear active.

      In Ubuntu the configuration file is different and the parameters are also not present right now.

      I hope I've helped.

  12.   Nikolaz said

    Thanks for sharing, it worked as expected. Regards!

  13.   Edman V. said

    For my purposes it served me very well. I have applications made on Windows XP and my laptop uses Windows 8, so I have the applications in virtual PC, I did not remember how to do it but thanks to the author (thank you very much, I must insist) as it is already. In the virtual PC Xp I have SQL Server 2000 installed, which is the manager used by the application. My client has bought a PC and obviously with windows 7 x64 minimum, so the application itself has no problem working. And they will work in a small network where the lying server will be the PC that I indicate with XP. Well, I already did the test and everything is fine, I hope it works for someone else. Ah! Do not forget to configure the ports that SQL server listens to on the server machine, on the firewall (port 1433 TCP and 1434 UDP), otherwise it will not work.

  14.   Andrew said

    Hi, I have tried several times and it does not work for me. I see that there are comments that work the first time ...
    eth1 Link encap: Ethernet HWaddr 08: 00: 27: cf: 5a: 1e
    inet6 addr: fe80::a00:27ff:fecf:5a1e/64 Scope:Link

    I connect via WIFI, I have a windows VISTA as host and a virtualized Debian 6 in Virtualbox.

    I appreciate any comments, greetings and thanks

  15.   Alex said

    ajjajajaja I had looked for it, very useful really THANK YOU VERY MUCH c:!

  16.   dexter said

    How do I connect my linux-fedora virtual machine to my physical machine ?? ... I want my virtual machine as "HOST-ONLY" I want communication between the two to exist !!

  17.   Domingo Gomez said

    I owe you a beer.

  18.   George said

    friend thank you very much you solved a problem for me 😀

  19.   Katy said

    Thanks, this helped me a lot, I was finally able to connect with trixbox in my virtual machine

  20.   fucken said

    Your alternative partially served me. Since if I just followed the procedure you posted, from the guest OS I would lose Internet access and could not ping the host, even though I could ping from the real machine to the virtual one.
    The solution was: Add another network adapter (Adapter 2) following what you did, instead of changing Adapter 1.
    Thank you!

    1.    Wendy garcia said

      I know this post is very old ... but let's see if you answer me lol Did you leave the Adapter 1 disabled or did you leave both with the same configuration? I have exactly the same problem, the guest cannot see the host.

  21.   Erika said

    Thank you very much, I managed to connect to my MV…. It was days of trying until I found your publication

  22.   Jeane said

    Hello, excuse me but I have a huge doubt, what happens is that my virtual machine is mounted on Debian, I put two network adapters, one in Bridge mode and the other in Internal Network, in my house if it enters the Internet but in my Not work: /, if it detects the Network card but I don't understand why this happens. What happens is that I am doing tests on the control of a Lan Network creating a proxy server with squid but hey, my question is because I cannot access the Internet to download my packages

  23.   manuel said

    excellent thank you very much.
    greetings from Lima, Peru

  24.   ogalaviz said

    With this configuration and due to the point-to-point nature, I cannot get the virtual machine to connect to the internet, although the configuration is that I will not need a router to connect my pc with the virtual machines ,, .. like I do so that it has an internet connection

    the scenario I have the host network is in the segment 192.168.50.X, and the network with the router with my pc 192.168.1.0, how do I get the virtual machine to have an internet connection?

  25.   migue said

    Hello…
    So I have it and it doesn't work for me.
    from w8 it gives me an answer -ping- but it does not connect to the repo that is w8

  26.   name said

    Good afternoon, I want to use the Wi-Fi connection in the virtual one and the cable connection in the physical one. It can?

  27.   jc said

    more false than Bolivian tuna

  28.   Andres c said

    Thank you, on two screens you solved my life, I thank you