bridgeインターフェースの設定方法について記載します。bridgeを用いることで、KVMの仮想マシンやLXDのコンテナをホストマシンと同じネットワークに接続させることができます。
Table of Contents
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 + 静的IPアドレス
#!/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 + 静的IPアドレス
#!/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 + 静的IPアドレス
#!/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