All container IPs ( ipv4) to one external public IP :port

currently I am able to forward one internal IP port of lxc container to my public IP :port. This is done by me using IPtables rules.

I want to listen all my container’s IPs from 1:65535 to one external IP port: say 213.138.92.25:8082

How to achieve this?

Why I am doing this.

I want two control panels (aapanel on Ubuntu 18.04 container) in two different lxc containers. Panel uses different ports for different apps . I have to do manually route each internally port to external public IP port.

These are the articles I refered and believe it is possible.


https://blog.widodh.nl/2016/04/anyip-bind-a-whole-subnet-to-your-linux-machine/

I learnt all about lxc from this forum only. I am not an IT engineer but a chemical tech engineer. Please help me in very layman’s language .

I’m not sure whether you are asking by LXD or LXC, but given what you are asking, the proxy device in LXD sounds relevant.

https://linuxcontainers.org/lxd/docs/master/instances#type-proxy

However you cannot bind multiple container’s proxy devices to the same port and IP on the host, as otherwise the host won’t know which packets should be destined for one or the other containers.

You can setup a proxy device in each container that listens on the same host IP but different ports and then have them forward back to the same port in each container (for example run one control panel on port 80 and the other on port 81, both forwarding back to port 80 in the relevant containers).

You haven’t specified which ports you need, but if you only need to expose the web port for control panels then you could also consider using an HTTP reverse proxy (such as nginx or apache) either running on the host or inside a separate container, that could listen on the host’s port 80 and then use the domain of the HTTP request to pass the requests to the relevant internal container’s port 80.

This would have the effect of allowing multiple web apps to run on the host’s single IP.

Thanks Tomp got insight.