New to VirtualBox and VM, I am running Ubuntu with 14.04 on latest VirtualBox. I have 2 network adapters:

  1. Host-only
  2. NAT

I run the following command to install SSH:

$ sudo apt-get install openssh-server

gives this error:

'Could not resolve 'security.ubuntu.com'

So it cannot connect to the network. Do I have to do any port forwarding?

  • It doesn't necessarily mean you haven't got network connection, it might be that your DNS isn't working. Try: ping 8.8.8.8, if this works you have network (and internet) connection, – gogoud Nov 25 '15 at 6:52
  • Use bridging when setting up your virtual NICs and link them to the physical NIC that has internet access. Then set your VM network accordingly (e.g. DHCP vs. static). – schaiba Nov 25 '15 at 7:00
  • ping8.8.8.8 gives network unreachable.Being an application developer, and new to network settings, need specific instructions to connect to the network. – kakoli Nov 25 '15 at 8:13
  • See the link, to understand the theory vmware.com/support/ws5/doc/ws_net_configurations_bridged.html – Rui F Ribeiro Nov 25 '15 at 8:48
  • look at the image in this link forums.virtualbox.org/viewtopic.php?f=8&t=16619 – Rui F Ribeiro Nov 25 '15 at 8:50

The fact that you got a "Could not resolve" error suggests that your VM couldn't reach a DNS server. In the comments you say that you can't ping public addresses, which suggests that your VM isn't configured for network access. In my experience the simplest way to have a VirtualBox VM connect to the internet is to use the NAT interface.

You can do this via the GUI, but I'll include command-line examples for concreteness.

First let's remove all of network interface cards (for the sake of simplicity and so that we don't leave any room for a routing conflict):

for n in 1 2 3 4 5 6 7 8; do
    vboxmanage modifyvm "${VMNAME}" --nic${n} none
done

Now let's add a single NAT interface:

vboxmanage modifyvm "${VMNAME}" --nic1 NAT

Let's sanity-check the NIC configuration:

vboxmanage showvminfo "${VMNAME}" | grep '^NIC'

The output should something like this:

NIC 1:          MAC: 08002784C3DE, Attachment: NAT, Cable connected: on,
                Trace: off (file: none), Type: Am79C973, Reported speed: 0
                Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings: MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 2:           disabled
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled

Now, if you want, let's add a port-forwarding rule for ssh. Here is an example which maps port 2222 on the host to port 22 on the guest:

vboxmanage modifyvm "${VMNAME}" --natpf1 ssh,tcp,,2222,,22

Now boot the VM and then we'll test the network connection.

vboxmanage startvm "${VMNAME}"

Now try to ping a public host. Finally, install your Ubuntu package.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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