Assigning a public IP to a LXC container

Thykeadams

Member
Aug 4, 2020
4
0
6
23
Hello fellow Proxmoxers!, I just have a quick question as I cant find an answer to it anywhere. I am trying to setup a machine with 4 IP Addresses to have 3 LXC containers each with their own Public IPV4 Address, but I cant seem to get the network config working.

My current host network config looks like this:
Code:
auto lo
iface lo inet loopback

iface eth0 inet manual
iface eth1 inet manual
auto vmbr0
iface vmbr0 inet static
        address 1xx.xxx.60.205/24
        gateway 1xx.xxx.xx.1
        bridge-ports eth0
        bridge-stp off
        bridge-fd 0

auto vmbr1
iface vmbr1 inet static
        address 2xx.xxx.xx.59/24
        bridge-ports eth1
        bridge-stp off
        bridge-fd 0
How would I go about setting an IP address to the LXC container. Say I wanted `example:` 99.233.59.123 pointed to CT 1 and only CT 1, how would that work?
 
Code:
auto lo
iface lo inet loopback

iface eth0 inet static
        address  1xx.xxx.60.205/24
        gateway  1xx.xxx.60.1
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp


auto vmbr0
iface vmbr0 inet static
        address  99.233.59.121/29
        bridge-ports none
        bridge-stp off
        bridge-fd 0


Code:
arch: amd64
cores: 1
hostname: ct1
memory: 512
net0: name=eth0,bridge=vmbr0,gw=99.233.59.121,hwaddr=XX:XX:XX:XX:XX:XX:XX:XX,ip=99.233.59.123/29,type=veth
onboot: 0
ostype: debian
rootfs: ctstore:vm-201-disk-0,size=8G
swap: 512
unprivileged: 1
 
Code:
auto lo
iface lo inet loopback

iface eth0 inet static
        address  1xx.xxx.60.205/24
        gateway  1xx.xxx.60.1
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up echo 1 > /proc/sys/net/ipv4/conf/eth0/proxy_arp


auto vmbr0
iface vmbr0 inet static
        address  99.233.59.121/29
        bridge-ports none
        bridge-stp off
        bridge-fd 0


Code:
arch: amd64
cores: 1
hostname: ct1
memory: 512
net0: name=eth0,bridge=vmbr0,gw=99.233.59.121,hwaddr=XX:XX:XX:XX:XX:XX:XX:XX,ip=99.233.59.123/29,type=veth
onboot: 0
ostype: debian
rootfs: ctstore:vm-201-disk-0,size=8G
swap: 512
unprivileged: 1
I see you used gateway as the IP I wanted, is that how its supposed to be or? Where did you get the ...59.121 IP address?
 
Well you proposed the 99.233.59.0 network, otherwise it is guess work and assumption as I don't have all of your config information.

For that scheme to work, at least one of your allocated IP addresses would need to be allocated to the role of routing address (aka network gateway) and assigned to the vmbr0 interface. The remaining IP's can be assigned directly to your containers or VM's

It's possible to share the gateway IP by using port forwarding - so if you needed to use that ....59.121 address in our example for a web site say, you could forward http traffic on port 80 and 443 to a CT or VM using a private non-routable, ip address.

Having said that, you do need to speak to your hosting provider support to ensure that this is not going to breach any of their security policies.
 
Well you proposed the 99.233.59.0 network, otherwise it is guess work and assumption as I don't have all of your config information.

For that scheme to work, at least one of your allocated IP addresses would need to be allocated to the role of routing address (aka network gateway) and assigned to the vmbr0 interface. The remaining IP's can be assigned directly to your containers or VM's

It's possible to share the gateway IP by using port forwarding - so if you needed to use that ....59.121 address in our example for a web site say, you could forward http traffic on port 80 and 443 to a CT or VM using a private non-routable, ip address.

Having said that, you do need to speak to your hosting provider support to ensure that this is not going to breach any of their security policies.
Could that "allocated IP" be the same IP used to access the PVE server or does it have to be an entirely different one? Would you need 3 IP addresses for it to work correctly? (Sorry if I am buggin you, I'm new to this kind of networking)
 
There are multiple ways of doing this and no right or wrong way. We are working on the assumption that the Proxmox host IP is on a different subnet to the one's allocated to the VM's - yes?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!