Lxc container not getting default route

gatewaylxcroute

I'm running Ubuntu Precise. I understand that my current version of lxc doesn't support gateway/default route assignment (lxc 0.7.5-3ubuntu67).
I've been trying like heck to get a few lines to execute so that the default route can be set in the container:

#!/bin/bash -x
touch /root/route.txt
netstat -rn 2>&1 >> /root/route.txt
export defaultroute=`ifconfig eth0|grep Bcast|awk '{print $3}'|cut -d: -f2|awk -F. '{print $1"."$2"."$3".254"}'`
/sbin/route add default gw $defaultroute 2>&1 >> /root/route.txt
netstat -rn 2>&1 >> /root/route.txt

Very simple in theory. I'll be danged if I can figure out how to get this to execute.
I've inserted it near the end of rc.local. I've put it into the ssh init script.
I've attached it to other init scripts. Nothing. If I execute the commands after starting the container, they set the default route just fine.
My config for the container:

lxc.network.type = veth
lxc.network.link = br0
lxc.network.flags = up
lxc.network.ipv4 = 10.16.161.100/24
lxc.utsname = z100253

lxc.tty = 4
lxc.pts = 1024
lxc.rootfs = /var/lib/lxc/z100253/rootfs
lxc.mount  = /var/lib/lxc/z100253/fstab

lxc.cgroup.devices.deny = a
# /dev/null and zero
lxc.cgroup.devices.allow = c 1:3 rwm
lxc.cgroup.devices.allow = c 1:5 rwm
# consoles
lxc.cgroup.devices.allow = c 5:1 rwm
lxc.cgroup.devices.allow = c 5:0 rwm
#lxc.cgroup.devices.allow = c 4:0 rwm
#lxc.cgroup.devices.allow = c 4:1 rwm
# /dev/{,u}random
lxc.cgroup.devices.allow = c 1:9 rwm
lxc.cgroup.devices.allow = c 1:8 rwm
lxc.cgroup.devices.allow = c 136:* rwm
lxc.cgroup.devices.allow = c 5:2 rwm
# rtc
lxc.cgroup.devices.allow = c 254:0 rwm

from the lxc host I can ping the container and ssh to it without an issue. I just cant route to or from it. This is driving me crazy.

Best Answer

Had the same problem in debian wheezy. Starting from your idea I put a hardcoded script into /etc/init.d/networking

set_def_route() {
/sbin/route add default gw 192.168.1.1
}

and linked into the start option further down

case "$1" in
start)
       blah blab ...
       check_ifstate
       set_def_route

It works although very clumsy looking.

Related Topic