我正在运行 CentOS 6,并且安装了 OpenVZ(按照本指南安装)。我对虚拟化还很陌生,我只是将这些容器用于我自己的项目。
我遵循了该指南中的所有说明。
$ cat /proc/sys/net/ipv4/ip_forward
1
我使用 OpenVZ 的 CentOS 6 模板创建了一个 CentOS 6 容器。我还为容器添加了一个 IP 并设置了一个名称服务器。
主机的ifconfig:
eth0 Link encap:Ethernet HWaddr 00:30:48:A0:18:A8
inet addr:107.161.123.162 Bcast:107.161.123.167 Mask:255.255.255.248
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:255699 errors:0 dropped:0 overruns:0 frame:0
TX packets:40447 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:299527614 (285.6 MiB) TX bytes:3249925 (3.0 MiB)
Interrupt:28 Memory:fbce0000-fbd00000
eth0:0 Link encap:Ethernet HWaddr 00:30:48:A0:18:A8
inet addr:107.161.123.163 Bcast:107.161.123.167 Mask:255.255.255.248
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:28 Memory:fbce0000-fbd00000
eth0:1 Link encap:Ethernet HWaddr 00:30:48:A0:18:A8
inet addr:107.161.123.164 Bcast:107.161.123.167 Mask:255.255.255.248
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:28 Memory:fbce0000-fbd00000
eth0:2 Link encap:Ethernet HWaddr 00:30:48:A0:18:A8
inet addr:107.161.123.165 Bcast:107.161.123.167 Mask:255.255.255.248
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:28 Memory:fbce0000-fbd00000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:158 (158.0 b) TX bytes:158 (158.0 b)
venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
RX packets:393 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:29817 (29.1 KiB) TX bytes:0 (0.0 b)
我用来创建和启动容器的命令:
vzctl create 102 --ostemplate centos-6-x86_64
vzctl set 102 --ipadd 107.161.123.163 --save
vzctl set 102 --nameserver 8.8.8.8 --save
vzctl start 102
容器的ifconfig:
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:127.0.0.1 P-t-P:127.0.0.1 Bcast:0.0.0.0 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:47 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:2958 (2.8 KiB)
venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:107.161.123.163 P-t-P:107.161.123.163 Bcast:107.161.123.163 Mask:255.255.255.255
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
容器根本无法访问互联网,能ping通自己的IP(107.161.123.163),ping不通宿主机IP,也无法ping通8.8.8.8。
我是 Linux 虚拟化的新手。如能得到任何帮助我将不胜感激。
答案1
我解决了我的问题。原来是因为 IP 绑定到了主机上的接口,所以容器无法使用它。