Creating network bridge linux

How to Configure Network Bridge in Ubuntu

Linux supports the implementation of a software network bridge to reproduce the function of a network bridge, a networking device that interconnects two or more communication networks or network segments providing a way for them to work as a single network. It acts almost like a network switch, and in a software sense, it is used to implement the concept of a “virtual network switch”.

A typical use case of software network bridging is in a virtualization environment to connect virtual machines (VMs) directly to the host server network. This way, the VMs are deployed on the same subnet as the host and can access services such as DHCP and much more.

In this article, you will learn different ways to set up a network bridge in Ubuntu and use it within a virtualization environment to create virtual networking in a bridged mode under VirtualBox and KVM, to connect Virtual Machines to the same network as the host.

On this page:

Installing Network Bridge Utilities in Ubuntu

Begin by installing the bridge-utils package which contains utilities for configuring the Ubuntu ethernet bridge using the apt package manager as shown.

$ apt-get install bridge-utils

Next, identify the interface name for your ethernet device using the IP command as shown.

Check Network Interfaces in Ubuntu

Creating a Network Bridge Using NetPlan in Ubuntu

Netplan is a simple and easy-to-use front-end utility for configuring networking in Linux using the YAML format. It currently supports NetworkManager and systemd-netword as backend tools.

To configure networking for an interface such as a bridge, edit your netplan configuration file found in /etc/netplan/ directory.

The following is an example configuration file, where the renderer is systemd-netword which is the default (replace enp1s0 with your ethernet interface name).

network: version: 2 renderer: networkd ethernets: enp1s0: dhcp4: no bridges: br0: dhcp4: yes interfaces: - enp1s0 

Netplan Configuration File

Save the configuration file and apply the configuration to enable the bridge network by running the following command.

Читайте также:  Клавиши для переключения языка линукс минт

Then use the brctl command to show all bridges on the system. In this case, the Ethernet interface is automatically added as a port to the bridge.

Show Network Bridges

If you want to bring down or deactivate the created network bridge, then delete it using the following commands.

$ sudo ip link set enp1s0 up $ sudo ip link set br0 down $ sudo brctl delbr br0 OR $ sudo nmcli conn up Wired\ connection\ 1 $ sudo nmcli conn down br0 $ sudo nmcli conn del br0 $ sudo nmcli conn del bridge-br0

Creating a Network Bridge Using Nmcli in Ubuntu

nmcli is a widely-used network manager command-line tool to administer NetworkManager (create, show, edit, delete, activate, and deactivate network connections) and displaying network device status.

To create a network bridge using nmcli, run the following command.

$ sudo nmcli conn add type bridge con-name br0 ifname br0

Create a Network Bridge Using nmcli Tool

Then add the Ethernet interface as a port in the bridge as shown (remember to replace enp1s0 with your device name).

$ sudo nmcli conn add type ethernet slave-type bridge con-name bridge-br0 ifname enp1s0 master br0

Add a Network Bridge Ports

Next, confirm that the bridge has been created by showing all network connections.

$ sudo nmcli conn show --active

Verify Network Bridge

Next, activate the bridge connection as follows (you can use either the connection/interface name or the UUID).

$ sudo nmcli conn up br0 OR $ sudo nmcli conn up e7385b2d-0e93-4a8e-b9a0-5793e5a1fda3

Activate Bridge Network Connection

Then deactivate the Ethernet interface or connection.

$ sudo nmcli conn down Ethernet\ connection\ 1 OR $ sudo nmcli conn down 525284a9-60d9-4396-a1c1-a37914d43eff

Deactivate Ethernet Connection

Now try to view active connections once more, the Ethernet interface should now be a slave in the bridge connection as shown in the following screenshot.

$ sudo nmcli conn show --active

Check Active Network Connections

Creating a Network Bridge Using nm-connection-editor Tool

To open the nm-connection-editor application, run the following command from the terminal.

From the network connections editor window, click on the + sign to add a new connection profile.

Add a New Network Connection

Next, choose the connection type as Bridge from the drop-down and click Create.

Select Network Connection Type

Next, set the bridge connection name and the interface name.

Читайте также:  Linux отменить последнее обновление

Set Bridge Connection Name

Then click the Add button to add the bridge slave ports i.e the Ethernet interface as shown in the following screenshot. Select Ethernet as the connection type and click Create.

Add a Network Bridge Connection

Next, set the connection name according to your preference and click Save.

Set New Bridge Connection Name

Under bridged connections, the new connection should now appear.

Verify New Bridge Connection

Now if you open the network connection editor once more, the new bridge interface and the slave interface should exist as indicated in the following screenshot.

Check Network Bridge Connection

Next, activate the bridge interface and deactivate the Ethernet interface, using the nmcli command.

$ sudo nmcli conn up br0 $ sudo nmcli conn down Ethernet\ connection\ 1

How to Use a Network Bridge in a Virtualization Software

After setting up a network bridge (virtual network switch), you can use it in a virtualization environment such as Oracle VirtualBox and KVM to connect VMs to the host network.

Using a Network Bridge in Oracle VirtualBox

Open VirtualBox, then from the list of VMs, select a VM, then click on its settings. From the settings window, go to the Network option and select an adapter (e.g Adapter 1).

Then check the option Enable Network Adapter, set the value of the attached to the field to Bridged Adapter, then set the Name of the bridged interface (e.g br0) as indicated in the following screenshot. Then click Ok.

Configure VM to Use Bridge Network in VirtualBox

Using a Network Bridge in KVM

You can use the new network bridge under KVM by adding the —network=bridge=br0 option while creating a new virtual machine, using the virt-install command.

# virt-install --virt-type=kvm --name Ubuntu18.04 --ram 1536 --vcpus=4 --os-variant=ubuntu18.04 --cdrom=/path/to/install.iso --network=bridge=br0,model=virtio --graphics vnc --disk path=/var/lib/libvirt/images/ubuntu18.04.qcow2,size=20,bus=virtio,format=qcow2

From the web console, it will be select automatically. Besides, you can also configure a network bridge using the virsh command-line tool, and a VM’s XML configuration file.

For more details, read the netplan and nmcli man pages (by running man netplan and man nmcli ) as well as virtual networking in libvirt and virtual networking in VirtualBox. You can post any queries to us via the comment section below.

Источник

Как настроить сетевой мост (br0) на Ubuntu Linux 14.04 и 16.04 LTS

В данном посте пойдет речь о том, как настроить сетевой мост на сервере с ОС Ubuntu 14.04 LTS или 16.04 LTS.

Читайте также:  Изменить размер экрана линукс

Сетевой мост — это ничто иное, как простой технический способ соединения с внешней сетью через физический интерфейс. Это полезно при использовании виртуализации LXC/KVM/Xen/Containers и других виртуальных интерфейсов. В этом туториале будет рассказано как можно настроить мост Linux используя bridge-utils (brctl) на сервер с Ubuntu.

В этом примере eth0 и eth1 — это физический сетевой интерфейс. eth0 соединяется с LAN и eth1 соединен непосредственно с оборудованием провайдера.

Установка bridge-utils

Введите команду apt-get для установки bridge-utils:

$ sudo apt-get install bridge-utils 
$ sudo apt install bridge-utils 

Создаем сетевой мост на сервере с Ubuntu

Редактируем /etc/network/interfaces используя текстовый редактор такой как nano, vi или любой другой любимый Вами редактор, и вводим:

$ sudo cp /etc/network/interfaces /etc/network/interfaces.bakup-1-july-2016 $ sudo vi /etc/network/interfaces 

Далее установим eth1 и метим его как br1, вводим:

# br1 имеет статический IPv4 адрес, шлюз для него - роутер провайдера auto br1 iface br1 inet static address 208.43.222.51 network 255.255.255.248 netmask 255.255.255.0 broadcast 208.43.222.55 gateway 208.43.222.49 bridge_ports eth1 bridge_stp off bridge_fd 0 bridge_maxwait 0 

Устанавливаем eth0 и метим его как br0, вводим:

auto br0 iface br0 inet static address 10.18.44.26 netmask 255.255.255.192 broadcast 10.18.44.63 dns-nameservers 10.0.80.11 10.0.80.12 # set static route for LAN post-up route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.18.44.1 post-up route add -net 161.26.0.0 netmask 255.255.0.0 gw 10.18.44.1 bridge_ports eth0 bridge_stp off bridge_fd 0 bridge_maxwait 0 

Заметка про br0 и DHCP

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

Сохраните и закройте файл.

Перезапускаем сервер или сетевой сервис

Теперь нужно перезагрузить сервер или ввести команду для перезапуска сетевого сервиса:

$ sudo systemctl restart networking 

Если используется Ubuntu 14.04 LTS или более старая версия дистрибутива, введите:

$ sudo /etc/init.d/restart networking 

Команда проверки связности

Используем команду ping/ip для того, чтобы убедиться в доступности интерфейсов LAN и WAN:

# смотрим состояние br0 и br1 ip a show # проверяем маршрутизацию ip r # проверяем доступность внешних ресурсов ping -c 2 8.8.8.8 # проверяем доступность внутренней сети ping -c 2 10.0.80.12 

Теперь можно сконфигурировать XEN/KVM/LXC контейнеры, чтобы использовать br0 и br1 и получить доступ непосредственно к Интернету или внутренней LAN. Таким образом отпадает потребность в установке специальной таблицы маршрутизации или создания iptables, SNAT правил.

Источник

Оцените статью
Adblock
detector