[Lxc-users] adding a default gateway inside a container as a non root user

Jäkel, Guido G.Jaekel at dnb.de
Fri Mar 2 07:23:05 UTC 2012


Dear Arun,

You may also use a DHCP environment to setup the containers network IP, routing, DNS-Servers etc. This approach will ease any changes of the network infrastructure and will help you to make your templates more generic. For that, you have the to assign a fix MAC address to the container and to configure a fixed parameter table (host/IP/MAC) at the dhcpd.

At my lxc-starter I'm using the formula

	IP=$(gethostbyname $CONTAINER)
	HWADDR=`IP=${IP#*.}; printf "00:50:C2:%02X:%02X:%02X" ${IP//./ }`        # a.b.c.d -> 00:50:C2:bb:cc:dd (hex)
	[...]
	lxc-start -n $CONTAINER  [...]  -s lxc.network.hwaddr=$HWADDR 

Guido

>> >> My tactical work around was to inject the route add into /etc/rc.d/rc.local
>> >> in the rootfs template for my LXC containers, so when I create each
>> >> container rc.local is staged, did the same with /etc/resolv.conf as well.

> > Hi,
> > 
> > I am trying to add a default gateway inside a lxc container so that the
> > application can talk to outside network.




More information about the lxc-users mailing list