Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Static IP for container #2083
Comments
|
The recommendation is that you configure the distribution in the container to have a static IP. On Ubuntu/Debian, that's done through /etc/network/interfaces LXC does support setting those for you from outside the container, but most distributions will then fail to boot or will just unset that preset data. If you're using an environment which does support pre-configured network interfaces at boot time, you can set something like:
The fact that this is only available through "raw.lxc" is a clear indication that while we let you pass that through, it's not supported and may very well break. |
|
Upcoming work on network bridge configuration inside LXD itself will likely come with the ability to configure specific DHCP leases which we'd then be able to support. |
stgraber
closed this
Jun 7, 2016
bradenwright
commented
Jun 16, 2016
|
@stgraber much appreciated! I really love lxd, while I don't use static ips in prod, stage. On my local machine for dev of chef cookbooks they come in very handy!!! I appreciate you allowing raw lxc.network again! |
henrylawson
commented
Oct 4, 2016
|
With version 2.3 is this now possible with LXD? Previously I was extending the dnsmasq configuration and setting "dhcp-host" and "dhcp-option" config values to provide static IP addresses and default gateways to LXD hosts using their hostnames. After the 2.3 upgrade, this no longer working, I think maybe it is because "--dhcp-hostsfile" is specified as an arg to dnsmasq, not sure if this was always the case. the "/var/lib/lxd/networks/lxdbr0/dnsmasq.hosts" is read only too. What is the recommended way, still the above? |
|
You can just set ipv4.address and/or ipv6.address in your container's device entry which will then generate a dhcp-host line for you. |
|
lxc network attach lxdbr0 c1 eth0 |
bradenwright
commented
Oct 4, 2016
|
@stgraber thanks again for adding support for this ^^^ I know its been in a little while, but it was really much appreciated! |
henrylawson
commented
Oct 4, 2016
|
Thanks @stgraber, that worked :) Not sure if it is always required but I had to execute all of the below:
Without Without Is it possible to also My use case here, is that 1 container is a transparent proxy (needs static IP). Other hosts will have their default router set to the transparent proxy's IP. I had this setup with the previous networking model as it all lived in the |
|
Hmm, that's odd, host_name shouldn't be needed for ipv4.address. It sounds like this may have regressed a bit when I introduced the mac_filtering feature... LXD doesn't do any filtering on raw.dnsmasq so I'm not sure why dnsmasq is ignoring your dhcp-option in there. It may be because LXD is always generating one for DNS management when dns.mode is managed. If that's the problem, then doing: lxc network set lxdbr0 dns.mode dynamic |
bradenwright
commented
Oct 5, 2016
|
FYI, I can confirm that this works for me: I do publish a container for static purposes, after I run: Otherwise I get a dhcp address and static ip |
wtayyeb
commented
Oct 5, 2016
•
|
I have done it with new lxc network command: create
then run
it will restart dnsmasq and load the hostsfile and set new ips to c1, c2 each time the above hostsfile changed one must restart the lxd service or fake edit the network configs to changes take effect. (also need to restart the container) |
|
Interesting, good to know! |
vthiagarajan
commented
Oct 17, 2016
|
I am trying LXD new to build Linux based infrastructure container. when i setup it with init command, i let it use the default private subnet 10.140.216.1 it took since I dont want to create any issues with existing network. I created a container and setup static IP from valid internal network of the actual host, but since lxdbr0 shows 10.140.216.1 its not bridging the connection to the actual container. How do I change this to match with host network? at the sametime without impacting any existing systems on the subnet/VLAN. Actual host is on: 10.250.120.0/24 #ifconfig -a lxdbro0 Link encap:Ethernet HWaddr XX:XX:XX:XX:XX:XX #lxc list |
This was referenced Oct 20, 2016
jsaintrocc
commented
Mar 12, 2017
|
Looks like the newer releases of LXD (I'm using 2.11) make this fairly trivial using cloud-init. Caveats are that you need a cloud-init based image (like the ones at https://cloud-images.ubuntu.com/releases). Full documentation is here https://github.com/lxc/lxd/blob/master/doc/cloud-init.md
|
kirgene commentedJun 6, 2016
So how can I set static IP for containers?