0

(This is a beginner's question)

I would like to have two (or more) virtual machines (KVM qemu based) on a dedicated server (Hetzner).

How many IPv4 address do I need?

I have one main IPv4 address. From what I understand I need additional IPv4 addresses to establish a bridge network for the virtual machines. Do I need a single IPv4 address for each virtual machine?

My use case is to have a database server and the web server on different virtual machines. So the virtual machines should be able to communicate with each other and to communicate with the outside world (internet).

So to say it in different words: I'd like to ssh into the host and from there into the virtual machines but the :80 and :443 traffic should go to the HTML-vm and the (local) database listens on a MYSQL-vm.

2
  • "the virtual machines should be able to communicate with each other and to communicate with the outside world (internet)" - that can be achieved with NAT. The real question is whether these machines need to be directly reachable from the outside world
    – roaima
    Sep 27, 2022 at 12:35
  • @roaima I don't think it is necessary to reach the virtual machines from outside world, except for traffic to port 80/443. Might port forwarding be the way to go here?
    – topskip
    Sep 27, 2022 at 12:38

1 Answer 1

1

You say that "the virtual machines should be able to communicate with each other and to communicate with the outside world (internet)". This can be achieved with NAT. The real question is whether these machines need to be directly reachable from the outside world, and you've indicated that you "don't think it is necessary to reach the virtual machines from outside world, except for traffic to port 80/443".

On that basis I would say that you could hide all the VMs behind your host's single public IP address, and use an internal Host/VM bridged network to allow the Host and the two VMs to communicate directly with each other.

  • Host accepts ssh traffic (not necessarily on port 22)
  • Host forwards web traffic on ports 80/443 to the VM web server
  • Host masquerades (SNAT) other traffic outbound from the VMs to the Internet

The Host will have two interfaces: the public one and an internal-only one that provides bridging for the two VMs. The VMs will use the internal Host interface as their default route outwards, with the Host forwarding new traffic out, but proxying selected traffic inward.

2
  • Thank you. I'll give it a try and report back.
    – topskip
    Sep 27, 2022 at 12:58
  • I have used multipass on Ubuntu 22.04 to install two virtual machines and enabled port forwarding for 80/443 to one machine with ufw (maurow.bitbucket.io/notes/multipass-vm-port-forwarding.html has an example setup). That was much easier than I thought. Thank you for your answer!
    – topskip
    Sep 28, 2022 at 7:51

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.