From 2e15716eead40c5cec0793e677259fd3cd10a4b7 Mon Sep 17 00:00:00 2001 From: Aleksandr O. Levchuk Date: Mon, 22 Jun 2009 19:14:30 -0700 Subject: [PATCH] Fix in debian-add_ip.sh config, missing network route This patch creates a way for containers to connect to the different private networks that surround them. I had to make this patch because my Debain containers have to access multiple networks (192.168.1.0/24, 192.168.3.0/24, etc...). This patch adds a new routes for each IP. A route points to a network X when a new IP Y is added. The Network X is implicitly derived from the IP Y. This is done in a simplified way, but it will work in most cases. Simply the last byte of X is replaced with 0, to produce Y. For example, when you run: vzctl set ycao-chemolddb \ --ipdel all \ --ipadd 192.168.16.53 \ --ipadd 192.168.1.53 \ --save The resulting Debain /etc/network/interfaces will look like this: # This configuration file is auto-generated. # WARNING: Do not edit this file, your changes will be lost. # Please create/edit /etc/network/interfaces.head and /etc/network/interfaces.tail instead, # their contents will be inserted at the beginning and at the end # of this file, respectively. # Auto generated interfaces auto lo iface lo inet loopback auto venet0 iface venet0 inet static address 127.0.0.1 netmask 255.255.255.255 broadcast 0.0.0.0 up route add -net 138.23.192.1 netmask 255.255.255.255 dev venet0 up route add default gw 138.23.192.1 auto venet0:0 iface venet0:0 inet static address 192.168.16.53 netmask 255.255.255.255 broadcast 0.0.0.0 up route add -net 192.168.16.0 netmask 255.255.255.0 dev venet0:0 auto venet0:1 iface venet0:1 inet static address 192.168.1.53 netmask 255.255.255.255 broadcast 0.0.0.0 up route add -net 192.168.1.0 netmask 255.255.255.0 dev venet0:1 --- etc/dists/scripts/debian-add_ip.sh | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/etc/dists/scripts/debian-add_ip.sh b/etc/dists/scripts/debian-add_ip.sh index 331eef9..f40a090 100755 --- a/etc/dists/scripts/debian-add_ip.sh +++ b/etc/dists/scripts/debian-add_ip.sh @@ -79,13 +79,16 @@ function create_config() { local ip=$1 local ifnum=$2 + local network=${ip%.*}.0 + local dev=${VENET_DEV}:${ifnum} if [ "${ip#*:}" = "${ip}" ]; then - echo -e "auto ${VENET_DEV}:${ifnum} -iface ${VENET_DEV}:${ifnum} inet static + echo -e "auto ${dev} +iface ${dev} inet static address ${ip} netmask 255.255.255.255 broadcast 0.0.0.0 + up route add -net ${network} netmask 255.255.255.0 dev ${dev} " >> ${CFGFILE}.bak else -- 1.5.4.5