Skip to main content Logo (IEC resistor symbol)logo

Quis custodiet ipsos custodes?
Home | About | All pages | RSS Feed | Gopher

Proxmox VE - One Public IP

Published: 10-07-2014 | Author: Remy van Elst | Text only version of this article

Table of Contents

This guide will show you how to set up Proxmox with only one public IP. We willconfigure an extra interface bridge and make sure VM traffic is NATed. I have afew dedicated servers, some run Proxmox. Most of them however have only a fewIP's. Therefore the VM's in proxmox cannot all have a public IP. For most ofthem that is not a problem. If needed I run a proxy or set up iptables toforward ports to the VM's.

If you like this article, consider sponsoring me by trying out a Digital OceanVPS. With this link you'll get $100 credit for 60 days). (referral link)

This guide is tested on a proxmox machine running proxmox version 3.2.

What we will have at the end is a VM with an SSH port reachable on the publicIP:

Container/VM ------------ Proxmox Server -------------- Public Internet10.21.21.5:22 --- NAT to ---

Proxmox by default creates one interface, vmbr0. That config looks like this:

# /etc/network/interfacesauto vmbr0iface vmbr0 inet static    address    netmask    network    broadcast    gateway    bridge_ports eth0    bridge_stp off    bridge_fd 0

Replace 1.2.3.X with your public ip, network, gateway and such. Do note thatthere might be more interfaces, like vmbr1 for ipv6.

We create a new bridge which will enable NAT when the interface gets UP. Add thefollowing to the file:

# /etc/network/interfaces:auto vmbr2iface vmbr2 inet static    address    netmask    bridge_ports none    bridge_stp off    bridge_fd 0    post-up echo 1 > /proc/sys/net/ipv4/ip_forward    post-up iptables -t nat -A POSTROUTING -s '' -o vmbr0 -j MASQUERADE    post-down iptables -t nat -D POSTROUTING -s '' -o vmbr0 -j MASQUERADE    post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to    post-down iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to

The first part:

address nonebridge_stp offbridge_fd 0

defines the IP address and subnet mask of the new interface. It also tells thenetwork stack that the bridge has no actual ports (like eth0) and that theSpanning Tree Protocol should be disabled.

post-up echo 1 > /proc/sys/net/ipv4/ip_forward

Enables IP forwarding when this interface gets up. This allows the machine toforward packets.

post-up iptables -t nat -A POSTROUTING -s '' -o vmbr0 -j MASQUERADEpost-down iptables -t nat -D POSTROUTING -s '' -o vmbr0 -j MASQUERADE

These two lines enable the actual NAT-ing of packets from the source network'' and vmbr0 as the output interface. If your WAN interface has adifferent name, change that here. The first line enables the natting when theinterface gets up, the second line deletes the firewall rule when the interfacegoes down.

post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 2222 -j DNAT --to

These two rules enable and disable the actual port forwarding of tcp port 2222on the WAN IP to tcp port 22 on internal IP address Here as well theWAN interface (this time, the input interface) is vmbr0.

If you for example want to expose tcp port 80 of a VM with IP on thepublic IP's port 80, you should also add these lines:

post-up iptables -t nat -A PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to iptables -t nat -D PREROUTING -i vmbr0 -p tcp --dport 80 -j DNAT --to

When you create a KVM VM, make sure it is attached to the bridge vmbr2. Itshould also have a static IP configured in the range you define. OpenVZ venetinterfaces with an IP in this range automagiaclly work.

Don't forget to restart the network afterwards:

/etc/init.d/networking restart
Tags: bash, kvm, openvz, proxmox, proxmox-ve, ssh, tutorials, virtualization