Centos

CentOS 主機,OpenVZ CentOS 容器有自己的 IP 無法訪問網際網路

  • September 13, 2015

我正在執行 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

容器根本無法訪問 Internet。它可以ping通自己的IP(107.161.123.163),無法ping通主機IP或8.8.8.8。

我是 Linux 虛擬化的新手。任何幫助將不勝感激。

我解決了我的問題。事實證明,由於 IP 綁定到主機上的介面,因此容器無法使用它。

引用自:https://serverfault.com/questions/722047