Let’s start by saying that Hetzner is a great company if you go by their rules. They offer cheap servers, have good network and wonderful support. However, they’re based in Germany and Germany has a lot of rules and laws preventing certain types of content being hosted on servers located in the country. However, this is not what we’re going to talk about today. Today we’re going to focus on configuring your Hetzner dedicated server’s networking to enable you to run your own virtual servers on it.
SharkServers is a web hosting company too, so it may seem illogical that we write a blog post explaining how to set something up on Hetzner’s infrastructure. However, many people are interested in this topic, and we just want to help. Who knows, maybe we’ll win some customers over by just being helpful. As always, if you can’t be bothered to do all of this on your own, we can do it for you.
When you order additional IP addresses from Hetzner, they will assign them from a completely different subnet. This means that in order to run virtualization, such as KVM or XEN, you will be required to set up a network bridge. The bridge will use one of the IPs from the additional subnet. This IP will be used as gateway for your virtual servers, as otherwise they will not be able to reach the Internet, or be reachable from it.
Let’s get our hands dirty!
Before we continue, I must urge you to make a backup of any file you modify. Backups are important, as I have found out the hard way, after living my life by the motto ‘real men don’t make backups’ for years. That’s a load of rubbish. We’re doing this on CentOS 7 system, so the actual commands may vary depending on the Linux distro you’re using. To start with, we need to find out what our network interface’s name is. This can be done by running the following command:
[[email protected] ~]# ifconfig
The above command will return all your network interfaces. You should be looking for the one that has your primary IP address assigned to it. In most cases it will be eth0, but that’s just an example. It can also be, for example, enp4s0, like in our case.
Once you’ve established what your primary network interface is, we need to create the bridge to act as a gateway for your virtual servers.
The name of the bridge doesn’t really matter. However, if you are using a control panel to manage your virtual servers, you will need to make sure that the control panel knows the name of the bridge that we’re about to create. In this case, we’ll assume our primary interface is enp4s0 and will name our bridge ‘br0’. We do this by issuing the following command:
Now open the ifcfg-br0 file with your favorite text editor, and put this into the file, modifying where necessary:
DEVICE=br0 ONBOOT=yes TYPE=Bridge BOOTPROTO=static IPADDR=PUT FIRST USABLE IP ADDRESS FROM ADDITIONAL SUBNET HERE NETMASK=255.255.255.240 # adjust this accordingly. This is for a /29 subnet STP=off DELAY=0
Save the file and exit the text editor.
All that’s left now is to restart the network. We do this by typing the following into the command line:
[[email protected] network-scripts]# service network restart
That’s it! The bridge is now active, and your virtual servers will be able to access the Internet. Good job!