VirtualBox: two network interfaces (NAT and host-only ones) in a Debian guest on Ubuntu

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
42
down vote

favorite
25












I created a Debian VM on VirtualBox with two interfaces: a NAT one (for accessing internet) and a host-only one. However, I do not know how to make both interfaces work at the same time. If I the define the host-only as the adapter 1, I can access my VM from the host but not the internet; if I define the NAT one as adapter 1, I can access the internet but cannot reach my guest Debian.



So, how could I make both interfaces work together?



Note: I am still trying to map some port from my host to the SSH port from my guest SO, so there is no need to suggest me to do it :)



EDIT: This is the output of ifconfig when the first adapter is the host-only one:



eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:495 errors:0 dropped:0 overruns:0 frame:0
TX packets:206 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:48187 (47.0 KiB) TX bytes:38222 (37.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)


This is the output of netstat -nr when the first adapter is the host-only one:



Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


This is the output of ifconfig when the first adapter is the NAT one:



eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:53 errors:0 dropped:0 overruns:0 frame:0
TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6076 (5.9 KiB) TX bytes:5526 (5.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1664 (1.6 KiB) TX bytes:1664 (1.6 KiB)


This is the output of netstat -nr when the first adapter is the NAT one:



Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0









share|improve this question



























    up vote
    42
    down vote

    favorite
    25












    I created a Debian VM on VirtualBox with two interfaces: a NAT one (for accessing internet) and a host-only one. However, I do not know how to make both interfaces work at the same time. If I the define the host-only as the adapter 1, I can access my VM from the host but not the internet; if I define the NAT one as adapter 1, I can access the internet but cannot reach my guest Debian.



    So, how could I make both interfaces work together?



    Note: I am still trying to map some port from my host to the SSH port from my guest SO, so there is no need to suggest me to do it :)



    EDIT: This is the output of ifconfig when the first adapter is the host-only one:



    eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
    inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
    inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:495 errors:0 dropped:0 overruns:0 frame:0
    TX packets:206 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:48187 (47.0 KiB) TX bytes:38222 (37.3 KiB)

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:8 errors:0 dropped:0 overruns:0 frame:0
    TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)


    This is the output of netstat -nr when the first adapter is the host-only one:



    Kernel IP routing table
    Destination Gateway Genmask Flags MSS Window irtt Iface
    192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


    This is the output of ifconfig when the first adapter is the NAT one:



    eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
    inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
    inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:53 errors:0 dropped:0 overruns:0 frame:0
    TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:6076 (5.9 KiB) TX bytes:5526 (5.3 KiB)

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:16 errors:0 dropped:0 overruns:0 frame:0
    TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:1664 (1.6 KiB) TX bytes:1664 (1.6 KiB)


    This is the output of netstat -nr when the first adapter is the NAT one:



    Kernel IP routing table
    Destination Gateway Genmask Flags MSS Window irtt Iface
    10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
    0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0









    share|improve this question

























      up vote
      42
      down vote

      favorite
      25









      up vote
      42
      down vote

      favorite
      25






      25





      I created a Debian VM on VirtualBox with two interfaces: a NAT one (for accessing internet) and a host-only one. However, I do not know how to make both interfaces work at the same time. If I the define the host-only as the adapter 1, I can access my VM from the host but not the internet; if I define the NAT one as adapter 1, I can access the internet but cannot reach my guest Debian.



      So, how could I make both interfaces work together?



      Note: I am still trying to map some port from my host to the SSH port from my guest SO, so there is no need to suggest me to do it :)



      EDIT: This is the output of ifconfig when the first adapter is the host-only one:



      eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
      inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:495 errors:0 dropped:0 overruns:0 frame:0
      TX packets:206 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:48187 (47.0 KiB) TX bytes:38222 (37.3 KiB)

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:8 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)


      This is the output of netstat -nr when the first adapter is the host-only one:



      Kernel IP routing table
      Destination Gateway Genmask Flags MSS Window irtt Iface
      192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


      This is the output of ifconfig when the first adapter is the NAT one:



      eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
      inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:53 errors:0 dropped:0 overruns:0 frame:0
      TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:6076 (5.9 KiB) TX bytes:5526 (5.3 KiB)

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:16 errors:0 dropped:0 overruns:0 frame:0
      TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:1664 (1.6 KiB) TX bytes:1664 (1.6 KiB)


      This is the output of netstat -nr when the first adapter is the NAT one:



      Kernel IP routing table
      Destination Gateway Genmask Flags MSS Window irtt Iface
      10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
      0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0









      share|improve this question















      I created a Debian VM on VirtualBox with two interfaces: a NAT one (for accessing internet) and a host-only one. However, I do not know how to make both interfaces work at the same time. If I the define the host-only as the adapter 1, I can access my VM from the host but not the internet; if I define the NAT one as adapter 1, I can access the internet but cannot reach my guest Debian.



      So, how could I make both interfaces work together?



      Note: I am still trying to map some port from my host to the SSH port from my guest SO, so there is no need to suggest me to do it :)



      EDIT: This is the output of ifconfig when the first adapter is the host-only one:



      eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
      inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:495 errors:0 dropped:0 overruns:0 frame:0
      TX packets:206 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:48187 (47.0 KiB) TX bytes:38222 (37.3 KiB)

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:8 errors:0 dropped:0 overruns:0 frame:0
      TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:560 (560.0 B) TX bytes:560 (560.0 B)


      This is the output of netstat -nr when the first adapter is the host-only one:



      Kernel IP routing table
      Destination Gateway Genmask Flags MSS Window irtt Iface
      192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


      This is the output of ifconfig when the first adapter is the NAT one:



      eth0 Link encap:Ethernet HWaddr 08:00:27:f6:b2:45 
      inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
      inet6 addr: fe80::a00:27ff:fef6:b245/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
      RX packets:53 errors:0 dropped:0 overruns:0 frame:0
      TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:6076 (5.9 KiB) TX bytes:5526 (5.3 KiB)

      lo Link encap:Local Loopback
      inet addr:127.0.0.1 Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING MTU:16436 Metric:1
      RX packets:16 errors:0 dropped:0 overruns:0 frame:0
      TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:1664 (1.6 KiB) TX bytes:1664 (1.6 KiB)


      This is the output of netstat -nr when the first adapter is the NAT one:



      Kernel IP routing table
      Destination Gateway Genmask Flags MSS Window irtt Iface
      10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
      0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0






      ubuntu debian networking virtualbox virtual-machine






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 12 '14 at 18:04

























      asked Apr 23 '12 at 14:43









      brandizzi

      1,25711422




      1,25711422




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          41
          down vote



          accepted










          The solution was pretty simple: I just had to add the following lines in Debian virtual machine's /etc/network/interfaces file:



          allow-hotplug eth1
          iface eth1 inet dhcp


          The second line instructs the interface to obtain an IP via DHCP. The first line loads the interface at boot time.



          To apply the changes to a running system, invoke:



          ifup eth1


          The name for the eth1 interface may vary, use ifconfig -a to list all available interfaces.



          EDIT: full /etc/network/interfaces:



          # This file describes the network interfaces available on your system
          # and how to activate them. For more information, see interfaces(5).

          # The loopback network interface
          auto lo
          iface lo inet loopback

          # The primary network interface
          allow-hotplug eth0
          iface eth0 inet dhcp

          allow-hotplug eth1
          iface eth1 inet dhcp





          share|improve this answer


















          • 1




            I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
            – davolfman
            Nov 17 '12 at 0:42











          • can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
            – John Nicholas
            Apr 1 '14 at 9:19










          • @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
            – brandizzi
            Apr 1 '14 at 18:54










          • cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
            – John Nicholas
            Apr 16 '14 at 9:56











          • Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
            – user152468
            Mar 25 '15 at 15:11

















          up vote
          10
          down vote













          I was facing similar problem with my Ubuntu 14.04 VM, and Solution suggested by @brandizzi for Debian worked with little change.



          EDIT: file /etc/network/interfaces:


          # This file describes the network interfaces available on your system
          # and how to activate them. For more information, see interfaces(5).

          # The loopback network interface
          auto lo
          iface lo inet loopback

          # The primary network interface
          auto eth0
          iface eth0 inet dhcp

          auto eth1
          iface eth1 inet dhcp


          For UBUNTU 16.04



          Run command



          ifconfig -a


          Look for new interface like in my case it is 'enp0s8'



          EDIT file /etc/network/interfaces:

          # The loopback network interface
          auto lo
          iface lo inet loopback

          # The primary network interface
          auto enp0s3
          iface enp0s3 inet dhcp

          auto enp0s8
          iface enp0s8 inet dhcp





          share|improve this answer


















          • 3




            This also now applies to Debian 9+ (Ubuntu 16 setup)
            – Maksim Luzik
            Feb 21 at 12:00

















          up vote
          3
          down vote













          Both adapter should be configured in Debian



          It seems that in both case you only have one adapter configured, hence your problem.



          Create 2 adapters in the VirtualBox configuration of your VM and then start it. If you see only one configured adapter when using ifconfig (a single eth0, no eth1 too), then you should use the network configuration tool for Debian (Network Manager, ifupdown, etc.) to configure both interface in DHCP. So you should have eth0 and eth1 in DHCP.






          share|improve this answer



























            up vote
            0
            down vote













            Ensure you are using separate Private Address space subnets for each interface.



            So for example, for the interface that is NAT, you could use an address in 192.168.0.0/16 space.



            The interface that is 'host only' could be in the 10.0.0.0/24 space.






            share|improve this answer




















            • Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
              – brandizzi
              Apr 23 '12 at 18:58











            • Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
              – George M
              Apr 23 '12 at 19:45










            • Ok, I added the output of the commands to the question.
              – brandizzi
              Apr 24 '12 at 13:17










            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37122%2fvirtualbox-two-network-interfaces-nat-and-host-only-ones-in-a-debian-guest-on%23new-answer', 'question_page');

            );

            Post as a guest






























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            41
            down vote



            accepted










            The solution was pretty simple: I just had to add the following lines in Debian virtual machine's /etc/network/interfaces file:



            allow-hotplug eth1
            iface eth1 inet dhcp


            The second line instructs the interface to obtain an IP via DHCP. The first line loads the interface at boot time.



            To apply the changes to a running system, invoke:



            ifup eth1


            The name for the eth1 interface may vary, use ifconfig -a to list all available interfaces.



            EDIT: full /etc/network/interfaces:



            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            allow-hotplug eth0
            iface eth0 inet dhcp

            allow-hotplug eth1
            iface eth1 inet dhcp





            share|improve this answer


















            • 1




              I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
              – davolfman
              Nov 17 '12 at 0:42











            • can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
              – John Nicholas
              Apr 1 '14 at 9:19










            • @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
              – brandizzi
              Apr 1 '14 at 18:54










            • cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
              – John Nicholas
              Apr 16 '14 at 9:56











            • Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
              – user152468
              Mar 25 '15 at 15:11














            up vote
            41
            down vote



            accepted










            The solution was pretty simple: I just had to add the following lines in Debian virtual machine's /etc/network/interfaces file:



            allow-hotplug eth1
            iface eth1 inet dhcp


            The second line instructs the interface to obtain an IP via DHCP. The first line loads the interface at boot time.



            To apply the changes to a running system, invoke:



            ifup eth1


            The name for the eth1 interface may vary, use ifconfig -a to list all available interfaces.



            EDIT: full /etc/network/interfaces:



            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            allow-hotplug eth0
            iface eth0 inet dhcp

            allow-hotplug eth1
            iface eth1 inet dhcp





            share|improve this answer


















            • 1




              I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
              – davolfman
              Nov 17 '12 at 0:42











            • can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
              – John Nicholas
              Apr 1 '14 at 9:19










            • @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
              – brandizzi
              Apr 1 '14 at 18:54










            • cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
              – John Nicholas
              Apr 16 '14 at 9:56











            • Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
              – user152468
              Mar 25 '15 at 15:11












            up vote
            41
            down vote



            accepted







            up vote
            41
            down vote



            accepted






            The solution was pretty simple: I just had to add the following lines in Debian virtual machine's /etc/network/interfaces file:



            allow-hotplug eth1
            iface eth1 inet dhcp


            The second line instructs the interface to obtain an IP via DHCP. The first line loads the interface at boot time.



            To apply the changes to a running system, invoke:



            ifup eth1


            The name for the eth1 interface may vary, use ifconfig -a to list all available interfaces.



            EDIT: full /etc/network/interfaces:



            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            allow-hotplug eth0
            iface eth0 inet dhcp

            allow-hotplug eth1
            iface eth1 inet dhcp





            share|improve this answer














            The solution was pretty simple: I just had to add the following lines in Debian virtual machine's /etc/network/interfaces file:



            allow-hotplug eth1
            iface eth1 inet dhcp


            The second line instructs the interface to obtain an IP via DHCP. The first line loads the interface at boot time.



            To apply the changes to a running system, invoke:



            ifup eth1


            The name for the eth1 interface may vary, use ifconfig -a to list all available interfaces.



            EDIT: full /etc/network/interfaces:



            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            allow-hotplug eth0
            iface eth0 inet dhcp

            allow-hotplug eth1
            iface eth1 inet dhcp






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 21 at 16:25









            krlmlr

            387316




            387316










            answered Apr 24 '12 at 18:58









            brandizzi

            1,25711422




            1,25711422







            • 1




              I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
              – davolfman
              Nov 17 '12 at 0:42











            • can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
              – John Nicholas
              Apr 1 '14 at 9:19










            • @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
              – brandizzi
              Apr 1 '14 at 18:54










            • cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
              – John Nicholas
              Apr 16 '14 at 9:56











            • Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
              – user152468
              Mar 25 '15 at 15:11












            • 1




              I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
              – davolfman
              Nov 17 '12 at 0:42











            • can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
              – John Nicholas
              Apr 1 '14 at 9:19










            • @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
              – brandizzi
              Apr 1 '14 at 18:54










            • cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
              – John Nicholas
              Apr 16 '14 at 9:56











            • Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
              – user152468
              Mar 25 '15 at 15:11







            1




            1




            I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
            – davolfman
            Nov 17 '12 at 0:42





            I can confirm. Debian doesn't setup the second interface in /etc/network/interfaces. Fixed my problem, thanks. For potential debugging, this is two virtio interfaces provided by Virtualbox. One is the NAT interface used for internet access (NATs are provided individually by vbox), the other is a host-only network with DHCP in a completely different private IP class. Debian version tested 6.0.6 x64.
            – davolfman
            Nov 17 '12 at 0:42













            can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
            – John Nicholas
            Apr 1 '14 at 9:19




            can you please post your whole /etc/network/interfaces please. Have been struggling with this for 2 days now.
            – John Nicholas
            Apr 1 '14 at 9:19












            @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
            – brandizzi
            Apr 1 '14 at 18:54




            @JohnNicholas done. Note that you should edit the guest /etc/network/interfaces file.
            – brandizzi
            Apr 1 '14 at 18:54












            cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
            – John Nicholas
            Apr 16 '14 at 9:56





            cheers, mine was the same. My problem was that when i had the NAT adapter first in vbox the other (host) adapter would try to use the dhcp server on that adapter and all would go wrong. When I ordered the adapters in vbox as host only then NAT all started to work (irrespective of their ordering in linux interestingly enough). Netctl didn't have this problem in another vm.
            – John Nicholas
            Apr 16 '14 at 9:56













            Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
            – user152468
            Mar 25 '15 at 15:11




            Under centOs there is no directory /etc/network. Still I would like to have both the NAT networking and host-only working. When I do ifconfig, I can only see one interface. Any ideas what I need to do on CentOs?
            – user152468
            Mar 25 '15 at 15:11












            up vote
            10
            down vote













            I was facing similar problem with my Ubuntu 14.04 VM, and Solution suggested by @brandizzi for Debian worked with little change.



            EDIT: file /etc/network/interfaces:


            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto eth0
            iface eth0 inet dhcp

            auto eth1
            iface eth1 inet dhcp


            For UBUNTU 16.04



            Run command



            ifconfig -a


            Look for new interface like in my case it is 'enp0s8'



            EDIT file /etc/network/interfaces:

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto enp0s3
            iface enp0s3 inet dhcp

            auto enp0s8
            iface enp0s8 inet dhcp





            share|improve this answer


















            • 3




              This also now applies to Debian 9+ (Ubuntu 16 setup)
              – Maksim Luzik
              Feb 21 at 12:00














            up vote
            10
            down vote













            I was facing similar problem with my Ubuntu 14.04 VM, and Solution suggested by @brandizzi for Debian worked with little change.



            EDIT: file /etc/network/interfaces:


            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto eth0
            iface eth0 inet dhcp

            auto eth1
            iface eth1 inet dhcp


            For UBUNTU 16.04



            Run command



            ifconfig -a


            Look for new interface like in my case it is 'enp0s8'



            EDIT file /etc/network/interfaces:

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto enp0s3
            iface enp0s3 inet dhcp

            auto enp0s8
            iface enp0s8 inet dhcp





            share|improve this answer


















            • 3




              This also now applies to Debian 9+ (Ubuntu 16 setup)
              – Maksim Luzik
              Feb 21 at 12:00












            up vote
            10
            down vote










            up vote
            10
            down vote









            I was facing similar problem with my Ubuntu 14.04 VM, and Solution suggested by @brandizzi for Debian worked with little change.



            EDIT: file /etc/network/interfaces:


            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto eth0
            iface eth0 inet dhcp

            auto eth1
            iface eth1 inet dhcp


            For UBUNTU 16.04



            Run command



            ifconfig -a


            Look for new interface like in my case it is 'enp0s8'



            EDIT file /etc/network/interfaces:

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto enp0s3
            iface enp0s3 inet dhcp

            auto enp0s8
            iface enp0s8 inet dhcp





            share|improve this answer














            I was facing similar problem with my Ubuntu 14.04 VM, and Solution suggested by @brandizzi for Debian worked with little change.



            EDIT: file /etc/network/interfaces:


            # This file describes the network interfaces available on your system
            # and how to activate them. For more information, see interfaces(5).

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto eth0
            iface eth0 inet dhcp

            auto eth1
            iface eth1 inet dhcp


            For UBUNTU 16.04



            Run command



            ifconfig -a


            Look for new interface like in my case it is 'enp0s8'



            EDIT file /etc/network/interfaces:

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The primary network interface
            auto enp0s3
            iface enp0s3 inet dhcp

            auto enp0s8
            iface enp0s8 inet dhcp






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 1 '17 at 18:36

























            answered Mar 7 '17 at 18:08









            Pandurang Patil

            20125




            20125







            • 3




              This also now applies to Debian 9+ (Ubuntu 16 setup)
              – Maksim Luzik
              Feb 21 at 12:00












            • 3




              This also now applies to Debian 9+ (Ubuntu 16 setup)
              – Maksim Luzik
              Feb 21 at 12:00







            3




            3




            This also now applies to Debian 9+ (Ubuntu 16 setup)
            – Maksim Luzik
            Feb 21 at 12:00




            This also now applies to Debian 9+ (Ubuntu 16 setup)
            – Maksim Luzik
            Feb 21 at 12:00










            up vote
            3
            down vote













            Both adapter should be configured in Debian



            It seems that in both case you only have one adapter configured, hence your problem.



            Create 2 adapters in the VirtualBox configuration of your VM and then start it. If you see only one configured adapter when using ifconfig (a single eth0, no eth1 too), then you should use the network configuration tool for Debian (Network Manager, ifupdown, etc.) to configure both interface in DHCP. So you should have eth0 and eth1 in DHCP.






            share|improve this answer
























              up vote
              3
              down vote













              Both adapter should be configured in Debian



              It seems that in both case you only have one adapter configured, hence your problem.



              Create 2 adapters in the VirtualBox configuration of your VM and then start it. If you see only one configured adapter when using ifconfig (a single eth0, no eth1 too), then you should use the network configuration tool for Debian (Network Manager, ifupdown, etc.) to configure both interface in DHCP. So you should have eth0 and eth1 in DHCP.






              share|improve this answer






















                up vote
                3
                down vote










                up vote
                3
                down vote









                Both adapter should be configured in Debian



                It seems that in both case you only have one adapter configured, hence your problem.



                Create 2 adapters in the VirtualBox configuration of your VM and then start it. If you see only one configured adapter when using ifconfig (a single eth0, no eth1 too), then you should use the network configuration tool for Debian (Network Manager, ifupdown, etc.) to configure both interface in DHCP. So you should have eth0 and eth1 in DHCP.






                share|improve this answer












                Both adapter should be configured in Debian



                It seems that in both case you only have one adapter configured, hence your problem.



                Create 2 adapters in the VirtualBox configuration of your VM and then start it. If you see only one configured adapter when using ifconfig (a single eth0, no eth1 too), then you should use the network configuration tool for Debian (Network Manager, ifupdown, etc.) to configure both interface in DHCP. So you should have eth0 and eth1 in DHCP.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 24 '12 at 13:54









                Huygens

                4,69311930




                4,69311930




















                    up vote
                    0
                    down vote













                    Ensure you are using separate Private Address space subnets for each interface.



                    So for example, for the interface that is NAT, you could use an address in 192.168.0.0/16 space.



                    The interface that is 'host only' could be in the 10.0.0.0/24 space.






                    share|improve this answer




















                    • Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
                      – brandizzi
                      Apr 23 '12 at 18:58











                    • Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
                      – George M
                      Apr 23 '12 at 19:45










                    • Ok, I added the output of the commands to the question.
                      – brandizzi
                      Apr 24 '12 at 13:17














                    up vote
                    0
                    down vote













                    Ensure you are using separate Private Address space subnets for each interface.



                    So for example, for the interface that is NAT, you could use an address in 192.168.0.0/16 space.



                    The interface that is 'host only' could be in the 10.0.0.0/24 space.






                    share|improve this answer




















                    • Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
                      – brandizzi
                      Apr 23 '12 at 18:58











                    • Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
                      – George M
                      Apr 23 '12 at 19:45










                    • Ok, I added the output of the commands to the question.
                      – brandizzi
                      Apr 24 '12 at 13:17












                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Ensure you are using separate Private Address space subnets for each interface.



                    So for example, for the interface that is NAT, you could use an address in 192.168.0.0/16 space.



                    The interface that is 'host only' could be in the 10.0.0.0/24 space.






                    share|improve this answer












                    Ensure you are using separate Private Address space subnets for each interface.



                    So for example, for the interface that is NAT, you could use an address in 192.168.0.0/16 space.



                    The interface that is 'host only' could be in the 10.0.0.0/24 space.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 23 '12 at 15:04









                    George M

                    8,79623247




                    8,79623247











                    • Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
                      – brandizzi
                      Apr 23 '12 at 18:58











                    • Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
                      – George M
                      Apr 23 '12 at 19:45










                    • Ok, I added the output of the commands to the question.
                      – brandizzi
                      Apr 24 '12 at 13:17
















                    • Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
                      – brandizzi
                      Apr 23 '12 at 18:58











                    • Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
                      – George M
                      Apr 23 '12 at 19:45










                    • Ok, I added the output of the commands to the question.
                      – brandizzi
                      Apr 24 '12 at 13:17















                    Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
                    – brandizzi
                    Apr 23 '12 at 18:58





                    Well, they are separated (my NAT space is 10.0.2.0/24 and my NAT is 192.168.56.0/24).
                    – brandizzi
                    Apr 23 '12 at 18:58













                    Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
                    – George M
                    Apr 23 '12 at 19:45




                    Can you edit your question to include the output of ifconfig and netstat -nr so we can see how the interfaces and routing are configured?
                    – George M
                    Apr 23 '12 at 19:45












                    Ok, I added the output of the commands to the question.
                    – brandizzi
                    Apr 24 '12 at 13:17




                    Ok, I added the output of the commands to the question.
                    – brandizzi
                    Apr 24 '12 at 13:17

















                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37122%2fvirtualbox-two-network-interfaces-nat-and-host-only-ones-in-a-debian-guest-on%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay