Mémo pour configurer une ip statique sur un container lxc.
Créer un réseau :
1 2 |
command lxc network create lxdbr1 command lxc network edit lxdbr1 |
Dans l’éditeur, changer l’adresse ip « ipv4.address ».
Exemple :
Pour un réseau 192.168.1.x, saisir 192.168.1.1/24 pour le réseau.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
### This is a YAML representation of the network. ### Any line starting with a '# will be ignored. ### ### A network consists of a set of configuration items. ### ### An example would look like: ### name: lxdbr0 ### config: ### ipv4.address: 10.62.42.1/24 ### ipv4.nat: true ### ipv6.address: fd00:56ad:9f7a:9800::1/64 ### ipv6.nat: true ### managed: true ### type: bridge ### ### Note that only the configuration can be changed. config: ipv4.address: 192.168.1.1/24 ipv4.nat: "true" description: "" name: lxdbr1 type: bridge used_by: [] managed: true status: Created locations: - none |
Attacher le réseau au container et configurer son ip :
1 2 3 4 |
command lxc stop mon_container command lxc network attach lxdbr1 mon_container eth0 eth0 command lxc config device set mon_container eth0 ipv4.address 192.168.1.10 command lxc start mon_container |
Vérifier avec :
1 2 3 4 5 6 |
command lxc list +---------------+---------+-----------------------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +---------------+---------+-----------------------+------+-----------+-----------+ | mon_container | RUNNING | 192.168.1.10 (eth0) | | CONTAINER | 0 | +---------------+---------+-----------------------+------+-----------+-----------+ |
Et voilà !
Source : https://discuss.linuxcontainers.org/t/using-static-ips-with-lxd/1291/6