Ubuntu 17.10: 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.

$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
    link/ether 52:54:00:54:47:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.86/24 brd 192.168.11.255 scope global dynamic ens3
       valid_lft 43195sec preferred_lft 43195sec
    inet6 fe80::d994:6724:e148:4e5a/64 scope link
       valid_lft forever preferred_lft forever

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.

$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
master br0 state UP group default qlen 1000
    link/ether 52:54:00:54:47:c6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::5054:ff:fe54:47c6/64 scope link
       valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state
UP group default qlen 1000
    link/ether 52:54:00:54:47:c6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.86/24 brd 192.168.11.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe54:47c6/64 scope link
       valid_lft forever preferred_lft forever