By the time I moved to the cloud (in my case Hetzner) I wanted to replicate my home lab setup I had before. This would include my own IP-Range because I want to create and delete VMs on my Proxmox installation on a regular basis. Since a hosting provider would only supply one external IP address and I want to host multiple services on it, I want to setup a NAT.
What is NAT?
Typically you get only one IP-Address assigned by your provider even though you have multiple devices which need an IP-Address to browse the internet. Therefor your router implements NAT which stands for network address translation.
To implement NAT the router has to keep track which device requested content. Then the router itself requests the content from the world wide web. When the content arrives at your router it does a lookup where he has to route the data. If PC1 requests google.com, it sends it’s request to the router because google.com translates to an IP-Address outside it’s own network. The Router creates an entry in it’s NAT-Table and also changes the source address to it’s own (public) address. This has to be done because google.com has to know where the request came from. Since the IP-Address of PC1 is not public, google.com would not be able to send the response back. As soon as the response of the requested website arrives at the router, the package gets retransmitted to PC1.
Whats the goal?
This is also what I want to replicate with my proxmox setup in the cloud. I only have one public IP-Address but multiple VM which need unique IP-Addresses. It would be possible to request additional public IP-Addresses but this would not only cost more money, but also is a lot less dynamic. Every time I create a new VM I would have to request a new one from the provider. Inside my own sub network I can host a DHCP Server which would assign IP-Addresses automatically.
All the configuration is done inside
/etc/network/interfaces. Here is an example configuration. (I had to upload it with the file ending “.txt”. If you opt to use this as a basis please remove the ending)
Let’s talk about each block separately.
|This is kind of an include statement for other interface configuration files. This folder however is in my case empty.|
|These lines of code define an internal loopback interface which is used for inter-process networking. We define one for IPv4 and one for IPv6.|
|This is the actual definition of your hardware network interface. |
Also this entry is used to specify the external IP Address and additional network configurations. The gateway is typically pretty much the same as your public ip address. The netmask typically contains a lot of 255.
|Last but not least I want to mention how port forwarding works with this setup. If you want to expose a port of a virtual machine you will have to create those four entries. The first two create a port forwarding of port 80 to the host with the IP-Address 10.55.0.66. The second two are pretty much the same but enables a vm behind the NAT to reach the public IP Address.|
As soon as your configuration file is done you should do a restart. There are other possibilities like the
ifup command but I encountered some problems with my VMs. Every time you add a new VM please make sure you only use the
vmbr0 interface. Also because there is no DHCP-Server included with this configuration you have to assign IP-Addresses manually. During the configuration you will also be asked to input the gateway and DNS-Server. The gateway is in case of the example 10.55.0.1. If you don’t host your own DNS-Server inside this network, you can use the common DNS-Servers like 220.127.116.11 or 18.104.22.168 or 22.214.171.124.
If you are interested in a setup with IPv6 please check out this article.
I hope you could follow the steps to adjust the example to your needs. Signing off.