19
0
Fork 0
wiki/HowtoLXC.md

2.1 KiB

Cette page a été importée automatiquement de notre ancien wiki mais n'a pas encore été révisée.

HowtoLXC

Debian 8 (JESSIE)

Installation

# apt install lxc bridge-utils libvirt-bin debootstrap

Modifications réseau

# cat /etc/network/interfaces
[...]
auto br0
iface br0 inet static
        bridge_ports eth0
        bridge_fd 0
        bridge_maxwait 0
        address 10.10.10.42
        netmask 255.255.255.0
        gateway 10.10.10.254

auto br1
iface br1 inet static
        pre-up brctl addbr br1
        address 10.1.0.254
        netmask 255.255.255.0
        bridge_fd 0
        post-down brctl delbr br1
# /sbin/iptables -A INPUT -p tcp --sport 11371 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT
# /sbin/iptables -t nat -A POSTROUTING -s 10.1.0.254/24 -o br0 -j SNAT --to *IP de l'hyperviseur*

Activation du forwarding

# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
# echo "net.ipv4.conf.all.arp_announce=2" >> /etc/sysctl.conf
# echo "net.ipv4.conf.all.arp_ignore=1" >> /etc/sysctl.conf
# echo "net.ipv4.conf.all.rp_filter=0" >> /etc/sysctl.conf
# sysctl -w net.ipv4.ip_forward=1
# sysctl -w net.ipv4.conf.all.rp_filter=0
# sysctl -w net.ipv4.conf.all.arp_ignore=1
# sysctl -w net.ipv4.conf.all.arp_announce=2

Installation d'un container

# lxc-create -t download -n test

Avant de démarrer la VM mettre ces lignes dans le fichier de conf du conteneur : ``/var/lib/lxc/test/config`

lxc.network.type = veth
lxc.network.link = br1
lxc.network.ipv4 = 10.1.0.X/24
lxc.network.ipv4.gateway = 10.1.0.254
lxc.network.name = eth0
lxc.network.flags = up

(Il est conseillé de supprimer systemd du container car ce dernier est mal géré pour le moment)

# apt install sysvinit-core

Utilisation

Démarrer un conteneur :

# lxc-start -n test -d

Entrer dans un conteneur :

# lxc-attach -n test

Arreter un conteneur :

# lxc-stop -n test

Autres commandes utiles :

# lxc-info -n test-container
# lxc-console -n test-container
# lxc-halt -n test-container
# lxc-info -n test-container
# lxc-destroy -n test-container