I Interface with 2 addresses. How can I assign 1 of the addresses as the main gateway for an container?

So I have 2 IP address on 1 Eth0 interface.

10.0.0.10
10.0.0.11

These are both routed to the internet via our cloud provider. The IP .10 is already being used by the host system but is there a way to make my LXD Ubuntu container on the host system use only the .11 IP for all its traffic and not the .10 one?

When I ran lxd init I set up a bridge.

You should be able to set the ip statically inside a container with whatever networking scripts it would normally use, depends on the OS.

The host should automatically map the address across the bridge for you.

For example, in an Ubuntu container using Netplan, I set the following;

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: false
      dhcp-identifier: mac
      dhcp4: false
      addresses:
        - 1xx.xx.xx.56/24
      gateway4: 1xx.xx.xx.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

And I see the IP showing in the list;

root@lxd14:~# lxc list
+----------+---------+------------------------+-----------+-----------+-----+--------+
|   NAME   |  STATE  |          IPV4          |   TYPE    | SNAPSHOTS | CPU | MEMORY |
+----------+---------+------------------------+-----------+-----------+-----+--------+
| test71   | RUNNING | 1xx.xx.xx.56 (eth0)    | CONTAINER | 0         |     |        |
+----------+---------+------------------------+-----------+-----------+-----+--------+

I should map the IP automatically but it does not. I can set the IP inside the container but that does not stay after a container restart. Also I got no connectivity even when I set the ip.

You might have to set it like this if you’re using a managed bridge;

lxc config device override <container_name> eth0 ipv4.address=<IP_ADDRESS>

Error: Invalid devices: Device validation failed for “eth0”: Device IP address “192.168.2.100” not within network “Jelly” subnet

One thing to mention is I uninstalled LXD to refresh it but the Bridge was left over so I manually removed it and then I reinstalled LXD via Snap.

Sorry, I don’t have any experience with managed bridges. Hopefully someone with more knowledge than me will come along and help you soon.

If you don’t have any services using the 10.0.0.11 address on your LXD host currently, then removing it from the host and moving it into the container using the routed NIC type will allow it to be entirely used by the container for ingress and egress traffic.

See How to get LXD containers get IP from the LAN with routed network