LXD setup IP for VM

Hi
I have a small problem. I don’t know how to configure the network and assign an IP for a container or VM.
I have a bare metal server with Ubuntu 24 and LXD installed.
I am currently using the LXD UI and would like to configure IP and network access for an additional VM.
Unfortunately, I don’t know how to configure LXD network settings. Could someone help me?

Network data:

Main IP - 000.208.198.202
Network - 000.208.198.200
Netmask - 255.255.255.248 (/29)
Gateway - 000.208.198.201
Caching DNS - 000.208.196.51, 000.208.196.52

Available IPs I have for my bare metal:
000.208.198.202/29

000.208.198.202 - main IP for my bare metal that I use
000.208.198.203 - The IP I would like to configure for my VM or Container
000.208.198.204
000.208.198.205
000.208.198.206

I would be very grateful for your help and advice.
Regards

I do not use LXD myself but maybe the How-to guides are of some help.

@g-schick I read the documentation, but it doesn’t help me much. I’ve never been good at network configuration. I know Proxmox a little better.

You need to either dedicate a network interface for your guests (VMs/LXCs) or create a bridge on your host and share that with LXD.

LXD can do networking similarly to Proxmox, but also has some additional unique features available.

By default, a network created in LXD is NATted. Your host will have an IP address (1.2.3.4 for example) and all guests live in 10.20.43.0/24 for example. This network is separated from your physical network via NAT. This is the unique feature I was referring to, other virtualization hosts do not offer this out of the box.

You can also have your guests on the same physical network as your host. This behavior is what almost every virtualization software offers by default. This is also what Proxmox does.

Proxmox creates a bridge out of your main network interface. For example if your main interface is eth0, a network bridge is created (vmbr0) and configured with an ip address/gateway etc. Because it’s a bridge, your guests can connect to it to be able to get connectivity on your physical network.

I tried to keep the explanation simple, I hope you’re still following me. :slight_smile: if not feel free to ask

So, now it depends on your setup. Do you have a dedicated network interface for your guests or do you have an interface that you wish to share for both the host OS and the guests?

Situation 1: You have a single network interface on your server

You need to modify your network configuration to create a bridge, you can call it vmbr0 or br0 for simplicity. Assuming you’re using Ubuntu for your OS, here’s the netplan documentation: https://netplan.readthedocs.io/en/latest/examples/#how-to-configure-network-bridges

Once the bridge is created, you can go to the LXD UI → Networks → Create Network → Type Physical & Parent br0, choose a fitting name for your network and hit create. This network can now be configured on your instances (Or in your (default) profile which is the preferred method in LXD)

Situation 2: You have a dedicated network interface on your server for your VMs/LXCs

you can go to the LXD UI → Networks → Create Network → Type Bridge & bridge.external_interfaces<the dedicated network interface> and choose a fitting name. Put IPv4 and IPv6 addresses to None.

Now you can connect it to a profile :slight_smile:

And that’s it!
Proxmox does situation 1 for you during the OS installation. Because LXD is installed on top of an OS of your choosing, we have to do this small step ourself when there is no dedicated network interface.

1 Like

@vosdev
Your answer has been very helpful, and I am slowly beginning to understand what is going on. Thank you!
However, I still have a few questions, and I would be very grateful if you could help me.

This is my default netplan config, which is applied every time the server reboots:

/etc/cloud/cloud.cfg.d/90-installer-network.cfg

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp1s0f0:
      addresses:
      - 000.208.198.202/29
      nameservers:
        addresses:
        - 000.208.196.51
        - 00.208.196.52
        search: []
      routes:
      - to: default
        via: 000.208.198.201
    enp1s0f1:
      dhcp4: true
    enxbe3af2b6059f:
      dhcp4: true
  version: 2

I want add “enp1s0f2” with additional static IP - 000.208.198.203
Can you explain how to do it correctly? I don’t want to mess anything up because it’s a production server, web servers, databases, etc.

Regards

Is this the network config for the server itself? And not a guest VM/LXC ?

Do you want the 000.208.198.203 IP for your server or for a guest VM?

@vosdev
This is the configuration of a bare metal server that uses IP - 000.208.198.202
I want to configure an additional IP for guest VM in LXD - 000.208.198.203

The .203 IPv4 address needs to be configured on the guest, not on the host.

You can follow the steps in situation 2 in my first post choosing enp1s0f2 as parent. This creates a network in LXD that has access to your physical network via the enp1s0f2 interface.

For our example lets name the network example-network

You can then create a VM, create a network interface for this VM and link it to example-network

Now inside your VM you will be given a typical default network configuration. Assuming you’re using ubuntu, your VM will be given the following network configuration:

/etc/netplan/50-cloud-init.yaml

network:
  version: 2
  ethernets:
    enp5s0:
      dhcp4: true

You can modify this configuration to:

network:
  version: 2
  ethernets:
    enp5s0:
      addresses:
      - 000.208.198.203/29
      nameservers:
        addresses:
        - 000.208.196.51
        - 00.208.196.52
        search: []
      routes:
      - to: default
        via: 000.208.198.201

You can create more VMs like this and give them a similar network configuration. Your /29 IPv4 allows you to use up until .206

Hi,

What @vosdev has suggested will work and will allow the instances to be connected (by way of an externally managed bridge) to the external network.

However as it is an externally managed network, you will not be able to use LXD’s provided DHCP and DNS server, and so you will need to manage static IP setup inside each instance.

However as you’ve been allocated an entire subnet (rather than individual IPs from different subnets):

There is an alternative approach that should allow you to use a LXD manage bridge (such as lxdbr0).

This is similar to how I’ve recommended setting up LXD in environments where a server is assigned a single /64 IPv6 subnet.

The idea here is that you assign the /29 subnet to lxdbr0, e.g.

lxc network set lxdbr0 ipv4.address=000.208.198.202/29

This will assign the 000.208.198.202/29 address to the lxdbr0 interface.
You can then modify the external network interface’s settings to either keep the 000.208.198.202 IP but change its subnet size to /32 (a single IP) or remove its IP entirely and depend on proxy ARP for advertising that IP to the external network:

https://wiki.debian.org/BridgeNetworkConnectionsProxyArp

What you want to end up with is:

  1. The external interface having a single IP subnet (/32) setting.
  2. Default route to your gateway as “device route” on the external interface (i.e ip route add default dev <external interface>) so it doesn’t depend on a subnet route added for the external interface.
  3. The lxdbr0 bridge having the /29 route locally.
  4. Optionally (maybe needed for just the main IP or all of your IPs depending on your env) proxy arp to advertise your IPs to the external network.

@tomp @vosdev

Hi
I’m still trying to configure the VM, but I’m having a problem when I want to attach the network. Any idea?

Instance update failed.
 Failed to start device "br0": lstat /sys/bus/pci/devices/0000:01:00.0/iommu_group: no such file or directory

Can you show me the network configuration for your server? Did you apply the new config if you modified it?

Looks like your trying to pass through the bridge into the VM (not possible), please show:

lxc config show <instance> --expanded