From 58ad18cbc6b1696014c2ecf9bdb94271f63b44f0 Mon Sep 17 00:00:00 2001 From: magikcypress Date: Mon, 13 Feb 2017 19:43:51 +0100 Subject: [PATCH] =?UTF-8?q?On=20utilise=20dhcp=20sur=20le=20container,=20l?= =?UTF-8?q?e=20r=C3=A9seau=20ne=20fonctionne=20pas=20bien=20sur=20une=20IP?= =?UTF-8?q?=20fixe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sub_scripts/lxc_build.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sub_scripts/lxc_build.sh b/sub_scripts/lxc_build.sh index c4158c2..dfaf66b 100755 --- a/sub_scripts/lxc_build.sh +++ b/sub_scripts/lxc_build.sh @@ -33,6 +33,7 @@ sudo apt-get install -y lxc lxctl >> "$LOG_BUILD_LXC" 2>&1 os_name=$(sed -n -e '/PRETTY_NAME/ s/^.*=\|"\| .*//gp' /etc/os-release); if [ os_name == "Ubuntu" ] then + echo -e "\e[1m> Install lxc-templates debootstrap si Ubuntu\e[0m" | tee "$LOG_BUILD_LXC" sudo apt-get install -y lxc-templates debootstrap >> "$LOG_BUILD_LXC" 2>&1 fi @@ -69,8 +70,8 @@ sudo ifup $LXC_BRIDGE --interfaces=/etc/network/interfaces.d/$LXC_BRIDGE >> "$LO echo -e "\e[1m> Configuration réseau du conteneur\e[0m" | tee -a "$LOG_BUILD_LXC" sudo sed -i "s/^lxc.network.type = empty$/lxc.network.type = veth\nlxc.network.flags = up\nlxc.network.link = $LXC_BRIDGE\nlxc.network.name = eth0\nlxc.network.hwaddr = 00:FF:AA:00:00:01/" /var/lib/lxc/$LXC_NAME/config >> "$LOG_BUILD_LXC" 2>&1 -echo -e "\e[1m> Configuration réseau de la machine virtualisée\e[0m" | tee -a "$LOG_BUILD_LXC" -sudo sed -i "s@iface eth0 inet dhcp@iface eth0 inet static\n\taddress $PLAGE_IP.2/24\n\tgateway $PLAGE_IP.1@" /var/lib/lxc/$LXC_NAME/rootfs/etc/network/interfaces >> "$LOG_BUILD_LXC" 2>&1 +# echo -e "\e[1m> Configuration réseau de la machine virtualisée\e[0m" | tee -a "$LOG_BUILD_LXC" +# sudo sed -i "s@iface eth0 inet dhcp@iface eth0 inet static\n\taddress $PLAGE_IP.2/24\n\tgateway $PLAGE_IP.1@" /var/lib/lxc/$LXC_NAME/rootfs/etc/network/interfaces >> "$LOG_BUILD_LXC" 2>&1 echo -e "\e[1m> Configure le parefeu\e[0m" | tee -a "$LOG_BUILD_LXC" sudo iptables -A FORWARD -i $LXC_BRIDGE -o $main_iface -j ACCEPT >> "$LOG_BUILD_LXC" 2>&1 @@ -85,6 +86,9 @@ sudo lxc-ls -f >> "$LOG_BUILD_LXC" 2>&1 echo -e "\e[1m> On lance l'interface réseau\e[0m" | tee -a "$LOG_BUILD_LXC" sudo lxc-attach -n $LXC_NAME -- /etc/init.d/networking start +echo -e "\e[1m> On récupére l'ip du container\e[0m" | tee -a "$LOG_BUILD_LXC" +IP_CONTAINER=$(sudo lxc-attach -n $LXC_NAME -- ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + echo -e "\e[1m> Update et install aptitude sudo git\e[0m" | tee -a "$LOG_BUILD_LXC" sudo lxc-attach -n $LXC_NAME -- apt-get update sudo lxc-attach -n $LXC_NAME -- apt-get install -y aptitude sudo git @@ -113,7 +117,7 @@ sudo lxc-attach -n $LXC_NAME -- chown pchecker: -R /home/pchecker/.ssh >> "$LOG_ echo | tee -a $HOME/.ssh/config <> "$LOG_BUILD_LXC" 2>&1 # ssh $LXC_NAME Host $LXC_NAME -Hostname $PLAGE_IP.2 +Hostname $IP_CONTAINER User pchecker IdentityFile $HOME/.ssh/$LXC_NAME EOF