[lxc-users] nat networking with fixed (dhcp ) IP addresses

Michel Jansens michel.jansens at ulb.ac.be
Fri May 25 08:25:13 UTC 2018


Thanks Fajar it works!

What I did:

#lets create a new profile  
lxc profile  copy default nonet

#remove network from the profile  
lxc profile  device remove nonet eth0

#create the ’testip' container
lxc init ubuntu:18.04 testip --profile nonet

#attach the network device to it, with IP address
lxc config  device add testip eth0 nic nictype=bridged parent=lxdbr0  host_name=testip ipv4.address=10.0.3.203

#Woops, didn’t work because I entered the wrong IP network, change IP to the right one
lxc config  device set testip eth0 ipv4.address 10.115.240.89
#check

lxc list testip
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
|  NAME  |  STATE  |         IPV4          |                     IPV6                     |    TYPE    | SNAPSHOTS |
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+
| testip | RUNNING | 10.115.240.123 (eth0) | fd3f:a1a8:9bb:fb1e:216:3eff:fea5:bf77 (eth0) | PERSISTENT | 0         |
+--------+---------+-----------------------+----------------------------------------------+------------+-----------+

#IT works!

A remark about the interface:
  it feels not coherent that when you add a device you use <key>=<value> and when you want to update a value in the device you use <key> <value>  


An afterthought: 
   after re-reading Stéphane Graber’s "Network management with LXD (2.3+)” ( https://blog.ubuntu.com/2017/02/14/network-management-with-lxd-2-3 <https://blog.ubuntu.com/2017/02/14/network-management-with-lxd-2-3> )  I realized that  the nat internal dns server registers all the container hostnames, so if my Ansible container is on the same lxdbr0 nat network, I coud just reference the different hosts by hostnames and forget about static IP.

—
Cheers,

Michel

> 
> One way that works is to specify eth0 in the container config file,
> overriding the profile.
> While you're at it you might wan to set host_name as well, so that the
> veth device name on the host side stays the same.
> 
> Example:
> devices:
>  eth0:
>    host_name: c1-0
>    ipv4.address: 10.0.3.203
>    name: eth0
>    nictype: bridged
>    parent: lxdbr0
>    type: nic
> 
> -- 
> Fajar
> _______________________________________________
> lxc-users mailing list
> lxc-users at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20180525/d4634705/attachment.html>


More information about the lxc-users mailing list