[Lxc-users] Set default GW

Gordon Henderson gordon at drogon.net
Wed Jun 9 20:55:28 UTC 2010


On Wed, 9 Jun 2010, Bodhi Zazen wrote:

> Daniel - Thank you for answering, not a big deal.
>
> Gordon - Aye, that is what I do for containers. For applications I write an "init" script
>
> #!/bin/bash
>
> route add default gw 192.168.0.1 eth0
>
> Additional commands / config
>
> service start foo

> or what not (depending on the application).
>
> then
>
> lxc-execute -n foo -f foo.config /path_to/init_script

Actually, I sort of mis-read your mail and later realised you already were 
using an init script.

In my init scripts, I often do a bit more - and often the default route 
isn't on the same network that container's IP address is (same physical 
LAN, different subnet) - a (real, live!) example:

In the config file, I have:

lxc.network.ipv4 = 195.10.226.165/27

and in the init script, (/etc/init.d/rcS) I have:

   route add -net 195.10.225.64  netmask 255.255.255.224 dev eth0
   route add -net 195.10.230.96  netmask 255.255.255.240 dev eth0
# route add -net 195.10.226.160 netmask 255.255.255.224 dev eth0

   route add default gw 195.10.225.67

   ifconfig eth0:53 195.10.226.164 netmask 255.255.255.224
   ifconfig eth0:25 195.10.230.105 netmask 255.255.255.240

   sh /etc/network/firewall

So how generic or otherwise should the config file be? I'd hate to see it 
hard-wired into something that doesn't allow me that sort of 
flexability... Although for starting simple applications (which I've no 
use for), I can see it might be handy.

Gordon




More information about the lxc-users mailing list