2

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.

Dennis Kaarsemaker
  • 19,277
  • 2
  • 44
  • 70
user176373
  • 53
  • 2
  • 4
  • 1
    Why not update your version of lxc? – Tommiie Dec 21 '18 at 06:06
  • That is what I ended up doing. version 0.8+ includes the ability to define a gateway/default route for each container config. So going that route makes more sense then having to futz with things at a lower level. Easier to manage this way and repeatable. Thank you for your response! – user176373 Jan 11 '19 at 22:31

1 Answers1

1

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.

slooow
  • 111
  • 1
  • Yes, that is one way to do it, but I ended up updating my version of lxc and I was able to define the default route for each container upon creation instead of mucking around with the net stack at a lower level that would have to be updated every time that script is updated by system updates. – user176373 Jan 11 '19 at 22:29
  • There is a different way of doing your approach that precludes having to futz with the init script. On RHEL systems, there is a dir under /etc/ that you can drop a script into that will get executed when the net stack is initialized. Same for Debian based. I just forget where those dirs are, but that is what the man pages and Google are for! – user176373 Jan 11 '19 at 22:33