I rent a dedicated server and want to use LXC instead of KVM. I want to buy IPs for every single container. For now i have two external IPs:
- 193.X.X.30/32
- 213.X.X.31/32
I prefer a routing solution instead of NAT.
My last try is like this:
-------------------
| INTERNET |
-------------------
|
V
----------------------------------------------
| ------------------- ------- [HOST] |
| | br0: 193.X.X.30 | <--- | em1 | |
| ------------------- ------- |
| | |
| V |
| ------------------- |
| | vethXXXX | |
| ------------------- |
| | |
| V |
| -------------------------------------- |
| | -------------------- [CONTAINER] | |
| | | eth0: 213.X.X.31 | | |
| | -------------------- | |
| | | |
| -------------------------------------- |
----------------------------------------------
Network configuration on my host:
auto br0
iface br0 inet static
bridge_ports em1
bridge_fd 0
address 193.X.X.30
netmask 255.255.255.0
gateway 193.X.X.1
dns-nameservers 8.8.8.8 8.8.4.4
My container configuration:
lxc.network.type = veth
lxc.network.link = br0
lxc.network.ipv4 = 213.X.X.31/24
lxc.network.ipv4.gateway = 213.X.X.1
My container network configuration:
auto eth0
iface eth0 inet static
address 213.X.X.31
netmask 255.255.255.0
gateway 213.X.X.1
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4
I didn't succeeded to connect the containers directly. What should be the right configuration/topology that the containers successfully host services like Web/Mail/DNS.
PREROUTINGchain of thenatuse-j DNATto forward distinct incoming requests on the external IP to the LXC guest. Allows me to only let relevant services through. For this, however, the container has two NICs, statically configured. One on an internal subnet, the other the external IP. No interface on the host has the (secondary) external IP assigned. We purely do it by routing. Forwarding has to be enabled for IPv4.man lcx.container.conf) to add and remove the netfilter rules. And btw, buying individual IPv4 addresses for every single container is probably overkill - especially if the services running on them don't overlap. Putting a jailed proxy on the host or into a dedicated guest will go a long way in using IPv4 addresses economically.route add 213.X.X.31 vethXXXXandarp -s 213.X.X.31 00:16:3e:aa:bb:cc. Then change the gateway of container to193.X.X.1finally i can ping the container. But i ping the213.X.X.31reply comes from193.X.X.30