Running multiple virtual machines behind a shared IP

I assume that you have already set up your private VM's to use bridged networking (vmbr0), as described in a previous blog post by me.

On the Proxmox host just setup IP forwarding to the private IP's of the private machines.

For instance, to forward port 60101 on proxmox host to port 22 on the virtual machine (10.0.0.101), so that you can SSH into the virtual machine. Run the following on the proxmox host.

iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 60101 -j DNAT --to-destination 10.0.0.101:22

When you are happy with your config, then run the following and they will be persisted even after a restart:
iptables-save > /etc/iptables.rules


In order to persist and reload automatically when the proxmox host boot, you need to do the following.

# vim /etc/network/interfaces

auto vmbr0
iface vmbr0 inet static
        pre-up iptables-restore < /etc/iptables.rules
        post-down iptables-save > /etc/iptables.rules
        address  10.0.0.1
        netmask  255.255.255.0
....


Giving virtual machines access to the internet, run this on proxmox host

# iptables -t nat -A POSTROUTING -s '10.0.0.0/24' -o eth0 -j MASQUERADE
# reboot

Comments

Popular posts from this blog

Switching from Docker Desktop to Rancher Desktop on WSL2: Solving the Missing docker-credential-desktop.exe Error

Running LXD/LXC on WSL2 with Ubuntu 20.04

Proxmox Remote administration via VNC