I´m completely new to Linux containers and i just wanted to figure out what is the best common way to set public static ip´s for my containers?
I´m using a root server and my LXD version is 2.0.11 on 16.04.2-Ubuntu. I have a few more public IP´s available: 138.201.151.XX/29
At the moment i created a subnet with lxdbr0 for the public ip´s and use the LXD_CONFILE="/etc/default/dns.conf" to attach always the same IP.
But in general i don’t want that. I just would like to attach each ip statically to each container. What would be the right approach to do that?
yes it works - i tested it in my local LAN. Thank you!
Now will test it on the root server. In general I understand the most important thing is to set the interfaces file correctly. Do you think I can just copy the entries of eth0 over to br0 and comment out the eth0 entries? I want to avoid to block myself from the rootserver because i dont have physical access to the machine.
If you use macvlan mode you do not have to change the network config in the host (you create a macvlan profile, assign it to the containers and config the network inside container). I have read that macvlan is faster than bridge but the host can’t communicate with his containers. Look at Macvlan vs network bridge
In Another ‘networking issue’ or ‘how to connect containers to more than one network using a bridge or macvlan’ you can see an interfaces file that I have used in several Ubuntu 16.04 hosts without problems (previously I installed the bridge-utils and verify the interface’s name). I can not assure 100% that you have no problems; but you can ask the hosting company if they have any limitations regarding the use of containers and bridge mode (or macvlan).
thank you mgregal for the help. Im just struggeling with the bridged network now and want to make it running. Maybe later I will also test macvlan but now i want to make the bridge runing before.
On the host the bridge is allready running fine but the containers i cant “convince” to get an ip with the new profile. Something I´m doing wrong - probably its the ip configuration inside the container or the profile is wrong. br0 is comming up fine and eth0 is using it. The containers are also running with the old profile and br0. But as I change the profile the container is not getting the IP adress.
maybe you can see an error in my config? I will post the files here:
This is my interfaces file from the host:
auto lo
iface lo inet loopback
iface lo inet6 loopback
auto br0
iface br0 inet static
address 136.243.106.231
netmask 255.255.255.192
gateway 136.243.106.193
dns-nameservers 8.8.8.8 8.8.4.4
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
up route add -net 136.243.106.192 netmask 255.255.255.192 gw 136.243.106.193 dev eth0
Is the right gateway? The container is in the net 138.201.151.48/29 and the gateway is 136.243.106.231 (another network). I think his gateway should be a host directly accessible
Hm ok i added also auto eth0. But eth0 in the contaier still has no ip (output form ifconfig -a). As if the settings in container/etc/network/interfaces would not affect the eth0 interface.
its silly because if i use the default profile the eth0 interface in the container gets an ip independently what is set in the inetrfaces file on the container:
eth0 from the cotainer with profile “default” is set
lxc assign default,bridge <-- assigns two profiles. You can change the list of profiles which apply to a given container and the overlapping parameters will take a value from the last applied profile.
start the container and verify if container has IP and connection
It isn’t necessary delete but I would change the values for lxdbr0 (to not use the same network for lxdbr0 and for containers in bridge mode with br0).
Lxdbr0 is like a NAT network in Virtualbox; that is to say, containers in that network will receive a IP via an internal dhcp server (lxd do this) and they will be able to access internet via iptables (doing SNAT through the public IP of the host). Services running in those container only will be accessible via iptables DNAT. You can see NAT rules via: sudo iptables -t nat -L -n . In my computer:
manuel@pcmanuel:~$ sudo iptables -t nat -L -n
[sudo] password for manuel:
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
You can change the lxdbr0 values with: lxc network edit lxdbr0
I have a bridge br0 and lxdbr0 without problems (and even more internal networks). Some containers work in bridge mode with br0 (they require a real IP config for the lan network) and others in bridge mode with lxdbr0.
OK i edited the /etc/default/lxd-bridge file manually (lxc network command is missing in lxd 2.0 i guess) and restarted the bridge. Now the container is getting an IP from 10.0.8.0/24 range in default profile. But it didnt solved the problem. The container doesnt still get an IP with bridge profile attached.
I also created a macvlan profile now. But the container also doesnt get an IP.
Container interfaces file:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 138.201.151.50/29 <--- My subnet wit pubic IP´s
gateway 136.243.106.231 <--- IP Adress of the Host
dns-nameservers 8.8.8.8 8.8.4.4
Host interfaces file:
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
iface lo inet6 loopback
auto eth0
iface eth0 inet static
address 136.243.106.231 <--- Host public IP
netmask 255.255.255.192
gateway 136.243.106.193
up route add -net 136.243.106.192 netmask 255.255.255.192 gw 136.243.106.193 dev eth0
iface eth0 inet6 static
address 2a01:4f8:171:fe6::2
netmask 64
gateway fe80::1
I tried your profiles and interface file in my computer and they worked (both the macvlan profile and bridge profile). Both the host and container are Ubuntu 16.04.4 LTS.
My lxd version is 2.21 from backports repositories
oh thats cool :-D. Thank you! Unfortunately here its not working! Struggeling all the time but have no idea at the moment where is the bug. Maybe it has to do with network settings of my hoster? This is a root server from hetzner.de (no virtual machine). Another probem might be that the IP of the host bridge br0 is not in the subnet which I use for the containers?
server IP is 136.243.106.231
gateway 136.243.106.193
@simos has a lot of tutorials about LXD and two of them are about Hetzner:
Maybe, you see something we do not see.
Another probem might be that the IP of the host bridge br0 is not in the subnet which I use for the containers?
No, in labs with my pupils I have a bridge br0 and I created a lot of containers with IPs from different networks. The container should catch the IP, netmask, gateway and dns from interface file. The only thing I see strange is the gateway for the container ( 136.243.106.231) because it’s in a different network.