
我使用以下指南在我的 Ubuntu 14.04 伺服器上建立了一個橋接。
現在我想為我的虛擬機器指派一個靜態公用IP。我該怎麼做?
答案1
編輯們有一個不同的問題,但基本上與我在這裡回答的問題相同。對此不熟悉,所以不確定是否/如何合併 -Ping 到 LXC 容器
除了橋接之外,您還需要確保 Linux 容器上有一個專用的虛擬網路卡,然後將為該網路卡指派主機網路上的 IP 位址。
以下是核心說明,但是詳細的步驟和背景來自這篇盆景框架文章。
在主機上建立永久 macvlan
/etc/network/interfaces
新增到主機檔案的底部,# Creates a macvlan interface called macvlan0 without an IP address iface mvlan0 inet manual pre-up ip link add mvlan0 link eth0 address 8a:38:2a:cc:d7:aa type macvlan mode bridge post-down ip link del macvlan0 auto mvlan0
重新啟動系統以使變更生效。mvlan0
使用檢視網路設備時,您會注意到現在ifconfig -a
。
macvlan
透過修改位於 中的設定檔將容器連接到主機/var/lib/lxc/[container]/config
。
為您的新網卡新增的條目,
# macvlan for external IP lxc.network.type = macvlan lxc.network.macvlan.mode = bridge lxc.network.flags = up lxc.network.link = mvlan0 lxc.network.hwaddr = 00:16:3e:8d:4f:51 lxc.network.name = eth0
對於 hwaddr,透過免費網站(如helion.org。
最後,調整容器內的介面檔案以透過靜態綁定,或者如果您喜歡使用動態綁定。
就我而言,我調整了我的家庭路由器,以便 192.168.0.1 到 192.168.0.20 不是動態分配的,而是在我的 LXC 中使用靜態。
所以我修改我的容器介面檔如下,
auto eth0
iface eth0 inet static
address 192.168.0.12
gateway 192.168.0.1
netmask 255.255.255.0
auto eth1
iface eth1 inet dhcp
重新啟動您的 Linux 容器。