「LANの多重化」の版間の差分
Rin-scrooge (トーク | 投稿記録)  | 
				Rin-scrooge (トーク | 投稿記録)   | 
				||
| (同じ利用者による、間の30版が非表示) | |||
| 1行目: | 1行目: | ||
| + | '''自宅の環境で試しましたが…USB-LANアダプタはBonding出来ないようです…<br/>でも…オンボードのr8152もUSB-LANなんだけどな…'''  | ||
| + | |||
| + | |||
ArchLinuxのカーネルがバージョンアップしてから、またLANが不安定に…。<br/>  | ArchLinuxのカーネルがバージョンアップしてから、またLANが不安定に…。<br/>  | ||
ちなみに使用しているNICはasixのAX88179チップのやつ…。<br/>  | ちなみに使用しているNICはasixのAX88179チップのやつ…。<br/>  | ||
| 8行目: | 11行目: | ||
※以下の手順はセキュリティ上VirtualBoxで操作した内容になっています。  | ※以下の手順はセキュリティ上VirtualBoxで操作した内容になっています。  | ||
| + | |||
== bondingの準備 ==  | == bondingの準備 ==  | ||
| + | === ifenslaveのインストール ===  | ||
| + | bondingに必要な「ifenslave」パッケージを、以下のコマンドでインストールします。  | ||
| + | <syntaxhighlight lang="bash">pacman -S ifenslave</syntaxhighlight>  | ||
netctlはデフォルトでインストールされているので、netctlを使用したbondingを実現できるように設定ファイルを作成します。  | netctlはデフォルトでインストールされているので、netctlを使用したbondingを実現できるように設定ファイルを作成します。  | ||
| + | === netctlの設定 ===  | ||
先ずは、bondingするNIC名を以下のコマンドで取得します。  | 先ずは、bondingするNIC名を以下のコマンドで取得します。  | ||
<syntaxhighlight lang="bash">ip a</syntaxhighlight>  | <syntaxhighlight lang="bash">ip a</syntaxhighlight>  | ||
| 27行目: | 35行目: | ||
     inet6 fe80::3092:89f5:4be1:eb66/64 scope link    |      inet6 fe80::3092:89f5:4be1:eb66/64 scope link    | ||
        valid_lft forever preferred_lft forever  |         valid_lft forever preferred_lft forever  | ||
| − | 3:   | + | 3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000  | 
     link/ether 08:00:27:59:5c:9a brd ff:ff:ff:ff:ff:ff  |      link/ether 08:00:27:59:5c:9a brd ff:ff:ff:ff:ff:ff  | ||
     inet 10.0.4.15/24 brd 10.0.4.255 scope global dynamic noprefixroute enp0s9  |      inet 10.0.4.15/24 brd 10.0.4.255 scope global dynamic noprefixroute enp0s9  | ||
| 34行目: | 42行目: | ||
        valid_lft forever preferred_lft forever</syntaxhighlight>  |         valid_lft forever preferred_lft forever</syntaxhighlight>  | ||
現時点ではNetworkManagerが起動しているので、2つのNICが生きています。<br/>  | 現時点ではNetworkManagerが起動しているので、2つのNICが生きています。<br/>  | ||
| − | + | 上記の例では「enp0s3」と「enp0s8」が、それぞれのNIC名になります。  | |
次に手順に従って、サンプルファイルをコピーします。  | 次に手順に従って、サンプルファイルをコピーします。  | ||
| 50行目: | 58行目: | ||
#Mode=balance-rr</syntaxhighlight>  | #Mode=balance-rr</syntaxhighlight>  | ||
【修正後】  | 【修正後】  | ||
| − | <syntaxhighlight lang="text" line="line" highlight="4,6  | + | <syntaxhighlight lang="text" line="line" highlight="4,6-10">Description="A bonded interface"  | 
Interface=bond0  | Interface=bond0  | ||
Connection=bond  | Connection=bond  | ||
| − | BindsToInterfaces=(enp0s3   | + | BindsToInterfaces=(enp0s3 enp0s8)  | 
IP=static  | IP=static  | ||
| + | Address="192.168.56.11/24"  | ||
| + | Gateway='192.168.56.1'  | ||
| + | DNS=('192.168.56.1')  | ||
IP6=stateless  | IP6=stateless  | ||
| − | |||
Mode=active-backup</syntaxhighlight>  | Mode=active-backup</syntaxhighlight>  | ||
| + | 「BindsToInterfaces」はbondingの対象にするNIC名を指定します。<br/>  | ||
| + | 「Address」は固定IPv4アドレスを指定します。<br/>  | ||
| + | 「IP6=stateless」はIPv6を有効にして、おまかせしています。<br/>  | ||
| + | 「Mode」は動作させるモードを指定します。指定する内容は[http://nosa.cocolog-nifty.com/sanonosa/2013/12/linuxnicbonding.html こちら]を参照してください。<br/>  | ||
| + | |||
| + | === bondingドライバの設定 ===  | ||
| + | 次にbondingドライバの設定をしていきます。<br/>  | ||
| + | 今の状態で動作させてもMIIの監視間隔が0なので、切り替わりません。<br/>  | ||
| + | nano等のエディタで「/etc/modprobe.d/bonding.conf」を以下の内容で新規作成します。  | ||
| + | <syntaxhighlight lang="text" line="line">options bonding miimon=100 primary=enp0s3</syntaxhighlight>  | ||
| + | |||
| + | == 切り替え ==  | ||
| + | === NetworkManegerの無効化とnetctlの有効化 ===  | ||
| + | NetworkManegerを無効化して、netctlを有効化します。  | ||
| + | <syntaxhighlight lang="bash">systemctl stop NetworkManager  | ||
| + | systemctl disable NetworkManager  | ||
| + | netctl start bonding  | ||
| + | netctl enable bonding</syntaxhighlight>  | ||
| + | |||
| + | === 再起動 ===  | ||
| + | bondingドライバに設定を反映させるために、OSを再起動します。  | ||
| + | <syntaxhighlight lang="bash">reboot</syntaxhighlight>  | ||
| + | |||
| + | === 動作確認 ===  | ||
| + | 以下のコマンドで動作状況を確認します。  | ||
| + | <syntaxhighlight lang="bash">cat /proc/net/bonding/bond0</syntaxhighlight>  | ||
| + | 以下の様に表示されます。  | ||
| + | <syntaxhighlight lang="text">Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)  | ||
| + | |||
| + | Bonding Mode: fault-tolerance (active-backup)  | ||
| + | Primary Slave: None  | ||
| + | Currently Active Slave: enp0s3  | ||
| + | MII Status: up  | ||
| + | MII Polling Interval (ms): 100  | ||
| + | Up Delay (ms): 0  | ||
| + | Down Delay (ms): 0  | ||
| + | |||
| + | Slave Interface: enp0s3  | ||
| + | MII Status: up  | ||
| + | Speed: 1000 Mbps  | ||
| + | Duplex: full  | ||
| + | Link Failure Count: 0  | ||
| + | Permanent HW addr: 08:00:27:66:20:41  | ||
| + | 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:59:5c:9a  | ||
| + | Slave queue ID: 0</syntaxhighlight>  | ||
| + | 何となくですが…動作モードは「active-backup」でアクティブが「enp0s3」、「enp0s8」は待機しています。  | ||
| + | |||
| + | |||
| + | これだけでは不安なので、「enp0s3」側のLANケーブルを抜いてみます。<br/>  | ||
| + | 切り替わったことを、確認してみます。  | ||
| + | <syntaxhighlight lang="bash">cat /proc/net/bonding/bond0  | ||
| + | Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)  | ||
| + | |||
| + | Bonding Mode: fault-tolerance (active-backup)  | ||
| + | Primary Slave: None  | ||
| + | Currently Active Slave: enp0s8  | ||
| + | MII Status: up  | ||
| + | MII Polling Interval (ms): 100  | ||
| + | Up Delay (ms): 0  | ||
| + | Down Delay (ms): 0  | ||
| + | |||
| + | Slave Interface: enp0s3  | ||
| + | MII Status: up  | ||
| + | Speed: 1000 Mbps  | ||
| + | Duplex: full  | ||
| + | Link Failure Count: 1  | ||
| + | Permanent HW addr: 08:00:27:66:20:41  | ||
| + | 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:59:5c:9a  | ||
| + | Slave queue ID: 0</syntaxhighlight>  | ||
| + | |||
| + | 切り替わってます!!  | ||
== 参考サイト ==  | == 参考サイト ==  | ||
[https://wiki.archlinux.jp/index.php/Netctl#.E3.83.9C.E3.83.B3.E3.83.87.E3.82.A3.E3.83.B3.E3.82.B0 netctl - ArchWiki]<br/>  | [https://wiki.archlinux.jp/index.php/Netctl#.E3.83.9C.E3.83.B3.E3.83.87.E3.82.A3.E3.83.B3.E3.82.B0 netctl - ArchWiki]<br/>  | ||
| + | [https://qiita.com/tukiyo3/items/08c8b0180eae29055736 ArchLinuxでネットワーク設定 (ブリッジ、bonding)]<br/>  | ||
[https://github.com/joukewitteveen/netctl/blob/master/docs/netctl.profile.5.txt マスターのnetctl / netctl.profile.5.txt・joukewitteveen / netctl・GitHub]<br/>  | [https://github.com/joukewitteveen/netctl/blob/master/docs/netctl.profile.5.txt マスターのnetctl / netctl.profile.5.txt・joukewitteveen / netctl・GitHub]<br/>  | ||
[http://nosa.cocolog-nifty.com/sanonosa/2013/12/linuxnicbonding.html LinuxでのNIC冗長化(bonding)を少し深く考えてみる: sanonosa システム管理コラム集]<br/>  | [http://nosa.cocolog-nifty.com/sanonosa/2013/12/linuxnicbonding.html LinuxでのNIC冗長化(bonding)を少し深く考えてみる: sanonosa システム管理コラム集]<br/>  | ||
2019年9月10日 (火) 14:36時点における最新版
自宅の環境で試しましたが…USB-LANアダプタはBonding出来ないようです…
でも…オンボードのr8152もUSB-LANなんだけどな…
ArchLinuxのカーネルがバージョンアップしてから、またLANが不安定に…。
ちなみに使用しているNICはasixのAX88179チップのやつ…。
ネットで調べても、不安定に悩んでいる人が少ないみたい…。
で色々調べた結果…以下の2点を実現することにしました。
- NetworkManagerをやめてnetctlに変更
ArchLinux独自ということで、ArchLinuxに最適化されていると信じる…。 - ネットワークを多重化する
速度の向上は特に望んでいないので、ウォームスタンバイにして1つのNICが死んでも別のNICで通信を継続するようにする。 
※以下の手順はセキュリティ上VirtualBoxで操作した内容になっています。
目次
bondingの準備
ifenslaveのインストール
bondingに必要な「ifenslave」パッケージを、以下のコマンドでインストールします。
pacman -S ifenslave
netctlはデフォルトでインストールされているので、netctlを使用したbondingを実現できるように設定ファイルを作成します。
netctlの設定
先ずは、bondingするNIC名を以下のコマンドで取得します。
ip a
こんなふうに出力されるかと思います。
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:66:20:41 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::3092:89f5:4be1:eb66/64 scope link 
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:59:5c:9a brd ff:ff:ff:ff:ff:ff
    inet 10.0.4.15/24 brd 10.0.4.255 scope global dynamic noprefixroute enp0s9
       valid_lft 80855sec preferred_lft 80855sec
    inet6 fe80::3384:eba2:7991:7635/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
現時点ではNetworkManagerが起動しているので、2つのNICが生きています。
上記の例では「enp0s3」と「enp0s8」が、それぞれのNIC名になります。
次に手順に従って、サンプルファイルをコピーします。
cp /etc/netctl/examples/bonding /etc/netctl
コピーできたら、環境に合わせて内容を編集します。
nanoなどのエディタで「/etc/netctl/bonding」を開きます。
【修正前】
1 Description="A bonded interface"
2 Interface=bond0
3 Connection=bond
4 BindsToInterfaces=(eth0 eth2)
5 IP=static
6 Address="10.0.0.1/8"
7 #Mode=balance-rr
【修正後】
 1 Description="A bonded interface"
 2 Interface=bond0
 3 Connection=bond
 4 BindsToInterfaces=(enp0s3 enp0s8)
 5 IP=static
 6 Address="192.168.56.11/24"
 7 Gateway='192.168.56.1'
 8 DNS=('192.168.56.1')
 9 IP6=stateless
10 Mode=active-backup
「BindsToInterfaces」はbondingの対象にするNIC名を指定します。
「Address」は固定IPv4アドレスを指定します。
「IP6=stateless」はIPv6を有効にして、おまかせしています。
「Mode」は動作させるモードを指定します。指定する内容はこちらを参照してください。
bondingドライバの設定
次にbondingドライバの設定をしていきます。
今の状態で動作させてもMIIの監視間隔が0なので、切り替わりません。
nano等のエディタで「/etc/modprobe.d/bonding.conf」を以下の内容で新規作成します。
1 options bonding miimon=100 primary=enp0s3
切り替え
NetworkManegerの無効化とnetctlの有効化
NetworkManegerを無効化して、netctlを有効化します。
systemctl stop NetworkManager
systemctl disable NetworkManager
netctl start bonding
netctl enable bonding
再起動
bondingドライバに設定を反映させるために、OSを再起動します。
reboot
動作確認
以下のコマンドで動作状況を確認します。
cat /proc/net/bonding/bond0
以下の様に表示されます。
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: enp0s3
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: enp0s3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 08:00:27:66:20:41
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:59:5c:9a
Slave queue ID: 0
何となくですが…動作モードは「active-backup」でアクティブが「enp0s3」、「enp0s8」は待機しています。
これだけでは不安なので、「enp0s3」側のLANケーブルを抜いてみます。
切り替わったことを、確認してみます。
cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: enp0s8
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: enp0s3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: 08:00:27:66:20:41
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:59:5c:9a
Slave queue ID: 0
切り替わってます!!
参考サイト
netctl - ArchWiki
ArchLinuxでネットワーク設定 (ブリッジ、bonding)
マスターのnetctl / netctl.profile.5.txt・joukewitteveen / netctl・GitHub
LinuxでのNIC冗長化(bonding)を少し深く考えてみる: sanonosa システム管理コラム集