Fedora 28: 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 bridge-utils + DHCP

#!/bin/sh


INTERFACE=ens3
MACADDR=$(/usr/sbin/ip a s ${INTERFACE} | \
            grep "link/ether" | awk '{ print $2 }')

sudo dnf install -y bridge-utils
cat <<EOF | sudo tee /etc/sysconfig/network-scripts/ifcfg-${INTERFACE}
TYPE="Ethernet"
MACADDR="${MACADDR}"
NAME="${INTERFACE}"
DEVICE="${INTERFACE}"
ONBOOT="yes"
BRIDGE="br0"
EOF
cat <<EOF | sudo tee /etc/sysconfig/network-scripts/ifcfg-br0
TYPE="Bridge"
BOOTPROTO="dhcp"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
EOF
sudo reboot

2 bridge-utils + Static IP Address

#!/bin/sh -e


INTERFACE=ens3
MACADDR=$(/usr/sbin/ip a s ${INTERFACE} | \
            grep "link/ether" | awk '{ print $2 }')

sudo dnf install -y bridge-utils
cat <<EOF | sudo tee /etc/sysconfig/network-scripts/ifcfg-${INTERFACE}
TYPE="Ethernet"
MACADDR="${MACADDR}"
NAME="${INTERFACE}"
DEVICE="${INTERFACE}"
ONBOOT="yes"
BRIDGE="br0"
EOF
cat <<EOF | sudo tee /etc/sysconfig/network-scripts/ifcfg-br0
TYPE="Bridge"
BOOTPROTO="none"
IPADDR="192.168.11.250"
NETMASK="255.255.255.0"
GATEWAY="192.168.11.1"
DNS1="192.168.11.2"
SEARCH="hiroom2.com"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
NAME="br0"
DEVICE="br0"
ONBOOT="yes"
EOF
sudo reboot

3 nmcli + DHCP

#!/bin/sh -e


INTERFACE=ens3

sudo nmcli con add type bridge ifname br0
sudo nmcli con mod bridge-br0 bridge.stp no
sudo nmcli con add type bridge-slave ifname ${INTERFACE} master bridge-br0
sudo reboot

4 nmcli + Static IP Address

#!/bin/sh -e


INTERFACE=ens3

sudo nmcli con add type bridge ifname br0
sudo nmcli con mod bridge-br0 bridge.stp no
sudo nmcli con add type bridge-slave ifname ${INTERFACE} master bridge-br0
sudo nmcli con modify bridge-br0 ipv4.method manual \
         ipv4.address "192.168.11.250/24" \
         ipv4.gateway "192.168.11.1" \
         ipv4.dns "192.168.11.2" \
         ipv4.dns-search "hiroom2.com"
sudo reboot

5 systemd-networkd + DHCP

#!/bin/sh -e


INTERFACE=ens3
MACADDR=$(/usr/sbin/ip a s ${INTERFACE} | grep 'link/ether' | \
            awk '{ print $2 }')

cat <<EOF | sudo tee /etc/systemd/network/br0.netdev
[NetDev]
Name=br0
Kind=bridge
EOF
cat <<EOF | sudo tee /etc/systemd/network/br0.network
[Match]
Name=br0

[Link]
MACAddress=${MACADDR}

[Network]
DHCP=yes
EOF
cat <<EOF | sudo tee /etc/systemd/network/${INTERFACE}.network
[Match]
Name=${INTERFACE}

[Network]
Bridge=br0

[Network]
DHCP=no
EOF
sudo systemctl enable systemd-networkd
sudo reboot

6 systemd-networkd + Static IP Address

#!/bin/sh -e


INTERFACE=ens3
MACADDR=$(/usr/sbin/ip a s ${INTERFACE} | grep 'link/ether' | \
            awk '{ print $2 }')

cat <<EOF | sudo tee /etc/systemd/network/br0.netdev
[NetDev]
Name=br0
Kind=bridge
EOF
cat <<EOF | sudo tee /etc/systemd/network/br0.network
[Match]
Name=br0

[Link]
MACAddress=${MACADDR}

[Network]
Address=192.168.11.250/24
Gateway=192.168.11.1
DNS=192.168.11.2
Domain=hiroom2.com
EOF
cat <<EOF | sudo tee /etc/systemd/network/${INTERFACE}.network
[Match]
Name=${INTERFACE}

[Network]
Bridge=br0

[Network]
DHCP=no
EOF
sudo systemctl enable systemd-networkd
sudo reboot