Отсутствует мост IP для LXC (контейнеры Linux)

1315
Lingyuan He

Я использую LXC (Linux Containers) для размещения http-сервера в настройке VirtualBox, но у простого созданного мной специального моста LXC нет IP-адреса, поэтому он недоступен даже в ОС Ubuntu, работающей на VirtualBox. (Мне не нужно обращаться к серверу с реальной хост-ОС, но я упоминаю это для полноты)

Я попробовал два способа, первый - это редактирование / etc / network / interfaces:

auto lxcbr0 iface lxcbr0 inet dhcp bridge_ports eth0 bridge_stp off bridge_fd 0 bridge_maxwait 0 

Специальных настроек для LXC нет.

Второй - использовать brctl:

sudo brctl addbr lxcbr0 sudo brctl addif lxcbr0 eth0 sudo ip link set dev lxcbr0 up 

В первом методе для LXC ifconfig показывает:

eth0 Link encap:Ethernet HWaddr 00:16:3e:e7:2c:8f  inet addr:10.0.2.26 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::216:3eff:fee7:2c8f/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:42 errors:0 dropped:0 overruns:0 frame:0 TX packets:29 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000  RX bytes:6146 (6.1 KB) TX bytes:2666 (2.6 KB) 

Но на канале нет:

lxcbr0 Link encap:Ethernet HWaddr 08:00:27:2b:85:76  inet6 addr: fe80::a00:27ff:fe2b:8576/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:168 errors:0 dropped:0 overruns:0 frame:0 TX packets:56 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0  RX bytes:9826 (9.8 KB) TX bytes:8968 (8.9 KB)  vethFEBAAO Link encap:Ethernet HWaddr fe:5c:88:b0:88:3b  inet6 addr: fe80::fc5c:88ff:feb0:883b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:33 errors:0 dropped:0 overruns:0 frame:0 TX packets:51 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000  RX bytes:3026 (3.0 KB) TX bytes:7041 (7.0 KB) 

Нет адреса IPv4 для моста на стороне хоста. Второй метод имеет аналогичную проблему.

Что мне не хватает?

3

1 ответ на вопрос

0
JakeGould

I am using LXC to host an http server in VirtualBox, but the simple bridge I created does not have an IP address, so it cannot be reached in the host.

I know your question specifically is about LXC (Linux Containers) which is something I am not 100% on, but I will provide some advice based on what I know about guest OS to host OS connections in VirtualBox. Maybe this dovetails with your LXC specific issue?

You say you want to have a simple bridge setup between the VirtualBox guest and the host, but what settings do you have in VirtrualBox for vboxnet0? To my knowledge, there are two places where the network settings need to be adjusted for a setup like this to work: Within the guest OS but also on the host OS itself.

I’m using a Mac, but the general concept should be the same for anyone else using VirtualBox on Windows or Linux: You need two adapters on a VirtualBox guest OS to ensure an outgoing network connection on the 10.x.x.xnetwork as well as a connection on the host only network which is usually192.168.x.x`.

If I go to “Preferences” when I launch VirtualBox and then click the “Network” icon and then click the “Host-only Networks” tab, I get a list of adapters I have setup:

enter image description here

Then—as shown in the screenshot—if I select vboxnet0 and then click the screwdriver icon, I can change options. Screenshot below:

enter image description here

I have the “IPv4 Address” set to 192.168.56.1 and the related IPv4 Network Mask set to 255.255.255.0. Now I usually have the DHCP server disabled as shown in the following screenshot:

enter image description here

Once that is setup, I make sure the guest OS in VirtualBox has the adapter enabled like this:

enter image description here

Note that I have a “Host-only Adapter” designated and that adapter is associated to vboxnet0? Once that is done, the guest OS should be fully aware of the host-only setup and you should be good to go.

Спасибо за ответ, я думаю, что исказил мою ситуацию. Мне не нужно обращаться к серверу с реальной хост-ОС, но я упоминаю VirtualBox для полноты. Все, что мне нужно сделать, это добраться до сервера в контейнере из ОС, работающей на VirtualBox. Lingyuan He 9 лет назад 1
@LingyuanHe Аааа, ладно ... Хост LXC для контейнера LXC. Определенно не то, что я касаюсь. Оставим это на месте пока. Можно удалить позже или обновить, если я опущу ответ. JakeGould 9 лет назад 0
@LingyuanHe Вы случайно просматриваете ответ здесь? http://ubuntuforums.org/showthread.php?t=2137446&p=12673212#post12673212 JakeGould 9 лет назад 0
Это полезно, я попробую кое-что там, но мне все еще нужно искать решение для временного моста brctl, хотя это кажется более подходящим для моих нужд. Спасибо! Lingyuan He 9 лет назад 1