23

I am trying to set up a set of guests in VirtualBox, such that each of them can access the Internet as well as be visible to each other and to the host. I also want the guests to have static IP addresses.

Here's the procedure that I have followed so far:

  1. Switch off the DHCP Server feature of the Host-Only network to be used in this setup
  2. Change the IP address assigned to the host to 192.168.56.254
  3. Create a guest machine with 2 networking interface cards (NIC)
  4. Configure the 1st NIC to use NAT
  5. Configure the 2nd NIC to use Hot-Only Networking
  6. Install the OS (Ubuntu Server 13.10) on each of them
  7. Update the OS
  8. Configure the networking as follows by editing /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.56.1
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
gateway 192.168.56.254
dns-search cloudspace.local
dns-nameservers 8.8.8.8 8.8.4.4
  1. Save the file
  2. Reboot

When the guest boots up again, the Host-Only networking is working fine. The host/guest and guest/guest pairs of machines can ping each other, however the Internet isn't working as apt-get fails.

If I then issue a service networking restart command, the networking begins to work as it should.

What am I doing wrong?

I have tried switching the order in which the NICs appear in the /etc/network/interfaces file. I have also swapped the NAT/Host-Only Network around between the 2 NICs. Nothing worked.

The host is Windows 8.1 and the guest is Ubuntu Server 13.10. I have tried the same on Mac OS X with similar results.

I would greatly appreciate any help in this.

Update:

I have included the output from the following commands below, to help in diagnostics:

  • cat /etc/network/interfaces
  • ifconfig -a
  • route -n
$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.56.1
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
gateway 192.168.56.254

$ ifconfig -a
eth0      Link encap:Ethernet  HWaddr 08:00:27:75:47:64
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe75:4764/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1180 (1.1 KB)  TX bytes:1332 (1.3 KB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:93:98:d8
          inet addr:192.168.56.1  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe93:98d8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:140 errors:0 dropped:0 overruns:0 frame:0
          TX packets:225 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:14418 (14.4 KB)  TX bytes:27378 (27.3 KB)

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:65536  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:1184 (1.1 KB)  TX bytes:1184 (1.1 KB)

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.56.254  0.0.0.0         UG    0      0        0 eth1
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1

Update 2:

After I execute sudo service networking restart, the output from route -n becomes:

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.56.0    0.0.0.0         255.255.255.0   U     0      0        0 eth1

So how do I ensure this configuration on boot?

5 Answers 5

17

It would be easier to troubleshoot your problem if you posted the results you are getting when trying to ping an external address (like the Google DNS servers you're using), the current network settings, and your routing table.

/sbin/ifconfig -a
/sbin/route -n

Without knowing more this is a bit of a shot in the dark, but my guesses are that either a) you are not getting a DHCP address on eth0, or b) your gateway settings for eth1 are messing with the default route DHCP assigned.

If you're not getting a DHCP address for eth0, it's probably a misconfiguration in VirtualBox (like getting your adapters backwards).

Either way, you don't need a gateway or DNS settings assigned specifically for eth1 since that will be assigned by DHCP on eth0, so I would remove the gateway, dns-search, and dns-nameservers lines from your config. Your virtual machines will still be able to communicate without a gateway setting if they are on the same network and VirtualBox is set up right.

Edit: To make sure you don't have a gateway on eth1 after a reboot, remove lines from your eth1 block so that it looks like this:

auto eth1
iface eth1 inet static
address 192.168.56.1
netmask 255.255.255.0

When you're done, you won't have any gateway lines in your interfaces file.

2
  • I have added the diagnostics as you suggested. I think the correct answer is (b), i.e., the gateway settings for eth1 are messing with the default route DHCP assigned. Is there a solution to this? Apr 11, 2014 at 11:19
  • 1
    I have edited my answer to show the way your eth1 block should look in the interfaces file. You don't need the network or broadcast lines, and you shouldn't have the gateway line. Remove those three.
    – jkt123
    Apr 11, 2014 at 11:30
3

I came up with thissolution, which is the same as @jkt123's answer, and @Umar's question, but shorter. I'd appreciate feedback on it!

In virtualbox, enable both NAT and host-only networks. (BTW: It works on my win7 host. I don't know how to do that in linux host).

On the host - find the "host-only" interface's ip

ipconfig /all     # for windows host
ifconfig -a       # for linux host

In the guest, edit /etc/network/interfaces. The trick was reversing the order eth1 (host-only) comes BEFORE eth0 (internet/dhcp). I don't know why.

auto lo                        # keep the original loopback settings
iface lo ...                   # yeah, i don't remember, just keep it.

# ----> Ok, this is my addition <-----
auto eth1                      
allow-hotplug eth1             # i think hotplug it helps. not sure.
iface eth1 inet static
address 192.168.56.100         # arbitrary IP address between 2 and 254

auto eth0                      # This is the original content
iface eth0 inet dhcp           #  of this file, now at the end.

reboot.

0

First of all, I enabled both networks NAT with DHCP and host only network with static ip add 192.168.40.41.

Then, I followed with this command :

nano cat /etc/network/interfaces

I obtained this result:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth1
iface eth1 inet static
address 192.168.41.4
netmask 255.255.255.0

And before rebooting, I typed the following command:

sudo service networking restart

Then rebooted.

After I loaded to VM VirtualBox, both networks are working. I can connect to internet and I can connect to 192.168.40.41 through a web browser.

I hope this will be helpful to get nano editor:

sudo apt-get update
sudo apt-get install nano

Then just type nano in terminal to start it.

0

You have multiple default gateways assigned to different NICs. In general, "Default" means a preselected option. In this case, if a specified default gateway is defined to both NICs, it would not be a preselected option. In addition, this would also result in communication issues such as Asynchronous routing. I'm not sure how the Metric of both interfaces is set to 0, but it may be due to having both NICs with gateways. Microsoft's write-up about this is located here and the Metric feature has a number of factors that provide how it is determined for setting priorities. (Link: https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes)

In agreement to @jkt123 in the answered response, there is only 1 default gateway that should be assigned.

0

I've tried to set it by configuring /etc/network/interfaces but didn't work, Then I'd read about netplan then set my ip address in /etc/netplan/00-installer-config.yaml

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s10:
      dhcp4: true
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: true
    enp0s9:
      addresses:
      - 192.168.57.3/24
      nameservers: {}
  version: 2

It'd worked

You must log in to answer this question.

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