Ubuntu 17.04: Bridge interface

This article will describe creating bridge interface of ethernet. This makes that other machines in network can connect to virtual machines on KVM and containers on LXD via network.

1 Install bridge-utils package

Install bridge-utils package before creating bridge.

$ sudo apt install -y bridge-utils

2 Network interfaces of before creating bridge

Network interfaces of before creating bridge is as below. The string of ens3 depends on the ethernet device.

$ ifconfig
ens3      Link encap:Ethernet  HWaddr 52:54:00:cd:e1:2e
          inet addr:192.168.11.92  Bcast:192.168.11.255  Mask:255.255.255.0
          inet6 addr: fe80::7446:bbda:95b6:990e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:306 errors:0 dropped:0 overruns:0 frame:0
          TX packets:252 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:41145 (41.1 KB)  TX bytes:29880 (29.8 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:179 errors:0 dropped:0 overruns:0 frame:0
          TX packets:179 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:13539 (13.5 KB)  TX bytes:13539 (13.5 KB)

3 Create bridge

Add br0 setting to /etc/network/interfaces. Reboot system after setting.

$ sudo reboot

3.1 When using DHCP

$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto br0
iface br0 inet dhcp
      bridge_ports ens3
      bridge_stp off
      bridge_maxwait 0

3.2 When using static IP address

$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
      address 192.168.11.93
      netmask 255.255.255.0
      network 192.168.11.0
      broadcast 192.168.11.255
      gateway 192.168.11.1
      dns-nameservers 192.168.11.2 192.168.11.1
      dns-search hiroom2.com
      bridge_ports ens3
      bridge_stp off
      bridge_maxwait 0

4 Network interfaces of after creating bridge

br0 which has the same MAC address with ens3 is created. IP address is assigned to br0.

$ ifconfig
br0       Link encap:Ethernet  HWaddr 52:54:00:cd:e1:2e
          inet addr:192.168.11.92  Bcast:192.168.11.255  Mask:255.255.255.0
          inet6 addr: fe80::5054:ff:fecd:e12e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:90 errors:0 dropped:0 overruns:0 frame:0
          TX packets:119 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:10232 (10.2 KB)  TX bytes:15201 (15.2 KB)

ens3      Link encap:Ethernet  HWaddr 52:54:00:cd:e1:2e
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:102 errors:0 dropped:0 overruns:0 frame:0
          TX packets:118 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12437 (12.4 KB)  TX bytes:15111 (15.1 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:162 errors:0 dropped:0 overruns:0 frame:0
          TX packets:162 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:11938 (11.9 KB)  TX bytes:11938 (11.9 KB)