How to Configure Network Between Guest VM and Host in Oracle VirtualBox

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

46 Responses

  1. Mark Chassy says:

    I have all of the above working now, but I can’t hit the webserver which is running on the guest, from the host.

    I get:

    /Users/markchassy/bitbucket/orson_ansible/playbooks
    (venv27)==> curl 192.168.56.10:8080
    curl: (7) Failed to connect to 192.168.56.10 port 8080: Connection refused
    
  2. Mark Chassy says:

    Really clear, but a couple questions/comments:

    1. Is there a reason to set the host only network as the first adapter and the NAT as the second. On Ubuntu, it does not seem to make a difference, but on CENTOS/RHEL it does.

    On VirtualBox, the NAT is usually there by default, so one naturally puts the host only second. If you try to switch the host only to static when the adapters are in that that order, the NAT seems to break.

    If you leave both as dynamic and switch the NAT to second place, the onboot=yes switches to onboot=no.

    You have to change that manually.

    Then you can switch the host-only to static and everything works fine.

    • Aaron Kili says:

      @Mark

      There is actually no difference, you can leave NAT for connecting to the internet on adapter 1 and add a second adapter for host-only connection. And thanks for sharing these useful tips.

      • Mark Chassy says:

        Yes, now that I have deactivated the firewall, I realize that I lost half a day just because of that and that I had my adapters set up correctly before. At least now, I actually understand what I am doing.

  3. Rinart73 says:

    And after going through all these instructions I still can’t access nginx server that is running on VirtualBox from my host PC. It just gets stuck on connecting. I guess Windows 10 just can’t do it properly.

  4. Richard says:

    Great article.

    But I have a problem. I want to configure an IP on the virtualbox Centos6.9 instance as follows: 10.156.147.xxx. Its default IP is 10.0.2.15.

    My own network on my pc is which is hosting the VirtualBox software has the IP 192.168.1.xxx.

    I am try and on the Centos6.9 VB IP to 10.156.147.xxx and try and restart the network and it says Ok but the IP is not changed its still 10.0.2.15

    • Aaron Kili says:

      @Richard

      Take not that you need to enable two network interfaces for your guest; one will be used to connect to the internet which should have the IP address 10.0.2.15 by default and another for host-only connection which will probably have the IP address 192.168.1.xxx.

      Follow the steps at the start of the article carefully for this to work i.e create a network for create a for guests and host machine, then add the necessary network interfaces as explained above.

      Also note this article is based on CentOS 7.

  5. george says:

    If dhcp is enabled in host, why to use a static ip in guest, i think iface enp0s3 inet dhcp works better than static

  6. JT says:

    After making adapter 1 host-only and adapter 2 NAT, when I try to start up my VM it gets stuck on “Start job is running for Wait for Network to be Configured” and eventually says that its failed.

    So I end up with no internet. Any idea how to fix this?

    • Aaron Kili says:

      @JT

      Then login to your system and configure static IPs as explained in the article, either for Debian/Ubuntu/Linux Mint or RHEL/CentOS/Fedora systems. Then restart the system for the changes to take effect.

  7. Anand Doraiswamy says:

    This is by far the best detailed documentation on this topic. I have been searching on how to setup n/w between guest hosts with static IP on my Virtualbox. Nothing even came close. Thanks a million. Awesome!

  8. Surren says:

    Very quick, simple and succinct. Well done.

  9. Lucas says:

    Very good, thanks :)

Got something to say? Join the discussion.

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