Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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? –  Umar Farooq Khawaja Apr 11 at 11:19
    
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 at 11:30
    
Brilliant, thanks! That sorted it out. –  Umar Farooq Khawaja Apr 11 at 15:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.