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.
Table of Contents
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 eth0 depends on the ethernet device.
$ /sbin/ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.11.100 netmask 255.255.255.0 broadcast 192.168.11.255 inet6 fe80::e5c1:c910:eab8:b6db prefixlen 64 scopeid 0x20<link> ether 52:54:00:a9:35:e0 txqueuelen 1000 (Ethernet) RX packets 159 bytes 32455 (31.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 131 bytes 22623 (22.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 30 bytes 1986 (1.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 30 bytes 1986 (1.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
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 eth0 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 eth0 bridge_stp off bridge_maxwait 0
4 Network interfaces of after creating bridge
br0 which has the same MAC address with eth0 is created. IP address is assigned to br0.
$ /sbin/ifconfig br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.11.100 netmask 255.255.255.0 broadcast 192.168.11.255 inet6 fe80::5054:ff:fea9:35e0 prefixlen 64 scopeid 0x20<link> ether 52:54:00:a9:35:e0 txqueuelen 1000 (Ethernet) RX packets 51 bytes 10838 (10.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 66 bytes 11002 (10.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 52:54:00:a9:35:e0 txqueuelen 1000 (Ethernet) RX packets 54 bytes 11774 (11.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 65 bytes 10892 (10.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 12 bytes 740 (740.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 740 (740.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0