How to install Proxmox and create VMs with non failover IPs on your Hetzner server?

In many cases, if you want to deploy a software for your project, you have to use a server, or any PaaS related service. You can use Scaleway, as explained here, or any other cloud provider (Vultr, Digital Ocean, etc).

These solutions are easy to use, but the bill can rise very quickly if you deploy multiple cloud instances/droplets/VPS/VMs, or whatever you call a "virtualized machine" etc.

Today, I will show you an alternative, and how to create multiple VMs on your Hetzner dedicated server with non fail-over IPs. As a reminder, you can get a server with 32 GB RAM, and Core i7-4770 with 2x2 TB for €26.22 (ex. VAT).  

That's a superb deal, but you need another thing. You will need IPs for each of your VM. Hetzner offers additional IPs at €0.84/per IP(ex. VAT).

Update 28/07/2021: Hetzner announced new pricing policy for their dedicated server, including installation fees and price increase. Have a look at the dedicated page.

Please keep in mind that hosting services by yourself means that you will have to back up them, in order to avoid any data loss if you get a hardware issue. Hetzner, or any other server provider won't be responsible for your dataloss.

Disclaimer: This documentation was made only for Hetzner baremetal/dedicated servers, as their internal and network infrastructure isn't working as Leaseweb, OVH or Contabo ones.

Please note that this tutorial is based on this blogpost released on Udona blog (in French btw).

Prerequisite:
-have a Hetzner dedicated server
-have an active non-failover IPv4
-have basic skills in Unix/Linux system administration
-have basic skills in technical English

As a reminder, I will use few words:
-Hetzner Robot Konsole: that's the Hetzner's customer area where you can manage your server (https://robot.your-server.de)
-VM: Acronym for Virtual Machine (also called VPS, cloud instance, droplet, etc)
-Additional IP: that's an extra/additional IP that you've order to add on any of your VM.
-PVE: Acronym for Proxmox Virtual Environment GUI
-ISO: That's the OS image that you will download to create your VM

Warning: This procedure, and tutorial was made for Hetzner servers. If you're using an Online.net, OVH, or any other dedicated server, the configuration will be different. Feel free to poke me if you're using another provider, and you want a new tutorial.

Step 1: Boot your server in rescue mode

In order to install any OS, we have to use Hetzner Wizard, which is only reachable in rescue mode. There is no web installer wizard, so let's go.

Login to your Hetzner Robot Konsole. Once it's done, click on "rescue" tab of your server.

Then, select the "Linux" operating system, select "64 bit" architecture, and select your SSH key if you have one. If you don't have one, don't worry, the Hetzner Robot Konsole, will give you a temporary root password.

Then, click on "Activate rescue system". And that's all. Now, you have to reboot your Hetzner dedicated sever, by clicking on "Reset" tab.

Select "Execute an automatic hardware reset", and click on "send".
Don't worry, it will just reboot your dedicated server. You will also receive an email about it.

Step 2: Install Proxmox with Hetzner wizard

Once you've performed past steps, you will have to connect to your server via SSH. You have to type the following command (if you're on MacOS or any Unix based system).

ssh root@YourHetznerPVEIP

Otherwise, you will have to use Putty, and type the right IP.

That's it! You're now connected to your dedicated server.
Now, you have to launch the Hetzner wizard, simply type:

installimage

Scroll down with the down arrow, and select "Other", then click on "Enter".

Select the right Proxmox image that you want. Currently, the latest version is Debian Buster. Click on "Enter".

Then, a configuration file will appear. If you want to activate software RAID, don't touch at this line, otherwise, replace 1 per 0.

Also, please choose your RAID level:
-RAID 0 = You will don't get any RAID
Eg. if you have 4x2TB HDD, you will get 8TB available storage
-RAID 1 = You will have a RAID disk
Eg. if you have 4x2TB HDD, you will get 4TB available storage
-RAID 10 = You will get one disk as mirror, and one disk as a stripe
Eg. if you have 4x2TB HDD, you will get 4TB available storage (warning: RAID 10 is available if you only have at least 4 disks).

I strongly recommend you to choose a RAID 1, in order to get a fault tolerance.
Also, keep in mind that RAID 1 can't be considered as a backup disk.

Also, you will have to set a FQDN from your side. Please be sure that this domain has an A record pointing to your HetznerPVEIP.

Then, exit, save and your server will be installed. You will get a screen displayed with all steps, and once it's completed, it will automatically reboot.

Step 3: Set up your server/PVE network

Once your server is rebooted, connect you to your server, and let's configure your server/PVE network interfaces.

First, we will have to allow IPv4 re-routing on our server, type the following command:

sysctl -w net.ipv4.ip_forward=1

And once you've authorized it again, type the following command:

nano /etc/network/interfaces

And you will get a default network configuration file like that.

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback
iface lo inet6 loopback


#The default network configuration, dont modify it
auto enp4s0
iface enp4s0 inet static
  address YourHetznerPVEIP
  netmask 255.255.255.255
  gateway YourHetznerGateway 
  poitopoint YourHetznerGateway

iface enp4s0 inet6 static
  address YourHetznerPVEIPv6
  netmask 64
  gateway fe80::1
  
#Our new modifications, paste this part on this config file
auto vmbr0
iface vmbr0 inet static
  address YourHetznerPVEIP
  netmask 255.255.255.255
  bridge_ports none
  bridge_stp off
  bridge_fd 0
  up ip route add YourHetznerAdditionnalIP/32 dev vmbr0

As a reminder, for the following information:
-YourHetznerGateway : The default gateway, available on your Hetzner Robot Konsole (just move your mouse over the IP of your server, and it will be displayed)
-YourHetznerAdditionalIP : Your additional IP address that you've ordered on your Hetzner Robot Konsole.
-255.255.255.255 is the default netmask used in our case
-YourHetznerPVEIP: Your PVE (Proxmox Virtual Environment), your dedicated server IP.

Step 4: Download an ISO image

So, we've configured our network, we've installed Promox, so all is right.
Now, we want to create Virtual Machines, and we will have to download an ISO image. To do it, we have to log in to your Proxmox/PVE online GUI.

You can access to it via: https://YourHetznerPVEIP:8006

Once you're on this page, you will have to type your user (root), and your root password. If you haven't turned on it, please follow this tutorial.

On the sidebar, click on "Datacenter", then click on your server name (here: HyperSpaceMountain) and click on "Shell".

The shell displayed here, is only the serial console (as if you were connected in SSH to your instance).

Next step, let's jump on the right folder where ISOs images are stored.

 cd /var/lib/vz/template/iso/

Then, get any ISO URL, for example:

# Debian Stretch
https://cdimage.debian.org/cdimage/archive/9.13.0/amd64/iso-dvd/debian-9.13.0-amd64-DVD-1.iso
# Ubuntu 20.04 Server
https://releases.ubuntu.com/21.04/ubuntu-21.04-live-server-amd64.iso

Here, I want to download Debian Stretch image:

wget https://cdimage.debian.org/cdimage/archive/9.13.0/amd64/iso-dvd/debian-9.13.0-amd64-DVD-1.iso

Just to verify, you can list files, which are on this folder. All ISOs listed will be usable to create a VM. Here, I will be able to create a VM with this Debian Image.

root@hyperspacemountain /var/lib/vz/template/iso # ls
debian-9.13.0-amd64-DVD-1.iso

Step 4: Create a Linux VM

Once you've created, and installed your Linux VM, by default, you don't have any network configuration.

Try to ping any DNS server, like 1.1.1.1, or reach any domain, it will timeout.
Then, you will have to configure network, which will require 2 actions.

Configuring your main network interface

nano /etc/network/interfaces

Once you've performed this command, you will have to add the following lines:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto ens18
iface ens18 inet static
  address YourHetznerAdditionnalIP 
  netmask 255.255.255.255
  pointopoint YourHetznerPVEIP
  gateway YourHetznerPVEIP

As a reminder, for the following information:
-YourHetznerAdditionalIP : Your additional IP address that you've ordered on your Hetzner Robot Konsole.
-255.255.255.255 is the default netmask used in our case
-YourHetznerPVEIP: Your PVE (Proxmox Virtual Environment), your dedicated server IP.

Once it's done, you will have to restart the networking service.
To do it, please proceed with the following command.

systemctl restart networking

That's done, your server can now ping any other connected device.

Configuring your DNS resolvers

Now, you can only reach any public IPv4 address, but you won't be able to reach domains. So you will have to configure also your DNS resolvers.

nano /etc/resolv.conf

By default, this file doesn't exist, but don't worry, we will create it with nano.

nameserver 1.1.1.1
nameserver 8.8.8.8

Here, I will use Cloudflare and Google DNS, but feel free to use any DNS server. In some cases, and if you really care about your data, use DNSWatch one (84.200.69.80).

Now, that's solved, and you can ping any domain name, without any issue.

Then, we will have to add and define which Debian sources/repo/mirror we will use on our VM. Because, by default, you won't be able to update your VM OS, as we've used an ISO for the VM creation (which emulated an CD-ROM).

In my case, I will use Hetzner official sources/repo/mirror, as explained here: https://docs.hetzner.com/robot/dedicated-server/operating-systems/hetzner-aptitude-mirror/

So, let's define our new sources:

nano /etc/apt/sources.list

Remove all lines displayed on this file and add these (if you're using a newer Debian version, check Hetzner page):

#Hetzner Mirror Sources 

deb http://mirror.hetzner.de/debian/packages buster         main contrib non-free
deb http://mirror.hetzner.de/debian/packages buster-updates main contrib non-free
deb http://mirror.hetzner.de/debian/security buster/updates main contrib non-free

deb http://deb.debian.org/debian/ buster          main contrib non-free
deb http://deb.debian.org/debian/ buster-updates  main contrib non-free
deb http://security.debian.org/   buster/updates  main contrib non-free

As usual, save this file, and you will be able to update and upgrade your Debian VM.

Congratulations, you've created your first VM on your hypervisor without any cloud provider. You no longer need them for your infrastructure.

Step 5: Go further...

If you want to go further, there are few options that can be really nice to do:

-discover how cloud-init works, and how it can help you to deploy few VMs in a few seconds without any boring config part, like explained here: https://pve.proxmox.com/wiki/Cloud-Init_Support

-create and install Windows VMs: follow the documentation available here
https://pve.proxmox.com/wiki/Paravirtualized_Network_Drivers_for_Windows

-use a (sub)domain as your hostname, and add an SSL certificate to your domain, simply add an A record pointing to your domain, and generate a new Let's Encyrpt certificate with this tutorial: https://pve.proxmox.com
/wiki/Certificate_Management

Congratulations, you've successfully learned how to install Proxmox and create VMs with non failover IPs on your Hetzner server!


Permalink: https://tomjorge.me/install-proxmox-and-create-vms-with-ips-on-your-hetzner-dedicated-server/