LinuxでのNICの冗長化設定(Bonding)

スポンサーリンク

RockyLinuxでNICの2つを使用して冗長化(二重化)構成にして、動作までの確認を行います。

検証した環境

$ cat /etc/os-release
NAME="Rocky Linux"
VERSION="9.2 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
$ uname -r
5.14.0-284.11.1.el9_2.x86_64

ボンディングの設定方法

ボンディングで使う用語で、下記のように使われます。

マスターインターフェース ・・・ 仮想NIC(Bond)。
スレーブインターフェース ・・・ 物理NIC。

設定前の状態確認

全部で4つあるNICのうち、「enp0s8」と「enp0s9」をボンディングで冗長化します。

$ nmcli device status
DEVICE   TYPE      STATE                   CONNECTION
enp0s3   ethernet  connected               enp0s3
enp0s10  ethernet  connected               enp0s10
enp0s8   ethernet  connected               enp0s8
enp0s9   ethernet  connected               enp0s9
lo       loopback  connected (externally)  lo
$ nmcli connection show
NAME     UUID                                  TYPE      DEVICE
enp0s3   ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
enp0s10  82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
enp0s8   c4df012f-ade4-4abc-afd4-585feecbd222  ethernet  enp0s8
enp0s9   645308fa-a364-459f-a8e0-84ce892cf6ee  ethernet  enp0s9
lo       e15765b2-b3f2-4712-8260-9326a2804670  loopback  lo

ボンディングの設定追加

「enp0s8」と「enp0s9」のコネクションを削除します。

$ sudo nmcli connection delete enp0s8
Connection 'enp0s8' (c4df012f-ade4-4abc-afd4-585feecbd222) successfully deleted.
$ sudo nmcli connection delete enp0s9
Connection 'enp0s9' (645308fa-a364-459f-a8e0-84ce892cf6ee) successfully deleted.
$ nmcli device status
DEVICE   TYPE      STATE                   CONNECTION
enp0s3   ethernet  connected               enp0s3
enp0s10  ethernet  connected               enp0s10
lo       loopback  connected (externally)  lo
enp0s8   ethernet  disconnected            -- ・・・ 切断されている
enp0s9   ethernet  disconnected            -- ・・・ 切断されている
$ nmcli connection show
NAME     UUID                                  TYPE      DEVICE
enp0s3   ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
enp0s10  82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
lo       e15765b2-b3f2-4712-8260-9326a2804670  loopback  lo

Bondインターフェースの追加をして、そのBondインタフェースにNICを追加します。

主なオプション説明
downdelayNICのリンクダウンを検知してから、ステータスを「Down」にするまでの時間。(単位:ms)
デフォルト : 0
updelayNICのリンクアップを検知してから、ステータスを「Up」にするまでの時間。(単位:ms)
デフォルト:0
miimonNICの状態を監視する間隔(単位:ms)
デフォルト:100
modeボンディングのモード。
1 ・・・ active-backup アクティブ-バックアップ方式。
※ 他にもモードがあるが、これ以外使用したことがない。
デフォルト:0 (ラウンドロビン方式)推奨されない。
primary優先するインターフェース
$ sudo nmcli connection add type bond ifname bond1 \
>          bond.options "mode=1,primary=enp0s8" ・・・ 仮想NIC追加
Connection 'bond1' (281b279d-0691-42be-a692-9ab1e127b4b0) successfully added.
$ nmcli device status
DEVICE   TYPE      STATE                                  CONNECTION
enp0s10  ethernet  connected                              enp0s10
enp0s3   ethernet  connected                              enp0s3
lo       loopback  connected (externally)                 lo
bond1    bond      connecting (getting IP configuration)  bond-bond1
enp0s8   ethernet  disconnected                           --
enp0s9   ethernet  disconnected                           --
$ nmcli connection show
NAME          UUID                                  TYPE      DEVICE
bond-bond1    281b279d-0691-42be-a692-9ab1e127b4b0  bond      bond1
enp0s10       82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
enp0s3        ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
lo            170bb0b6-3383-4487-b94a-d05659a9a0a5  loopback  lo
$ sudo nmcli connection add type ethernet ifname enp0s8 master bond1 ・・・ 物理NIC追加
Connection 'bond-slave-enp0s8' (6087996b-cc56-4856-9a9e-2a8b10355bbf)
 successfully added.
$ sudo nmcli connection add type ethernet ifname enp0s9 master bond1 ・・・ 物理NIC追加
Connection 'bond-slave-enp0s9' (3eecb8a5-f4b9-4806-bc9b-800b7e33857f)
 successfully added.
$ nmcli device status
DEVICE   TYPE      STATE                   CONNECTION
enp0s10  ethernet  connected               enp0s10
bond1    bond      connected               bond-bond1 ・・・・・・・・・・・ マスター
enp0s3   ethernet  connected               enp0s3
lo       loopback  connected (externally)  lo
enp0s8   ethernet  connected               bond-slave-enp0s8 ・・・ スレーブ
enp0s9   ethernet  connected               bond-slave-enp0s9 ・・・ スレーブ
$ nmcli connection show
NAME               UUID                                  TYPE      DEVICE
enp0s10            82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
bond-bond1         281b279d-0691-42be-a692-9ab1e127b4b0  bond      bond1
enp0s3             ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
lo                 170bb0b6-3383-4487-b94a-d05659a9a0a5  loopback  lo
bond-slave-enp0s8  6087996b-cc56-4856-9a9e-2a8b10355bbf  ethernet  enp0s8
bond-slave-enp0s9  3eecb8a5-f4b9-4806-bc9b-800b7e33857f  ethernet  enp0s9

ボンディングの動作確認

ボンディング設定した物理NICをDownさせて切り替わること確認します。

$ cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-284.11.1.el9_2.x86_64

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: enp0s8 (primary_reselect always)
Currently Active Slave: enp0s8
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: enp0s8 ・・・ こちらが使われている
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:62:1e:37
Slave queue ID: 0

Slave Interface: enp0s9
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:98:6c:d7
Slave queue ID: 0
$ sudo nmcli device down enp0s8 ・・・ NICを「down」させる
Device 'enp0s8' successfully disconnected.
$ cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-284.11.1.el9_2.x86_64

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: enp0s9
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: enp0s9 ・・・ こちらが使われている
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:98:6c:d7
Slave queue ID: 0
$ sudo nmcli device up enp0s8 ・・・ NICを「up」させる
Device 'enp0s8' successfully activated with '6087996b-cc56-4856-9a9e-2a8b10355bbf'.
$ cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v5.14.0-284.11.1.el9_2.x86_64

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: enp0s8 (primary_reselect always)
Currently Active Slave: enp0s8
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Peer Notification Delay (ms): 0

Slave Interface: enp0s9
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:98:6c:d7
Slave queue ID: 0

Slave Interface: enp0s8 ・・・ こちらが使われている
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:62:1e:37
Slave queue ID: 0

ボンディングの設定削除

ボンディングの設定で指定する物理NICを間違ってしまった場合に削除したい時があると思います。

$ nmcli device status
DEVICE   TYPE      STATE                   CONNECTION
enp0s10  ethernet  connected               enp0s10
bond1    bond      connected               bond-bond1
enp0s3   ethernet  connected               enp0s3
lo       loopback  connected (externally)  lo
enp0s8   ethernet  connected               bond-slave-enp0s8
enp0s9   ethernet  connected               bond-slave-enp0s9
$ nmcli connection show
NAME               UUID                                  TYPE      DEVICE
enp0s10            82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
bond-bond1         d644c01b-d627-425b-a450-8861034c689a  bond      bond1
enp0s3             ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
lo                 170bb0b6-3383-4487-b94a-d05659a9a0a5  loopback  lo
bond-slave-enp0s8  6087996b-cc56-4856-9a9e-2a8b10355bbf  ethernet  enp0s8
bond-slave-enp0s9  3eecb8a5-f4b9-4806-bc9b-800b7e33857f  ethernet  enp0s9

マスターインターフェースとスレーブインターフェースを削除します。

$ sudo nmcli connection delete bond-bond1 ・・・ マスターインターフェースの削除
Connection 'bond-bond1' (d644c01b-d627-425b-a450-8861034c689a)
 successfully deleted.
$ sudo nmcli connection delete bond-slave-enp0s8 ・・・ スレーブインターフェースの削除
Connection 'bond-slave-enp0s8' (6087996b-cc56-4856-9a9e-2a8b10355bbf)
 successfully deleted.
$ sudo nmcli connection delete bond-slave-enp0s9 ・・・ スレーブインターフェースの削除
Connection 'bond-slave-enp0s9' (3eecb8a5-f4b9-4806-bc9b-800b7e33857f)
 successfully deleted.
$ nmcli device status
DEVICE   TYPE      STATE                   CONNECTION
enp0s10  ethernet  connected               enp0s10
enp0s3   ethernet  connected               enp0s3
lo       loopback  connected (externally)  lo
enp0s8   ethernet  disconnected            --
enp0s9   ethernet  disconnected            --
$ nmcli connection show
NAME     UUID                                  TYPE      DEVICE
enp0s10  82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
enp0s3   ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
lo       170bb0b6-3383-4487-b94a-d05659a9a0a5  loopback  lo

物理NICを「Up」します。

$ sudo nmcli device up enp0s8 ・・・ 物理NICのUp
Device 'enp0s8' successfully activated with '6b5b2329-5298-4091-aff2-16adb8a0eb13'.
$ sudo nmcli device up enp0s9 ・・・ 物理NICのUp
Device 'enp0s9' successfully activated with '02c139ff-3653-4b4d-a439-eb21cba71e2a'.
$ nmcli device status
DEVICE   TYPE      STATE                   CONNECTION
enp0s10  ethernet  connected               enp0s10
enp0s3   ethernet  connected               enp0s3
enp0s8   ethernet  connected               enp0s8
enp0s9   ethernet  connected               enp0s9
lo       loopback  connected (externally)  lo
$ nmcli connection show
NAME     UUID                                  TYPE      DEVICE
enp0s10  82cee687-5da5-4a1f-bdcc-cf1c8b473650  ethernet  enp0s10
enp0s3   ea85d86c-eaee-381f-980c-d25609d599d6  ethernet  enp0s3
enp0s8   6b5b2329-5298-4091-aff2-16adb8a0eb13  ethernet  enp0s8
enp0s9   02c139ff-3653-4b4d-a439-eb21cba71e2a  ethernet  enp0s9
lo       170bb0b6-3383-4487-b94a-d05659a9a0a5  loopback  lo