如何用静态IP地址启动短暂的lxc以便连接到互联网?

问题描述:

我在Ubuntu 12.10中使用了lxc-start-ephemeral工具。我注意到临时容器启动很快,但是ifconfig显示其eth0接口的IP地址之前需要很长时间(〜20s)。我想尽可能地减少这种延迟。如何用静态IP地址启动短暂的lxc以便连接到互联网?

根据this post,延迟是由于dhcp引起的。我紧跟在后的建议,并写了一个脚本,修改容器的/ etc /网络/ interfaces文件看起来像这样:

auto lo 
iface lo inet loopback 

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

现在,容器的IP地址是准备马上和ssh [email protected]$LXC_ADDRESS工作正常。但是,容器无法连接到互联网,例如ping www.google.com不起作用。

需要额外的配置来纠正这个问题吗?

万一有帮助,这里是从命令ifconfig容器的当前eth0接口(带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) 

,这里是主机上的VETH接口,似乎对应于集装箱:

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) 

你实际上可以(我假设)连接到互联网,你只是没有名称服务,因为你没有运行dhcp,所以你没有得到resolv.conf。

只要把

域名服务器10.0.3.1

到/etc/resolv.conf中的容器,(或者只是从您的主机复制的resolv.conf)。

(如果你的容器运行需要resolvconf,您可能需要也把该行到/etc/resolvconf/resolv.conf.d/head容器)

+0

从塞尔离线沟通,解决的办法是'doroute add -host dev eth0',然后在临时容器上路由添加默认gw 。 – 2013-03-13 17:26:53