Virtualbox NAT and host-only connection












0














Because I'm working on multiple locations, I experience problems with my development servers. Because work on a variety of networks I do not want to configure the networking settings of my virtual machines every time I change network. Sometimes the network requires me to use DHCP. (public libraries and such)



Also I have to change network adapter often, I prefer ethernet but sometimes I have to work wireless.



So a lot of different networks and even different adapters.



Requirements




  • Internet connection

  • Access Host machine from Guest machine

  • Access Guest Machine from Host machine


I am looking for a configuration so I dont have to change my (virtual machines) network settings. Because I had to changed network (adapter)



Specs



host machine: Ubuntu, Virtualbox
guest machine: debian.
wireless interface: wlp2s0
eth adapter: eth1



Attempt #1



Just use NAT.




  • Added a NAT adapter to Virtualbox: (10.0.2.0/24, DHCP enabled)

  • Added a NAT adapter to the Guest machine.

  • Configure guest interface:


    • auto eth1

    • allow-hotplug eth1

    • iface eth1 inet static

    • address 10.0.2.5

    • netmask 255.255.255.0

    • gateway 10.0.2.2

    • network 10.0.2.0

    • broadcast 10.0.2.255




With this configuration the following works:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This seems to be a limitation when using NAT.



Attempt #2



NAT in combination with Bridged connection:




  • Virtualbox NAT Adapter (10.0.2.0/24, DHCP enabled)

  • Virtualbox Bridged Adapter (192.168.56.1/24, DHCP enabled)


Because sometimes I have to switch from wireless to Ethernet I also tried to configure a bridged adapter for both the network adapters on the Host Machine.



Host Machine IP: 192.168.56.101
Guest Machine IP: 192.168.56.100



With this configuration, the following does work:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This example has a problem because for a bridged connection the host machine IP has to be set in the range of the IP range of the bridged adapter. Sometimes I can't because i am required to use DHCP.



Given the details of my attempts, do you guys can advise me a alternative configuration for achieving my goals?










share|improve this question















migrated from serverfault.com Jun 28 '17 at 20:39


This question came from our site for system and network administrators.















  • I've set this up before, lemme recreate it and i'll post an answer for you
    – ivanivan
    Jun 29 '17 at 0:02










  • I'm not sure if it is working, but perhaps... What do you think about that, add two virtual adapters to guest, one assigned to ethernet, the other to the wifi, and in the guest bond these interfaces.
    – user907961
    Jun 3 '18 at 7:29
















0














Because I'm working on multiple locations, I experience problems with my development servers. Because work on a variety of networks I do not want to configure the networking settings of my virtual machines every time I change network. Sometimes the network requires me to use DHCP. (public libraries and such)



Also I have to change network adapter often, I prefer ethernet but sometimes I have to work wireless.



So a lot of different networks and even different adapters.



Requirements




  • Internet connection

  • Access Host machine from Guest machine

  • Access Guest Machine from Host machine


I am looking for a configuration so I dont have to change my (virtual machines) network settings. Because I had to changed network (adapter)



Specs



host machine: Ubuntu, Virtualbox
guest machine: debian.
wireless interface: wlp2s0
eth adapter: eth1



Attempt #1



Just use NAT.




  • Added a NAT adapter to Virtualbox: (10.0.2.0/24, DHCP enabled)

  • Added a NAT adapter to the Guest machine.

  • Configure guest interface:


    • auto eth1

    • allow-hotplug eth1

    • iface eth1 inet static

    • address 10.0.2.5

    • netmask 255.255.255.0

    • gateway 10.0.2.2

    • network 10.0.2.0

    • broadcast 10.0.2.255




With this configuration the following works:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This seems to be a limitation when using NAT.



Attempt #2



NAT in combination with Bridged connection:




  • Virtualbox NAT Adapter (10.0.2.0/24, DHCP enabled)

  • Virtualbox Bridged Adapter (192.168.56.1/24, DHCP enabled)


Because sometimes I have to switch from wireless to Ethernet I also tried to configure a bridged adapter for both the network adapters on the Host Machine.



Host Machine IP: 192.168.56.101
Guest Machine IP: 192.168.56.100



With this configuration, the following does work:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This example has a problem because for a bridged connection the host machine IP has to be set in the range of the IP range of the bridged adapter. Sometimes I can't because i am required to use DHCP.



Given the details of my attempts, do you guys can advise me a alternative configuration for achieving my goals?










share|improve this question















migrated from serverfault.com Jun 28 '17 at 20:39


This question came from our site for system and network administrators.















  • I've set this up before, lemme recreate it and i'll post an answer for you
    – ivanivan
    Jun 29 '17 at 0:02










  • I'm not sure if it is working, but perhaps... What do you think about that, add two virtual adapters to guest, one assigned to ethernet, the other to the wifi, and in the guest bond these interfaces.
    – user907961
    Jun 3 '18 at 7:29














0












0








0


1





Because I'm working on multiple locations, I experience problems with my development servers. Because work on a variety of networks I do not want to configure the networking settings of my virtual machines every time I change network. Sometimes the network requires me to use DHCP. (public libraries and such)



Also I have to change network adapter often, I prefer ethernet but sometimes I have to work wireless.



So a lot of different networks and even different adapters.



Requirements




  • Internet connection

  • Access Host machine from Guest machine

  • Access Guest Machine from Host machine


I am looking for a configuration so I dont have to change my (virtual machines) network settings. Because I had to changed network (adapter)



Specs



host machine: Ubuntu, Virtualbox
guest machine: debian.
wireless interface: wlp2s0
eth adapter: eth1



Attempt #1



Just use NAT.




  • Added a NAT adapter to Virtualbox: (10.0.2.0/24, DHCP enabled)

  • Added a NAT adapter to the Guest machine.

  • Configure guest interface:


    • auto eth1

    • allow-hotplug eth1

    • iface eth1 inet static

    • address 10.0.2.5

    • netmask 255.255.255.0

    • gateway 10.0.2.2

    • network 10.0.2.0

    • broadcast 10.0.2.255




With this configuration the following works:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This seems to be a limitation when using NAT.



Attempt #2



NAT in combination with Bridged connection:




  • Virtualbox NAT Adapter (10.0.2.0/24, DHCP enabled)

  • Virtualbox Bridged Adapter (192.168.56.1/24, DHCP enabled)


Because sometimes I have to switch from wireless to Ethernet I also tried to configure a bridged adapter for both the network adapters on the Host Machine.



Host Machine IP: 192.168.56.101
Guest Machine IP: 192.168.56.100



With this configuration, the following does work:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This example has a problem because for a bridged connection the host machine IP has to be set in the range of the IP range of the bridged adapter. Sometimes I can't because i am required to use DHCP.



Given the details of my attempts, do you guys can advise me a alternative configuration for achieving my goals?










share|improve this question















Because I'm working on multiple locations, I experience problems with my development servers. Because work on a variety of networks I do not want to configure the networking settings of my virtual machines every time I change network. Sometimes the network requires me to use DHCP. (public libraries and such)



Also I have to change network adapter often, I prefer ethernet but sometimes I have to work wireless.



So a lot of different networks and even different adapters.



Requirements




  • Internet connection

  • Access Host machine from Guest machine

  • Access Guest Machine from Host machine


I am looking for a configuration so I dont have to change my (virtual machines) network settings. Because I had to changed network (adapter)



Specs



host machine: Ubuntu, Virtualbox
guest machine: debian.
wireless interface: wlp2s0
eth adapter: eth1



Attempt #1



Just use NAT.




  • Added a NAT adapter to Virtualbox: (10.0.2.0/24, DHCP enabled)

  • Added a NAT adapter to the Guest machine.

  • Configure guest interface:


    • auto eth1

    • allow-hotplug eth1

    • iface eth1 inet static

    • address 10.0.2.5

    • netmask 255.255.255.0

    • gateway 10.0.2.2

    • network 10.0.2.0

    • broadcast 10.0.2.255




With this configuration the following works:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This seems to be a limitation when using NAT.



Attempt #2



NAT in combination with Bridged connection:




  • Virtualbox NAT Adapter (10.0.2.0/24, DHCP enabled)

  • Virtualbox Bridged Adapter (192.168.56.1/24, DHCP enabled)


Because sometimes I have to switch from wireless to Ethernet I also tried to configure a bridged adapter for both the network adapters on the Host Machine.



Host Machine IP: 192.168.56.101
Guest Machine IP: 192.168.56.100



With this configuration, the following does work:




  • Internet connection

  • Access Host Machine from Guest machine


With this configuration, the following does not work:




  • Access Guest Machine from Host Machine


This example has a problem because for a bridged connection the host machine IP has to be set in the range of the IP range of the bridged adapter. Sometimes I can't because i am required to use DHCP.



Given the details of my attempts, do you guys can advise me a alternative configuration for achieving my goals?







networking virtualbox






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 28 '17 at 23:19









Cory Knutson

302211




302211










asked Jun 28 '17 at 20:39









Beach ChickenBeach Chicken

611211




611211




migrated from serverfault.com Jun 28 '17 at 20:39


This question came from our site for system and network administrators.






migrated from serverfault.com Jun 28 '17 at 20:39


This question came from our site for system and network administrators.














  • I've set this up before, lemme recreate it and i'll post an answer for you
    – ivanivan
    Jun 29 '17 at 0:02










  • I'm not sure if it is working, but perhaps... What do you think about that, add two virtual adapters to guest, one assigned to ethernet, the other to the wifi, and in the guest bond these interfaces.
    – user907961
    Jun 3 '18 at 7:29


















  • I've set this up before, lemme recreate it and i'll post an answer for you
    – ivanivan
    Jun 29 '17 at 0:02










  • I'm not sure if it is working, but perhaps... What do you think about that, add two virtual adapters to guest, one assigned to ethernet, the other to the wifi, and in the guest bond these interfaces.
    – user907961
    Jun 3 '18 at 7:29
















I've set this up before, lemme recreate it and i'll post an answer for you
– ivanivan
Jun 29 '17 at 0:02




I've set this up before, lemme recreate it and i'll post an answer for you
– ivanivan
Jun 29 '17 at 0:02












I'm not sure if it is working, but perhaps... What do you think about that, add two virtual adapters to guest, one assigned to ethernet, the other to the wifi, and in the guest bond these interfaces.
– user907961
Jun 3 '18 at 7:29




I'm not sure if it is working, but perhaps... What do you think about that, add two virtual adapters to guest, one assigned to ethernet, the other to the wifi, and in the guest bond these interfaces.
– user907961
Jun 3 '18 at 7:29










2 Answers
2






active

oldest

votes


















0














OK, so there are 2 ways of sort of doing this.



1) Use the VirtualBox NAT network on the client. This doesn't provide a direct route from your host machine, but you can set preferences to forward ports. Kind of a pain to set up, but if the host machine was Windows or a Mac this is what I'd probably do, mostly because I'm not sure on firewalling/natting/routing capabilities on those systems (pretty sure Mac wouldn't have an issue, but Windows is unknown to me)



2) Use the VirtualBox Host Only Network. From your description, this may be better. Be aware that you will need to change the firewall script to point to whatever device is connected.... Here's teh details.



On the host machine, first set up the Host Only Network in your vbox preferences. In the Manager, click File and then Preferences, and then select Network. Flip over to Host Only, and then add one if needed. Here's what mine looks like:
hostonly network tab 1



Hostonly tab2



Next, on the host, configure the vboxnet0 interface. It automagically just happens for me, setting my host machine to the .1 address in the subnet. Here's output of ifconfig on my host, referencing my ethernet and vboxnet0 address.



ifconfig info on host machine



In your guest machine, set the network to some address in your subnet (even with the DHCP server enabled, this makes it easier to get gateway/dns server) and set a nameserver in the usual way (ie, edit /etc/network/interfaces and set the static address/netmask/gateway there, then edit /etc/resolv.conf and set a name server there).



At this point, your host machine and your guest machine should be able to communicate back and forth with no issues. You may want to put appropriate entries in /etc/hosts so you don't have to enter the IPs everywhere...



The last step is to get internet going for the guest. This is a simple matter of turning the host into a router. Since the vboxnet0 interface doesn't come up until vbox is up and running, you don't want to do this at boot time for the host.



A simple firewall script to allow the guest vm to access the world, and the host machine can still access the world and the guest in the vboxonly network. Be aware that this script could be MUCH more secure. As it is, it would accept some client on whatever network the host is connected to using your host machine as a gateway to the guest vm.



#!/bin/bash

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables=`which iptables`

$iptables -F

/sbin/iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE

$iptables -A FORWARD -i enp2s0 -o vboxnet0 -j ACCEPT
$iptables -A FORWARD -i vboxnet0 -o enp2s0 -j ACCEPT





share|improve this answer





















  • IvanIvan thanks for your detailed comment, I'll let you know if it worked!
    – Beach Chicken
    Jun 29 '17 at 6:42



















0














I was struggling with this problem till a few days back. To fix this, a simple setup would require using two adapters on the guest.




  1. NAT: This would enable communication from the guest to external networks and also guest to host. To view the IP to use for communicating with the host, view the host’s IP in the ifconfig / ipconfig output on the guest. This is the gateway for the NAT network. This would not show up in ifconfig on the host since a VirtualBox creates a NAT network for each of the VMs.


  2. Host Only: This would allow communication between the host and the guest. By default VirtualBox assigns guest IPs using DHCP, but you can assign static IP for the guest using an IP below 192.168.56.100



You may also set up a third optional adapter internal if you have more than one guest and you would like to communicate between guests. Here is the question I had asked last week regarding this issue: *Edit* Make virtualbox host only network bidirectional






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1223801%2fvirtualbox-nat-and-host-only-connection%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    OK, so there are 2 ways of sort of doing this.



    1) Use the VirtualBox NAT network on the client. This doesn't provide a direct route from your host machine, but you can set preferences to forward ports. Kind of a pain to set up, but if the host machine was Windows or a Mac this is what I'd probably do, mostly because I'm not sure on firewalling/natting/routing capabilities on those systems (pretty sure Mac wouldn't have an issue, but Windows is unknown to me)



    2) Use the VirtualBox Host Only Network. From your description, this may be better. Be aware that you will need to change the firewall script to point to whatever device is connected.... Here's teh details.



    On the host machine, first set up the Host Only Network in your vbox preferences. In the Manager, click File and then Preferences, and then select Network. Flip over to Host Only, and then add one if needed. Here's what mine looks like:
    hostonly network tab 1



    Hostonly tab2



    Next, on the host, configure the vboxnet0 interface. It automagically just happens for me, setting my host machine to the .1 address in the subnet. Here's output of ifconfig on my host, referencing my ethernet and vboxnet0 address.



    ifconfig info on host machine



    In your guest machine, set the network to some address in your subnet (even with the DHCP server enabled, this makes it easier to get gateway/dns server) and set a nameserver in the usual way (ie, edit /etc/network/interfaces and set the static address/netmask/gateway there, then edit /etc/resolv.conf and set a name server there).



    At this point, your host machine and your guest machine should be able to communicate back and forth with no issues. You may want to put appropriate entries in /etc/hosts so you don't have to enter the IPs everywhere...



    The last step is to get internet going for the guest. This is a simple matter of turning the host into a router. Since the vboxnet0 interface doesn't come up until vbox is up and running, you don't want to do this at boot time for the host.



    A simple firewall script to allow the guest vm to access the world, and the host machine can still access the world and the guest in the vboxonly network. Be aware that this script could be MUCH more secure. As it is, it would accept some client on whatever network the host is connected to using your host machine as a gateway to the guest vm.



    #!/bin/bash

    echo 1 > /proc/sys/net/ipv4/ip_forward

    iptables=`which iptables`

    $iptables -F

    /sbin/iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE

    $iptables -A FORWARD -i enp2s0 -o vboxnet0 -j ACCEPT
    $iptables -A FORWARD -i vboxnet0 -o enp2s0 -j ACCEPT





    share|improve this answer





















    • IvanIvan thanks for your detailed comment, I'll let you know if it worked!
      – Beach Chicken
      Jun 29 '17 at 6:42
















    0














    OK, so there are 2 ways of sort of doing this.



    1) Use the VirtualBox NAT network on the client. This doesn't provide a direct route from your host machine, but you can set preferences to forward ports. Kind of a pain to set up, but if the host machine was Windows or a Mac this is what I'd probably do, mostly because I'm not sure on firewalling/natting/routing capabilities on those systems (pretty sure Mac wouldn't have an issue, but Windows is unknown to me)



    2) Use the VirtualBox Host Only Network. From your description, this may be better. Be aware that you will need to change the firewall script to point to whatever device is connected.... Here's teh details.



    On the host machine, first set up the Host Only Network in your vbox preferences. In the Manager, click File and then Preferences, and then select Network. Flip over to Host Only, and then add one if needed. Here's what mine looks like:
    hostonly network tab 1



    Hostonly tab2



    Next, on the host, configure the vboxnet0 interface. It automagically just happens for me, setting my host machine to the .1 address in the subnet. Here's output of ifconfig on my host, referencing my ethernet and vboxnet0 address.



    ifconfig info on host machine



    In your guest machine, set the network to some address in your subnet (even with the DHCP server enabled, this makes it easier to get gateway/dns server) and set a nameserver in the usual way (ie, edit /etc/network/interfaces and set the static address/netmask/gateway there, then edit /etc/resolv.conf and set a name server there).



    At this point, your host machine and your guest machine should be able to communicate back and forth with no issues. You may want to put appropriate entries in /etc/hosts so you don't have to enter the IPs everywhere...



    The last step is to get internet going for the guest. This is a simple matter of turning the host into a router. Since the vboxnet0 interface doesn't come up until vbox is up and running, you don't want to do this at boot time for the host.



    A simple firewall script to allow the guest vm to access the world, and the host machine can still access the world and the guest in the vboxonly network. Be aware that this script could be MUCH more secure. As it is, it would accept some client on whatever network the host is connected to using your host machine as a gateway to the guest vm.



    #!/bin/bash

    echo 1 > /proc/sys/net/ipv4/ip_forward

    iptables=`which iptables`

    $iptables -F

    /sbin/iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE

    $iptables -A FORWARD -i enp2s0 -o vboxnet0 -j ACCEPT
    $iptables -A FORWARD -i vboxnet0 -o enp2s0 -j ACCEPT





    share|improve this answer





















    • IvanIvan thanks for your detailed comment, I'll let you know if it worked!
      – Beach Chicken
      Jun 29 '17 at 6:42














    0












    0








    0






    OK, so there are 2 ways of sort of doing this.



    1) Use the VirtualBox NAT network on the client. This doesn't provide a direct route from your host machine, but you can set preferences to forward ports. Kind of a pain to set up, but if the host machine was Windows or a Mac this is what I'd probably do, mostly because I'm not sure on firewalling/natting/routing capabilities on those systems (pretty sure Mac wouldn't have an issue, but Windows is unknown to me)



    2) Use the VirtualBox Host Only Network. From your description, this may be better. Be aware that you will need to change the firewall script to point to whatever device is connected.... Here's teh details.



    On the host machine, first set up the Host Only Network in your vbox preferences. In the Manager, click File and then Preferences, and then select Network. Flip over to Host Only, and then add one if needed. Here's what mine looks like:
    hostonly network tab 1



    Hostonly tab2



    Next, on the host, configure the vboxnet0 interface. It automagically just happens for me, setting my host machine to the .1 address in the subnet. Here's output of ifconfig on my host, referencing my ethernet and vboxnet0 address.



    ifconfig info on host machine



    In your guest machine, set the network to some address in your subnet (even with the DHCP server enabled, this makes it easier to get gateway/dns server) and set a nameserver in the usual way (ie, edit /etc/network/interfaces and set the static address/netmask/gateway there, then edit /etc/resolv.conf and set a name server there).



    At this point, your host machine and your guest machine should be able to communicate back and forth with no issues. You may want to put appropriate entries in /etc/hosts so you don't have to enter the IPs everywhere...



    The last step is to get internet going for the guest. This is a simple matter of turning the host into a router. Since the vboxnet0 interface doesn't come up until vbox is up and running, you don't want to do this at boot time for the host.



    A simple firewall script to allow the guest vm to access the world, and the host machine can still access the world and the guest in the vboxonly network. Be aware that this script could be MUCH more secure. As it is, it would accept some client on whatever network the host is connected to using your host machine as a gateway to the guest vm.



    #!/bin/bash

    echo 1 > /proc/sys/net/ipv4/ip_forward

    iptables=`which iptables`

    $iptables -F

    /sbin/iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE

    $iptables -A FORWARD -i enp2s0 -o vboxnet0 -j ACCEPT
    $iptables -A FORWARD -i vboxnet0 -o enp2s0 -j ACCEPT





    share|improve this answer












    OK, so there are 2 ways of sort of doing this.



    1) Use the VirtualBox NAT network on the client. This doesn't provide a direct route from your host machine, but you can set preferences to forward ports. Kind of a pain to set up, but if the host machine was Windows or a Mac this is what I'd probably do, mostly because I'm not sure on firewalling/natting/routing capabilities on those systems (pretty sure Mac wouldn't have an issue, but Windows is unknown to me)



    2) Use the VirtualBox Host Only Network. From your description, this may be better. Be aware that you will need to change the firewall script to point to whatever device is connected.... Here's teh details.



    On the host machine, first set up the Host Only Network in your vbox preferences. In the Manager, click File and then Preferences, and then select Network. Flip over to Host Only, and then add one if needed. Here's what mine looks like:
    hostonly network tab 1



    Hostonly tab2



    Next, on the host, configure the vboxnet0 interface. It automagically just happens for me, setting my host machine to the .1 address in the subnet. Here's output of ifconfig on my host, referencing my ethernet and vboxnet0 address.



    ifconfig info on host machine



    In your guest machine, set the network to some address in your subnet (even with the DHCP server enabled, this makes it easier to get gateway/dns server) and set a nameserver in the usual way (ie, edit /etc/network/interfaces and set the static address/netmask/gateway there, then edit /etc/resolv.conf and set a name server there).



    At this point, your host machine and your guest machine should be able to communicate back and forth with no issues. You may want to put appropriate entries in /etc/hosts so you don't have to enter the IPs everywhere...



    The last step is to get internet going for the guest. This is a simple matter of turning the host into a router. Since the vboxnet0 interface doesn't come up until vbox is up and running, you don't want to do this at boot time for the host.



    A simple firewall script to allow the guest vm to access the world, and the host machine can still access the world and the guest in the vboxonly network. Be aware that this script could be MUCH more secure. As it is, it would accept some client on whatever network the host is connected to using your host machine as a gateway to the guest vm.



    #!/bin/bash

    echo 1 > /proc/sys/net/ipv4/ip_forward

    iptables=`which iptables`

    $iptables -F

    /sbin/iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE

    $iptables -A FORWARD -i enp2s0 -o vboxnet0 -j ACCEPT
    $iptables -A FORWARD -i vboxnet0 -o enp2s0 -j ACCEPT






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 29 '17 at 0:26









    ivanivanivanivan

    1,19917




    1,19917












    • IvanIvan thanks for your detailed comment, I'll let you know if it worked!
      – Beach Chicken
      Jun 29 '17 at 6:42


















    • IvanIvan thanks for your detailed comment, I'll let you know if it worked!
      – Beach Chicken
      Jun 29 '17 at 6:42
















    IvanIvan thanks for your detailed comment, I'll let you know if it worked!
    – Beach Chicken
    Jun 29 '17 at 6:42




    IvanIvan thanks for your detailed comment, I'll let you know if it worked!
    – Beach Chicken
    Jun 29 '17 at 6:42













    0














    I was struggling with this problem till a few days back. To fix this, a simple setup would require using two adapters on the guest.




    1. NAT: This would enable communication from the guest to external networks and also guest to host. To view the IP to use for communicating with the host, view the host’s IP in the ifconfig / ipconfig output on the guest. This is the gateway for the NAT network. This would not show up in ifconfig on the host since a VirtualBox creates a NAT network for each of the VMs.


    2. Host Only: This would allow communication between the host and the guest. By default VirtualBox assigns guest IPs using DHCP, but you can assign static IP for the guest using an IP below 192.168.56.100



    You may also set up a third optional adapter internal if you have more than one guest and you would like to communicate between guests. Here is the question I had asked last week regarding this issue: *Edit* Make virtualbox host only network bidirectional






    share|improve this answer




























      0














      I was struggling with this problem till a few days back. To fix this, a simple setup would require using two adapters on the guest.




      1. NAT: This would enable communication from the guest to external networks and also guest to host. To view the IP to use for communicating with the host, view the host’s IP in the ifconfig / ipconfig output on the guest. This is the gateway for the NAT network. This would not show up in ifconfig on the host since a VirtualBox creates a NAT network for each of the VMs.


      2. Host Only: This would allow communication between the host and the guest. By default VirtualBox assigns guest IPs using DHCP, but you can assign static IP for the guest using an IP below 192.168.56.100



      You may also set up a third optional adapter internal if you have more than one guest and you would like to communicate between guests. Here is the question I had asked last week regarding this issue: *Edit* Make virtualbox host only network bidirectional






      share|improve this answer


























        0












        0








        0






        I was struggling with this problem till a few days back. To fix this, a simple setup would require using two adapters on the guest.




        1. NAT: This would enable communication from the guest to external networks and also guest to host. To view the IP to use for communicating with the host, view the host’s IP in the ifconfig / ipconfig output on the guest. This is the gateway for the NAT network. This would not show up in ifconfig on the host since a VirtualBox creates a NAT network for each of the VMs.


        2. Host Only: This would allow communication between the host and the guest. By default VirtualBox assigns guest IPs using DHCP, but you can assign static IP for the guest using an IP below 192.168.56.100



        You may also set up a third optional adapter internal if you have more than one guest and you would like to communicate between guests. Here is the question I had asked last week regarding this issue: *Edit* Make virtualbox host only network bidirectional






        share|improve this answer














        I was struggling with this problem till a few days back. To fix this, a simple setup would require using two adapters on the guest.




        1. NAT: This would enable communication from the guest to external networks and also guest to host. To view the IP to use for communicating with the host, view the host’s IP in the ifconfig / ipconfig output on the guest. This is the gateway for the NAT network. This would not show up in ifconfig on the host since a VirtualBox creates a NAT network for each of the VMs.


        2. Host Only: This would allow communication between the host and the guest. By default VirtualBox assigns guest IPs using DHCP, but you can assign static IP for the guest using an IP below 192.168.56.100



        You may also set up a third optional adapter internal if you have more than one guest and you would like to communicate between guests. Here is the question I had asked last week regarding this issue: *Edit* Make virtualbox host only network bidirectional







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 '17 at 15:05









        Scott

        15.6k113889




        15.6k113889










        answered Nov 19 '17 at 14:43









        RaviRavi

        388




        388






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1223801%2fvirtualbox-nat-and-host-only-connection%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

            How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...