LXD NAT Proxy Device and Port Forwarding

Oh also is there a way to automatically generate and set a static ip when creating a container?

lxc config device override <instance> <device> ipv4.address=n.n.n.n will create a static DHCP lease for the instance device in the LXD DHCP server.

But you still have to replace n.n.n.n with an ip, right, not autogenerated?

If I use override I get Error: The device already exists, and if I use set I get Error: Invalid devices: Device validation failed for "eth0": Device IP address "n.n.n.n" not within network "lxdbr0" subnet

Yes, auto allocation is what DHCP is for. But in NAT mode it requires a static allocation.

You can only assign a static DHCP allocation for IPs within the DHCP subnet. You’ve not shown the full command so I cant see what you’ve supplying. In general supplying the full command is more useful for support.

Yeah but since nat mode requires a static ip, isn’t there some way to randomly generate a static ip on creation of the container or first launch?

Not at this time. You could use the proxy device in non-nat mode to avoid needing to use a static IP and have it connect to the 127.0.0.1 address inside the container.

If it’s not in nat mode, I got the understanding that the client ip isn’t showed connecting to the port, but rather the proxy ip though.

Thats correct, unless your receiving application can support the proxy protocol, which can also be enabled in non-nat mode.

So basically I’m trying to make a hosting service and the services inside the containers aren’t controlled by me, and not all of them would support the proxy protocol which would be a major problem. But if I do use nat mode so they can get client ips, I can’t use a dynamic ip or generate a static ip on creation automatically, which would make it so I have to manually assign ips and prevent automating container generation.

Is there a better way to do this that allows both container generation automation and original client ips being passed?

I don’t think we have that capability at the moment. You could log an issue for it to be discussed to see if its viable. Otherwise you could just manage the allocation outside of LXD and add a statically assigned NIC device as part of the container creation process.