How to launch ephemeral lxc with static ip address in such a way that it can connect to the internet? [closed]

StackOverflow https://stackoverflow.com/questions/15346819

I'm usung the lxc-start-ephemeral utility in Ubuntu 12.10. I've noticed that the ephemeral container starts up pretty quickly, but that it takes a long time (~20s) before ifconfig shows an ip address for its eth0 interface. I'd like to reduce this delay by as much as I can.

According to this post, the delay is due to dhcp. I followed the suggestion in the post and wrote a script that modifies the container's /etc/network/interfaces file to look like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
  address 10.0.3.$LXC_ADDRESS
  netmask 255.255.255.0

Now, the container's ip address is ready right away, and ssh ubuntu@10.0.3.$LXC_ADDRESS works fine. However, the container can't connect to the internet, for example ping www.google.com doesn't work.

What additional configuration do I need to do to correct this problem?

In case it helps, here's the container's current eth0 interface from ifconfig (with LXC_ADDRESS=131):

eth0      Link encap:Ethernet  HWaddr 00:16:3e:ed:ec:50  
          inet addr:10.0.3.131  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:feed:ec50/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:42 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6363 (6.3 KB)  TX bytes:5035 (5.0 KB)

and here's the veth interface on the host that seems to correspond to the container:

vethdzOk4n Link encap:Ethernet  HWaddr fe:dd:37:41:f2:06  
          inet6 addr: fe80::fcdd:37ff:fe41:f206/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:54 errors:0 dropped:0 overruns:0 frame:0
          TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8179 (8.1 KB)  TX bytes:8067 (8.0 KB)
有帮助吗?

解决方案

You actually can (I'm assuming) connect to the internet, you just don't have name service, because you're not running dhcp so you didn't get a resolv.conf.

Just put

nameserver 10.0.3.1

into /etc/resolv.conf in the container, (or just copy the resolv.conf from your host).

(If your container is running resolvconf, you might need to also put that line into /etc/resolvconf/resolv.conf.d/head in the container)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top