Container using IP of host when connecting to the internet

Hello,

I want to setup two containers (each with a static IP address) so that they can be used as a standard VPS. I am using Ubuntu 18.04 on host and for containers. Let’s say static IPs are: 175.100.100.100 and 175.100.100.101. On host I run:
“lxc network set lxdbr0 ipv4.routes 175.100.100.100/32, 175.100.100.101/32”
I disabled netplan by running “sudo apt install ifupdown”.
Inside each container I setup networking in /etc/network/interfaces like this:
auto eth0
iface eth0 inet dhcp
post-up ip -4 addr add dev eth0 175.100.100.100/32 preferred_lft 0

Result: Internet is working inside containers. I can connect to IP of containers from outside. The problem is that when a container connect to the internet, IP address of the host is used instead of IP of the container. How do I fix this? I want the container to use its own IP address when connecting outside.

Hi Janus,

If you want to make a container individually visible to the LAN (or the Internet), you need to have it get an allowed IP address from the LAN (or the Internet).
That is, if you have a VPS, you would need to buy an additional IP address.
The reason is that the router that your host is connected to, is likely restricting what IP addresses it is expecting to originate from your host. By default, most VPS providers give you a single IP address.

If, however, you own the router (for example, it is your own LAN), then you can get each LXD container to get an IP address directly from the router. Each container would then be visible to the local network.

If you are allowed to get more IP addresses just like the one your host has, then in LXD you can use either macvlan or bridge to make your LXD container get an IP address from the local network.

Here is a specific example of setting up your baremetal server to use public IP addresses for your LXD containers. Here we use Packet.net and set up the server with a few extra public IP addresses.

1 Like

Hi Simos,

Thank you for your help. I managed to get it working with your macvlan tutorial. I also had to order a seperate MAC for each static IP from my webhost and set it up with lxc config set container_name volatile.eth0.hwaddr AA:BB:CC:DD:EE:FF.