Discussion:
LXD assigning static IP's at start tp containers
(too old to reply)
Kevin LaTona
2015-05-16 05:54:08 UTC
Permalink
I was reading about ways in legacy LXC of being able to have the DHCP server assign static IP's to containers at startup based upon container name.

If one is using Ubuntu 15.04, systemd and LXD is that still possible?

If so, can any one point towards any docs that might show how to do this?

Or if you are doing this can you sharing how you are doing this now with LXD based LXC containers?


Thanks
-Kevin
Kevin LaTona
2015-05-16 06:09:03 UTC
Permalink
Well I just found this link

http://askubuntu.com/questions/446831/how-to-let-built-in-dhcp-assign-a-static-ip-to-lxc-container-based-on-name-not

and much of what is talked about here appears to still applies to LXD.


Last thing that is hanging me up nowis how to change the dnsmasq config located at /etc/dnsmasq.d/lxc

from the 10.0.3.x default ip to some other ip like a 192.168.1.1.

When I tried doing this in the config file the lxcbr0 bridge did not boot up.

So some where I am missing some other setting that allows one to change this.

Any thoughts or ideas… would be much appreciated.

-Kevin
Post by Kevin LaTona
I was reading about ways in legacy LXC of being able to have the DHCP server assign static IP's to containers at startup based upon container name.
If one is using Ubuntu 15.04, systemd and LXD is that still possible?
If so, can any one point towards any docs that might show how to do this?
Or if you are doing this can you sharing how you are doing this now with LXD based LXC containers?
Thanks
-Kevin
_______________________________________________
lxc-users mailing list
http://lists.linuxcontainers.org/listinfo/lxc-users
Mark Constable
2015-05-16 07:30:33 UTC
Permalink
Post by Kevin LaTona
I was reading about ways in legacy LXC of being able to have the DHCP server
assign static IP's to containers at startup based upon container name.
If one is using Ubuntu 15.04, systemd and LXD is that still possible?
Hey Kevin, I just set something like this up and although this may not
be "the right way" to do it works for my situation which sounds somewhat
similar to what you are after. Best I should show my relevant config
files and some of this may help you or provide some ideas...

My main gateway/wireless/dhcp router is 192.168.0.1

~ grep -Ev "^(#|$)" /etc/default/lxc-net
USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="192.168.0.2"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.0.0/24"
LXC_DHCP_RANGE="192.168.0.2,192.168.0.54"
LXC_DHCP_MAX="53"
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf
LXC_DOMAIN="example.org"

And the magic to fill in the gaps above...

~ cat /etc/rc.local
sleep 5 && {
brctl addif lxcbr0 eth0
sleep 1
route add default gw 192.168.0.1
echo "nameserver 8.8.8.8" > /etc/resolv.conf
}
exit 0

~ cat /etc/lxc/dnsmasq.conf
dhcp-host=sysadm,192.168.0.3
dhcp-host=markc,192.168.0.4


I also remove ifupdown and resolvconf and set all my NetworkManager
interfaces not to "autoconnect=false" so if I need to switch to wifi
when moving my laptop away from an eth cable I can ifconfig down lxcbr0
select a wifi connection.
Kevin LaTona
2015-05-16 16:56:04 UTC
Permalink
Hi Mark,

I was thinking that by just updating the /etc/default/lxc-net config file from the 10.x.x.x to a 192.168.x.x that was going to do it for me.

It's not.

Some where else I am missing a spot that must be saying that the 10.0.x.x is the dnsmasq address.

As of right now at boot up the lxcbr0 is not loading in a base ubuntu 15.04 server install.

So I am still looking for that config setting to do that for me now rather than trying other methods.


Maybe someone else will adding in here to say where to find this blocking point.


Have to say a big thanks for showing how you used grep to grab the config file kv pairs.

Pretty cool use of grep….. I like how simple it is and it just works in this case.

Grep for me is another one of those never ending tools that one never fully recalls all the ways it can be used to grab some text.



-Kevin
Post by Mark Constable
Post by Kevin LaTona
I was reading about ways in legacy LXC of being able to have the DHCP server
assign static IP's to containers at startup based upon container name.
If one is using Ubuntu 15.04, systemd and LXD is that still possible?
Hey Kevin, I just set something like this up and although this may not
be "the right way" to do it works for my situation which sounds somewhat
similar to what you are after. Best I should show my relevant config
files and some of this may help you or provide some ideas...
My main gateway/wireless/dhcp router is 192.168.0.1
~ grep -Ev "^(#|$)" /etc/default/lxc-net
USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="192.168.0.2"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.0.0/24"
LXC_DHCP_RANGE="192.168.0.2,192.168.0.54"
LXC_DHCP_MAX="53"
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf
LXC_DOMAIN="example.org"
And the magic to fill in the gaps above...
~ cat /etc/rc.local
sleep 5 && {
brctl addif lxcbr0 eth0
sleep 1
route add default gw 192.168.0.1
echo "nameserver 8.8.8.8" > /etc/resolv.conf
}
exit 0
~ cat /etc/lxc/dnsmasq.conf
dhcp-host=sysadm,192.168.0.3
dhcp-host=markc,192.168.0.4
I also remove ifupdown and resolvconf and set all my NetworkManager
interfaces not to "autoconnect=false" so if I need to switch to wifi
when moving my laptop away from an eth cable I can ifconfig down lxcbr0
select a wifi connection.
_______________________________________________
lxc-users mailing list
http://lists.linuxcontainers.org/listinfo/lxc-users
Mark Constable
2015-05-16 17:24:08 UTC
Permalink
Post by Kevin LaTona
I was thinking that by just updating the /etc/default/lxc-net config file
from the 10.x.x.x to a 192.168.x.x that was going to do it for me.
Try this, first make sure ifupdown and NetworkManager are not interfering...

mv /etc/network/interfaces /etc/network/interfaces.orig
ll /etc/NetworkManager/system-connections/
# make sure each [connection] section has "autoconnect=false"

edit /etc/default/lxc-net to something like below...

USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="192.168.0.2"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.0.0/24"
LXC_DHCP_RANGE="192.168.0.2,192.168.0.54"
LXC_DHCP_MAX="53"
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf

Manually run these where 192.168.x.1 is your eth gateway...

ifconfig # eth0 up but without an IP, lxcbr0 should be 192.168.x.x

brctl addif lxcbr0 eth0
route add default gw 192.168.x.1
echo "nameserver 8.8.8.8" > /etc/resolv.conf

Make sure you can ping google.com on the host and bring up a container.
A default legacy container will attempt dhcp and should be able to hit
your gw routers dhcp server. For an unprivileged container you have to..

lxc exec <container name> bash
/etc/init.d/networking restart

This is a crude guide to a fairly simple default setup. If your container
gets a 192.168.x.x IP then your mostly there bar some extra fine tuning.
Kevin LaTona
2015-05-16 18:14:56 UTC
Permalink
Mark,

Thanks for all your ideas and lending a hand.

I figured it out.

I managed to have a small typo in my config file where I missed a 0 in of the addresses.

All working now.

-Kevin
Post by Mark Constable
Post by Kevin LaTona
I was thinking that by just updating the /etc/default/lxc-net config file
from the 10.x.x.x to a 192.168.x.x that was going to do it for me.
edit /etc/default/lxc-net to something like below...
USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="192.168.0.2"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.0.0/24"
LXC_DHCP_RANGE="192.168.0.2,192.168.0.54"
LXC_DHCP_MAX="53"
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf
Loading...