bonding したインターフェースの振る舞いを試してみる

ifenslave で eth0 と eth1 を bonding したネットワークインターフェース bond0 があるものとします。
active-backup です。

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
iface bond0 inet dhcp
slaves eth0 eth1
bond_mode active-backup
bond_primary eth0
bond_miimon 100
$ /sbin/ifconfig bond0
bond0     Link encap:イーサネット  ハードウェアアドレス 08:00:27:97:bf:08 
          inetアドレス:10.0.1.200 ブロードキャスト:10.0.1.255  マスク:255.255.255.0
          inet6アドレス: fe80::a00:27ff:fe97:bf08/64 範囲:リンク
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  メトリック:1
          RXパケット:1769 エラー:0 損失:0 オーバラン:0 フレーム:0
          TXパケット:99 エラー:0 損失:0 オーバラン:0 キャリア:0
      衝突(Collisions):0 TXキュー長:0 
          RXバイト:140298 (137.0 KiB)  TXバイト:13287 (12.9 KiB)

この状態で、eth0 を ifdown するとどうなるか。
できれば eth1 に切り替わって欲しいです。
ifdown だと落とせないんですね。ip とかならできたのかな。

$ ifdown eth0
ifdown: interface eth0 not configured
$ /sbin/ifconfig eth0 down
$ /sbin/ifconfig bond0
bond0     Link encap:イーサネット  ハードウェアアドレス 08:00:27:97:bf:08
          inetアドレス:10.0.1.200 ブロードキャスト:10.0.1.255  マスク:255.255.255.0
          inet6アドレス: fe80::a00:27ff:fe97:bf08/64 範囲:リンク
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  メトリック:1
          RXパケット:2064 エラー:0 損失:0 オーバラン:0 フレーム:0
          TXパケット:258 エラー:0 損失:0 オーバラン:0 キャリア:0
      衝突(Collisions):0 TXキュー長:0
          RXバイト:164240 (160.3 KiB)  TXバイト:31267 (30.5 KiB)

おぉ、落とせた。
なんかログに出てるかな。

$ tail /var/log/messages  | grep bond0
Oct 20 13:47:00 vmlv00 kernel: [117914.464299] bonding: bond0: link status definitely down for interface eth0, disabling it
Oct 20 13:47:00 vmlv00 kernel: [117914.464370] bonding: bond0: making interface eth1 the new active one.

いい感じです。
proc も覗いてみる。

$ cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)

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

Slave Interface: eth0
MII Status: down
Link Failure Count: 1
Permanent HW addr: 08:00:27:97:bf:08

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 08:00:27:04:2c:85

いい感じです。
わりとうまく動くな。
元に戻しておきましょう。

$ /sbin/ifconfig eth0 up
$ /sbin/ifconfig bond0
bond0     Link encap:イーサネット  ハードウェアアドレス 08:00:27:97:bf:08 
          inetアドレス:10.0.1.200 ブロードキャスト:10.0.1.255  マスク:255.255.255.0
          inet6アドレス: fe80::a00:27ff:fe97:bf08/64 範囲:リンク
          UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  メトリック:1
          RXパケット:3183 エラー:0 損失:0 オーバラン:0 フレーム:0
          TXパケット:587 エラー:0 損失:0 オーバラン:0 キャリア:0
      衝突(Collisions):0 TXキュー長:0 
          RXバイト:253530 (247.5 KiB)  TXバイト:68845 (67.2 KiB)

$ tail /var/log/messages  | grep bond0
Oct 20 13:47:00 vmlv00 kernel: [117914.464299] bonding: bond0: link status definitely down for interface eth0, disabling it
Oct 20 13:47:00 vmlv00 kernel: [117914.464370] bonding: bond0: making interface eth1 the new active one.
Oct 20 13:52:54 vmlv00 kernel: [118273.698976] bonding: bond0: link status definitely up for interface eth0.
Oct 20 13:52:54 vmlv00 kernel: [118273.699128] bonding: bond0: making interface eth0 the new active one.
$ cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)

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

Slave Interface: eth0
MII Status: up
Link Failure Count: 1
Permanent HW addr: 08:00:27:97:bf:08

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 08:00:27:04:2c:85

よし。