Adding public IP to lxd container

Hi team!

I have a server with public IP and I have an lxd configuration setup on it.

I ran a container and added a lxd network to it. Now I want to attach Public IP that I have on the server to this container so I can access publicly the application running inside my lxd container. I also need an internal IP (coming from the already added lxd network) for another use case.

So 2 networks I think need to be attached on the same container. One adding public IP of the server to the container and the other simply for internal access within the server.

I’m not sure if that’s even possible at all. Any advice would be appreciated. Thanks!

You could probably just use the ipv4.routes.external config key on the container’s nic entry and set that to 1.2.3.4/32. This should then add a route entry on the host which will route the address to the instance’s network.

The instance can then grab an IP normally through DHCP but then can also add the static address to the same interface and will respond on both.

Thanks @stgraber for the quick solution.

Let me try this out. Will update on this thread.

I’m not sure if I am doing this correctly. Please advice:

The network that I have attached to the container has this configuration:

lxc network show net2bd7f907b7

config:
  ipv4.address: 10.10.93.1/24
  ipv4.nat: "true"
  ipv4.routes: 1.2.3.4/32
  ipv6.address: none
  ipv6.nat: "true"
description: ""
name: net2bd7f907b7
type: bridge
used_by:
- /1.0/instances/lxc-174ec5b8-10fe-4ae5-8d2c-1659ebf14fa3
- /1.0/profiles/pro-174ec5b8-10fe-4ae5-8d2c-1659ebf14fa3
managed: true
status: Created
locations:
- none

I have port 55000 forwarded from my container to the host.

Now if I run a service inside the container at 55000 port then I am unable to access it at PUBLIC_IP:55000

Is this configuration incorrect?

Also, do I need to forward ports to make a service accessible at a port or are they automatically available when I enable Public IP access to the container? All ports are currently open on my Public IP.