Howto setup Debian/12/Cloud static IPV4 address

Running a Debian/12/Cloud instance on Ubuntu.

Read through many posting + can’t come up with a working solution.

My preference is to install netplan + setup a simple YAML config file, similar to Ubuntu.

If someone knows how to get netplan working, let me know.

Thanks!

Or if there’s a simpler way to achieve working static IPV4 address, that’s find too.

Or an “lxc config” command at machine level is fine too.

With default networkd it would be (example profile):

name: debian-test
config:
  user.network-config: |
    #cloud-config
    version: 2
    ethernets:
      eth0:
        dhcp4: no
        dhcp6: no
        addresses:
        - [YOUR IP]/32
        nameservers:
          addresses:
          - 8.8.8.8
          - 8.8.4.4
          search: []
        routes:
        - to: 0.0.0.0/0
          via: 169.254.0.1
          on-link: true
  user.user-data: |
    #cloud-config
    package_update: true
    package_upgrade: true
    packages:
      - openssh-server
description: Debian Test.
devices:
  eth0:
    host_name: veth-debtest
    ipv4.address: [YOUR IP]
    nictype: routed
    parent: [PARENT INTERFACE. The one the host, for example: enp1s0f0]
    type: nic
  root:
    path: /
    pool: default
    size: 3GB
    type: disk

Just replace the placeholders I wrote. However, for some reason on-link: true is actually not applied to the networkd’s configuration, which results in the network not working. To fix this, enter the container: lxc shell [container-name], and add: GatewayOnLink=yes to /etc/systemd/network/10-cloud-init-eth0.network file. Then restart networkd with: systemctl restart systemd-networkd and it’s done. Networking will work from now on.

Now that you have access to the network, you can download/install netplan and configure it if you wish. A good idea would be to create a custom image with netplan already installed, if you really want it in all future containers, I guess.

Following steps taken that failed.

# outside container
lxc profile create lxd-profile-debian-cloud-template
lxc profile edit   lxd-profile-debian-cloud-template < lxd-profile-debian-cloud-template.yaml
lxc profile add    net16-debian12-cloud-template lxd-profile-debian-cloud-template

# inside container
# added "GatewayOnLink=yes" to [Network] in /etc/systemd/network/10-cloud-init-eth0.network
# lxc restart net16-debian12-cloud-template

Contents of lxd-profile-debian-cloud-template.yaml are…

name: debian-test
config:
  user.network-config: |
    #cloud-config
    version: 2
    ethernets:
      eth0:
        dhcp4: no
        dhcp6: no
        addresses:
        - 144.217.145.114/32
        nameservers:
          addresses:
          - 8.8.8.8
          - 8.8.4.4
          - 1.1.1.1
          search: []
        routes:
        - to: 0.0.0.0/0
          via: 144.217.145.112
          on-link: true
  user.user-data: |
    #cloud-config
    package_update: true
    package_upgrade: true
    packages:
      - openssh-server
description: Debian Public IP Networking Setup
devices:
  eth0:
    host_name: veth-debtest
    ipv4.address: 144.217.145.114
    nictype: routed
    parent: eno1
    type: nic

Also “lxc list” produces no IPV4 address for this container, so likely I’ve missed something in your directions.

Let me know what I can do next.

Thanks for your assistance, as I was pulling my hair out!

Wrong route. Don’t change 169.254.0.1 it needs to be kept as in my example. Update the profile and recreate the container.

This route is a way for the container to communicate with the host. This IP is special.

Finally got “lxc list” to show the IPV4 network + routing is broken somehow, so packets don’t flow.

Likely due to no 10.10.10.X address being assigned to the container.

Pass along any other ideas to get this to work.

Thanks.

Did you add GatewayOnLink=yes like I mentioned, and did you restart networkd? If yes, then please paste the output of ip a and ip r from inside of the container.

Actually, one more thing. You mentioned that you added GatewayOnLink=yes to the “[Network]” section, that’s wrong. Add it to the [Route] section, at the very end of the file.

Hi,

What sort of network is the instance connected to?

Please can I see lxc config show <instance> --expanded.

As if it is connected to a LXD managed network (like bridge or ovn) you can actually get LXD to setup a static DHCP allocation using:

lxc config device override <instance> <nic> ipv4.address=n.n.n.n

That then doesn’t require any changes to the guest.

It worked for me to do this inside the container:

systemctl stop systemd-networkd
systemctl disable systemd-networkd

Is it a bad approach? Can I script that with cloud-config somehow?

I’ll be avoiding this, as working with profiles completely destroyed all LXD networking. Packets no longer route… at all…

Nothing I can do to back out changes to fix this, so a reinstall is required.

My suggestion to LXD dev is to work with whoever is rolling the Debian LXD images + add in Ubuntu style netplan setup, so networking works out of the box, rather than hacking on system + destroying networking like I’ve done.