Ликбез по бриджам

Fragaria

Народ, нужен некоторый ликбез на тему "Создание виртуального сетевого адаптера в Linux и бриджи"
Мне нужно создать для guest-машины VirtualBox виртуальный же сетевой адаптер и назначить ему айпишник, чтобы повесить на него guest-машину. В результате должно получиться так, что гостевая машина является отдельным хостом в моей локалке и я могу пинговать её с хостовой машины.
Есть мануал к VirualBox, где всё это описано. Вот та часть, которая касается настройки устройств (красным выделено то, что мне непонятно):
6.5.1. Permanent host interfaces and bridging
On Linux hosts, setting up a permanent host interface using bridging typically consists of three steps:
First, you must create a bridge on the host and add one of the host's physical network interfaces to it, usually eth0. This will let you connect that interface to the virtual interfaces used by the virtual machines.
Keep in mind that bridging is an Ethernet concept, not a TCP/IP one. In physical networking, bridging is normally used to connect two Ethernet networks, letting computers on the one communicate with computers on the other through a single point of contact without having to merge the networks into one. [3]
For each guest network card that uses host interface networking, you must create a new "virtual" host interface (usually called vbox0 or similar) and add this interface to the bridge.
Finally, specify the name of the new host interface in the settings of the virtual machine's virtual network card.
Unfortunately, Linux distributions differ substantially in how they do network configuration. As we cannot provide instructions for all Linux distributions, we have restricted ourselves to describing how to set up bridging on Debian, Ubuntu, Fedora/Red Hat and openSUSE; in addition, we offer some generic instructions for advanced users.
VirtualBox ships with two utilities, VBoxAddIF and VBoeleteIF, which work on all distributions. These tools allow you to create and delete permanent host interfaces (which will not disappear when you restart your host computer) and optionally add them to an existing bridge. We also provide a utility called VBoxTunctl which you can use to create a temporary interface. These tools are described in Section 6.5.1.5, “Host Interface Networking utilities for Linux”. Even if you use plan to use host interfaces to create other networking setups than what we describe here, we recommend that you read the following instructions in order to get an understanding of how the interfaces work.
Some distributions — such as Debian and Ubuntu — have built-in tools to create host interfaces; you may also use those tools on those distributions.
6.5.1.1. Debian and Ubuntu hosts
To set up a permanent host interface on a modern Debian or Ubuntu host, follow these steps:
First install the bridge utilities (bridge-utils). package. You can do this from the command line as follows
sudo apt-get install bridge-utils

Next, you must add an entry to the file /etc/network/interfaces to describe the bridge. The following sample entry creates a bridge called br0, adds the host ethernet interface eth0 to it and tells it to obtain an IP address using DHCP so that the host remains able to access the network.

auto br0
iface br0 inet dhcp
bridge_ports eth0

You will probably want to change this to suit your own networking needs. In particular, you may want to assign a static IP address to the bridge. You will find more documentation in the files
/usr/share/doc/bridge-utilities/README.Debian.gz and
/usr/share/doc/ifupdown/examples/network-interfaces.gz.
Непонятно: какому интерфейсу я должен присвоить свой айпи, под которым у меня комп в сетку ходит? eth0, как раньше, или этому бриджу br0? И если бриджу, то как тогда настраивать мой eth0? Тут бридж получает IP по DHCP, в данном примере он получит тот же, который имела eth0, или другой, под которым будет в сетке видна guest-машина?
Restart networking on the host:

sudo /etc/init.d/networking restart

After this the bridge will remain on your system even after a restart.
Now, to create a permanent host interface called vbox0 (all host interfaces created in this way must be called vbox followed by a number) and add it to the network bridge created above, use the following command (see Section 6.5.1.5, “Host Interface Networking utilities for Linux” for more details):

sudo VBoxAddIF vbox0 <user> br0

Replace <user> with the name of the user who is supposed to be able to use the new interface.
To tell VirtualBox to use the interface, select the virtual machine which is to use it in the main window of the VirtualBox application, configure one of its network adaptors to use Host Interface Networking (using "Settings", "Network", "Attached to") and enter vbox0 into the "Interface name" field.
Alternatively, you can use the VBoxManage command line tool (in this example we are attaching the interface to the first network card of the virtual machine "My VM"):

VBoxManage modifyvm "My VM" -hostifdev1 vbox0

To set up a host interface using Debian and Ubuntu's native methods, do the following instead of step 4 above:
First install the User Mode Linux utilities package (uml-utilities which contains tools to create TAP interfaces. You can do this from the command line as follows:

sudo apt-get install uml-utilities

In order for VirtualBox to be able to access the interface, the user who will be running the virtual machine must be added to the group uml-net, for example with the following command (replace <user> with your user name):

sudo gpasswd -a <user> uml-net

You will have to log in again for the change to take effect.
To describe the TAP interface to your Debian or Ubuntu system, add an entry to the file /etc/network/interfaces. This names the the interface and must also specify the user who will be running the virtual machine using the interface.
The following sample entry creates the interface tap0 for the user <user> (again, replace with your user name):

auto tap0
iface tap0 inet manual
up ifconfig $IFACE 0.0.0.0 up
down ifconfig $IFACE down
tunctl_user <user>

Почему тут стоит адрес 0.0.0.0? Это имеет какой-то особый смысл или его нужно заменить на какой-то осмысленный? Если да, то на какой? И почему такая странная настройка адаптера, не static, а именно manual?
You will probably want to change the entry based on your networking needs. You will find documentation in the file /usr/share/doc/uml-utilities/README.Debian on your host computer.
To add the TAP interface to the bridge, replace the line

bridge_ports eth0

in the bridge section in /etc/network/interfaces with

bridge_ports eth0 tap0

Restart networking on the host:

sudo /etc/init.d/networking restart
Кроме того, я не понял, где присвоить айпи гостевой машине и как должен быть сконфи

kruzer25

Как же сложно вам, линуксоидам.

vall

если ты хочешь чтоб ип хост машины был один в обеих сетях то ставь его на бридж
0.0.0.0 это такой способ поднять интерфес не назначая ему никакой ип

kruzer25

Ворам должно быть сложно, ты с этим не согласен?
А если ты - честный человек, то никаких проблем нет.

Fragaria

окей, тогда что с конфигом eth0 делать?

vall

если его в бридж прописать то он сам будет подниматься без адреса при поднятии бриджа
там в этих /etc/network/if-*.d скриптах всё просто и понятно, я даже сам как-то такой писал для хитрожопого ната и маршрутизации по источнику

Fragaria

Сделал короче дословно так, как в мануале, только бриджу настройки статиком прописал те, что были у eth0.
Гостевая система (винда) стала запускаться, но после введения логина и пароля жрёт 99% ресурсов и ничо не делает. Видимо что-то случилось (с) :)
Я думаю, это потому, что винда пытается лезть в домен за авторизацией, и что-то у неё не получается с этими виртуальными интерфейсами :(

Fragaria

Со второго раза винда загрузилась, всё заработало :) УРА!

Fragaria

Х...Й.
С хоста и из локалки не пингуется гест, хотя с геста пингуется хост и вся остальная локалка. Видимо что-то с маршрутами, подскажите, как настроить или хотя бы диагностировать проблему?
Моя таблица маршрутизации на хосте:

$ route -n
Таблица маршутизации ядра протокола IP
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 br0
0.0.0.0 192.168.50.2 0.0.0.0 UG 100 0 0 br0
Оставить комментарий
Имя или ник:
Комментарий: