Machine 62: Ubuntu 16.04, has access to internet, can be accessed via the internet. On the 62 machine, there is VirtualBox with a VM (also Ubuntu).

I'd like the VM to behave like a 'normal' machine (ip-requests). I reserved a static IP for it, but now I'm not sure how to configure the interfaces of the host and the guest in a way I can ping the guest-machine like I would usually ping the host machine (via the reserved IP instead of 62...).

ReverseProxy worked for a while, but then I needed websockets over ports I don't know in advance. So now my next guess is NAT? ipforwarding? Bridged networks? Masquerading?

  • 1
    Bridged network. This should be in your VirtualBox documentation.
    – roaima
    Nov 23 '17 at 13:05
  • And how do I access the VM then from outside the host? I still cant ping the virtual machine, only the host.
    – Rhodarus
    Nov 23 '17 at 13:24
  • 1
    Then either you've not got a Bridged network, there's a firewall in the way, or you've not configured your guest's IP address on the correct vNIC to match your LAN subnet.
    – roaima
    Nov 23 '17 at 14:23

You've to create a bridged network between the Host and VM. The configuration varies on Hypervisor vendor.

In case you're using Oracle Virtual Box

  1. Open Oracle VM VirtualBox Manager, select the VM and go to network section.
  2. In Adopter 1 tab change the default NAT to Bridged Adopter and chose host's Network Adopter from Name drop-down. Apply it.
  3. Now configure network inside VirtualBox as per your ISP's configuration like static dynamic etc.

If you're using QEMU-KVM

  1. Open Virtual Machine Manager GUI tool (In case you're using GUI)
  2. Select the specific Virtual machine and Open it. Then select the NIC
  3. Chnage default NAT to Host Device xxxxxx: macvtap apply and then configure network inside Virtual Machine as per ISP's configuration.
  4. If you don't have GUI tool then use virsh edit virtual-machine-name and modify the configuration as described previously.

A third alternate is creating iptable NAT rule in host. Then forward all traffic towards that IP (which you want to assign to VM) to VM's internal IP address. You've to write a few iptables line, please google for it. But for me it's the least preferred method.

NOTE-1 Bridged Network and macvtap doesn't work with most of the WiFi adopters in host.

NOTE-2 In case of macvtap your host will be unreachable from VM and vice versa. Both of them will be reachable from outside network. Further, if you've multiple VM they will remain reachable to each other. This is the way macvtap works. To access VM's from host and vice versa create one more NAT adopter in case of Oracle VirtualBox and one more NIC with NAT for QEMU-KVM.

NOTE-3 For both Bridged Network and macvtap the host's network adopter must have an IP address reserved per VM, as the question already mentioned.

  • Thanks, that is super useful. I dont even know what the problem is, now I suspect: "Now configure network inside VirtualBox as per your ISP's configuration like static dynamic etc." I'll figure that out and will comment than next week or accept your answer. The hard part for me here is that I dont know my ISP, because I rented a dedicated server and there is no information about the ISP...
    – Rhodarus
    Nov 24 '17 at 11:12
  • Your hosting provider is your ISP. I've written a general procedure. In most case ISPs (as well as hosting providers) run their DHCP server, so network inside your VM shall be auto configured. Ensure that iptables is not blocking dhclint. If didn't get auto-configured ask your hosting provider for IP, Gateway etc. Search online "How to configure network in CentOS 7" for e.g.
    – Abhik Bose
    Nov 24 '17 at 11:21
  • I only got this answer: " wiki.ubuntu.com/KvmWithBridge " That's not the answer I hoped for. I even bought an extra ip, but my main ip has "gateway" and "broadcast" information attached, that new ip has neither. Just putting the information in "/etc/network/interfaces" did not work.
    – Rhodarus
    Nov 24 '17 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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