LoginSignup
3
2

More than 1 year has passed since last update.

Ubuntuで複数のNICを束ねる方法

Posted at

はじめに

複数のNICを1つにまとめて1つのIPをもつ仮想NICの作成方法をまとめます.
いままでLANポートが1つしかなかったUbuntuサーバに拡張NICを追加しました.
そのまま使うとそれぞれのNICにIPが振られます(DHCP環境下の場合)
しかし,その場合はデフォルトゲートウェイが複数またはメトリックが同じ値になり,
sshなどが通らなくなることがあります.
そのため,難しいことは置いておいて,
複数のLANポートを仮想的に1つにまとめます.

環境

yasu@mypc:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"

設定方法

まず,netplanに束ねる設定ファイルを作ります.

sudo su
cd /etc/netplan
emacs /etc/netplan/02-bonding.yaml

01~のファイルは基本的に変更しない方がいいみたいです.
02-bonding.yamlには,以下を記述します.

/etc/netplan/02-bonding.yaml
network:
   version: 2
   ethernets:
      eno1:
         addresses: []
         dhcp4: false
         dhcp6: false
      enp6s0f0:
         addresses: []
         dhcp4: false
         dhcp6: false
      enp6s0f1:
         addresses: []
         dhcp4: false
         dhcp6: false

   bonds:
      #束ねた後のNIC名を指定する.
      bond0:
         #束ねた後のIPやゲートウェイ,DNSを指定する.
         addresses: [192.168.xxx.xxx/22]
         gateway4: 192.168.xxx.xxx
         nameservers:
            addresses: [192.168.xxx.xxx]
         #束ねるNIC名を列挙する.
         interfaces:
            - eno1
            - enp6s0f0
            - enp6s0f1
         parameters: 
            #束ね方をmodeで指定する.(詳細は後述)
            mode: balance-alb
            #NICの監視間隔(msec)
            mii-monitor-interval: 100
            #arpの監視間隔(0は無効)
            arp-interval: 0 

ifconfig等でNIC名を調べるボンディングしたいデバイスを指定します.
私のPCの場合はeno1はマザボのLANポートで,他の2つは追加したNICです.

mode一覧.
0: balance-rr
1: active-backup
2: balance-xor
3: broadcast
4: 802.3ad
5: balance-tlb
6: balance-alb

基本的には,NIC同士の冗長性や負荷分散をモードとして決めることができます.
冗長性:耐障害性を高めるための予備システムを準備すること
負荷分散:たくさん通信する場合に1つのNICに負荷がかからないように,複数のNICで役割分担する.

0-5には,そもそもローカルエリアにあるスイッチングハブ自体が対応している必要があるため,
全てのNICで負荷分散するために6を選びました.

設定を反映します.

sudo netplan apply

*このnetplan applyは構文チェックが自動で行われます.
ついでに,bridghの場合はtryはできないみたいです.怖い怖い.

bond0: reverting custom parameters for bridges and bonds is not supported

ifconfigを確認して,bond0(束ねたNIC)が作成されていることが確認できます.

bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST>  mtu 1500
        inet 192.168.xxx.xxx  netmask 255.255.252.0  broadcast 192.168.xxx.xxx
        略

eno1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
        略 

enp6s0f0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
        略

enp6s0f1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST>  mtu 1500
        ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
        略

おまけ

当初の目的であった帯域が広くなったか確認してみます.
専用のツールをインストールして確認してみます.

$ sudo apt install ethtool

$ ethtool bond0
Settings for bond0:
        Supported ports: [ ]
        Supported link modes:   Not reported
        Supported pause frame use: No
        Supports auto-negotiation: No
        Supported FEC modes: Not reported
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Advertised FEC modes: Not reported
        Speed: 3000Mb/s
        Duplex: Full
        Port: Other
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2