LXD container static IP set up

Hi everyone,

I’m running a small VPS hosting business and I’m starting looking into LXD as a potential replacement for OpenVZ but I’m finding many difficulties in setting up the network.

I need to set up the network so that all contaieners are availabel on the internet. I have read many posts on this form and elsewhere but I cant manage to make it work.

I have a basic Ubuntu 18.04 set up and thse are the steps I have been following:

I run the initial set up with all defaults so I have the managed bridged interface ready.

As first step I create the container:

root@server:~# lxc launch ubuntu:18.04 webserver
Creating webserver
Starting webserver

now the newly created container has DHCP assigned IP:

root@server:~# lxc list
±----------±--------±----------------------±---------------------------------------------±-----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±----------±--------±----------------------±---------------------------------------------±-----------±----------+
| webserver | RUNNING | 10.229.218.173 (eth0) | fd42:9f0f:a7e:c6c0:216:3eff:fe93:1bf1 (eth0) | PERSISTENT | 0 |
±----------±--------±----------------------±---------------------------------------------±-----------±----------+

Let’s say want to assign the following IP to webserver container: 104.218.16.147

I run the following commands:

lxc stop webserver
lxc network attach lxdbr0 webserver eth0
lxc config device set webserver eth0 ipv4.address 104.218.16.147
lxc start webserver

but I still see the old IP:

root@server:~# lxc list
±----------±--------±----------------------±---------------------------------------------±-----------±----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
±----------±--------±----------------------±---------------------------------------------±-----------±----------+
| webserver | RUNNING | 10.229.218.173 (eth0) | fd42:9f0f:a7e:c6c0:216:3eff:fe93:1bf1 (eth0) | PERSISTENT | 0 |
±----------±--------±----------------------±---------------------------------------------±-----------±----------+

Why is it like that? What I am doing wrong?

Is that IP an individual IP routed to the LXD host or do you have an entire subnet of IPs routed to your LXD host?

Also, is it your intention to share that IP between multiple instances or have it entirely consumed by a single instance?

Hi Tomp, the IP 104.218.16.147 is part of 104.218.16.146/21 subnet which is routed to the host node. I dont want to share the IP between multiple instances, each instance should have its unique IP.

In that case if can dedicate the entire subnet (or a /24 within it) for use by LXD you can create a new managed LXD bridge and assign it that subnet and disable NAT, e.g.

lxc network create mybridge --type=bridge ipv4.address=104.218.16.146/21 ipv4.nat=false

Then you can connect instances to the network:

lxc config device add c1 eth0 nic network=mybridge

Alternatively you can route single IPs from that subnet into your instances using a routed NIC see How to get LXD containers get IP from the LAN with routed network

Thank you for your reply, I’m getting the following error while running:

lxc config device add websever eth0 nic network=mybridge

Error: Invalid devices: Invalid device configuration key for nic: network

BTW here is my LXC version:

root@server:~# lxc --version
3.0.3

Oh that is a very old version of LXD.
Are you able to use the LXD 5.0 LTS?