Dav*_*rks 4 networking network-bridge lxc
我有一个可以正常工作的 LXC 容器,但现在第二个容器出现异常。
我已经为它配置了一个静态路由,但它只是不会后确定的网关sudo services networking restart或之后reboot now,或者lxc-restart ...,对于相同的DNS服务器。只需设置 IP(在 LXC 容器配置文件中定义)。
它可以很好地 ping 默认网关 (10.1.0.1),但只是不设置默认网关路由或名称服务器。
davidparks21@WebApp:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 10.1.3.10
netmask 255.255.0.0
broadcast 10.1.255.255
gateway 10.1.0.1
dns-nameservers 8.8.8.8
dns-nameservers 8.8.4.4
Run Code Online (Sandbox Code Playgroud)
davidparks21@WebApp:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.1.0.0 * 255.255.0.0 U 0 0 0 eth0
Run Code Online (Sandbox Code Playgroud)
lxc.network.type=veth
lxc.network.name=eth0
lxc.network.link=br0
lxc.network.ipv4 = 10.1.3.10/16
lxc.network.flags=up
lxc.rootfs = /var/lib/lxc/WebApp/rootfs
lxc.utsname = prodweb1
Run Code Online (Sandbox Code Playgroud)
root@WebApp:/var/log# ifdown eth0 && ifup eth0
ifdown: interface eth0 not configured
RTNETLINK answers: File exists
Failed to bring up eth0.
Run Code Online (Sandbox Code Playgroud)
注意:在其他有效的 LXC 容器上,此命令成功。
添加此注释:
root@WebApp:/var/log# ethtool eth0
Settings for eth0:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Speed: 10000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
MDI-X: Unknown
Link detected: yes
Run Code Online (Sandbox Code Playgroud)
我认为问题应该是,“为什么在我重新启动或运行时没有配置 eth0 service networking restart”
root@WebApp:/var/log# ls /run/network/
ifstate ifup.lo
root@WebApp:/var/log# ifconfig
eth0 Link encap:Ethernet HWaddr ee:1d:b6:c7:8d:3d
inet addr:10.1.3.10 Bcast:10.1.255.255 Mask:255.255.0.0
inet6 addr: fe80::ec1d:b6ff:fec7:8d3d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:196 errors:0 dropped:0 overruns:0 frame:0
TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70482 (70.4 KB) TX bytes:1174 (1.1 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:48 errors:0 dropped:0 overruns:0 frame:0
TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3840 (3.8 KB) TX bytes:3840 (3.8 KB)
Run Code Online (Sandbox Code Playgroud)
小智 8
我已经在这个问题上工作了一段时间了。我在主机上运行 12.04 LXC 0.7.5,在容器中运行 12.04 和 11.04 的混合物。
我的编辑成功/run/networking/ifstate率为零:因为在容器重新启动后它似乎不会持续存在。
我通过注释掉容器config文件的以下行解决了这个问题:
lxc.network.ipv4 = 10.1.3.10/16
Run Code Online (Sandbox Code Playgroud)
另一个对我有用的解决方案是通过向后移植安装 LXC 8.0。您首先需要在/etc/apt/sources.list.
sudo apt-get install -t precise-backports lxc
Run Code Online (Sandbox Code Playgroud)
LXC 8.0 允许容器config文件配置默认网关。
lxc.network.ipv4.gateway = 10.1.0.1
Run Code Online (Sandbox Code Playgroud)