More on LXD Networks

I have discussed LXD Proxies, Bridged, macvlan, and ipvlan as ways to provide network connectivity in LXD containers. Proxies provide port forwarding as is commonly used in Docker. Bridged and macvlan use a software bridge to provide a unique IP address and MAC address on your LAN for a container. Ipvlan uses a physical adapter to virtually connect a container to your LAN via a static IP with the same MAC address as the LXD host.

“routed” is another networking type for LXD containers that is designed to expose containers to a LAN dedicated IP address on an unmanaged network. Routed containers have the same MAC address as their host like ipvlan containers.

In this tutorial, we learned how to create a routed network profile and how to connect a container to it. This is limited use case since a routed container is designed to take over the routing function. A common use case for routed is to connect to a dedicated WAN address where your ISP has granted you more than one WAN address.

Create LXD container on your LXD host:

lxc launch ubuntu:22.04 test --profile default -c boot.autostart=true

Create a routed profile and edit it:

lxc profile create routed
lxc profile edit routed

Clear the contents of the file with the CTRL K command to delete lines and then insert the following as a template:

config:
  user.network-config: |
    #cloud-config
    version: 2
    ethernets:
      eth0:
        addresses:
          - 172.16.2.2/16
        dhcp4: no
        dhcp6: no
        nameservers:
          addresses: [1.1.1.1, 1.0.0.1]
        routes:
         - to: 0.0.0.0/0
           via: 169.254.0.1
           on-link: true
description: "routed LXD profile"
devices:
  eth0:
    ipv4.address: 172.16.2.2
    nictype: routed
    parent: enp5s0
    type: nic
name: routed
used_by:

Make the appropriate changes for your IP address, DNS, and parent adapter interface name.
Save the file with a CTRL X, Yes and Enter.

Copy the template profile to an appropriately named profile for your address:

lxc profile copy routed routed_172.16.2.2

You can edit the copied profile to make any changes.

lxc profile edit routed_172.16.2.2

Finally, stop the LXD container we created, apply the profile and restart the LXD container and your routed networking should be working.

lxc stop test
lxc profile add test routed_172.16.2.2
lxc start test
lxc list