netctl (日本語)
| 概要 |
|---|
| netctl とネットワークプロファイルスクリプトを使ってネットワークを設定するガイド。 |
| 概括 |
Arch Linux ではネットワークを設定するために netctl を提供しています。デスクトップやサーバーにおいて、netctl は有線接続または無線接続のセットアップやローミングをサポートし、ネットワーク設定の管理を容易にします。NetworkManager や Wicd は人気のある代替です。
|
| 資料 |
| Bridge with netctl |
Netctl はプロファイルを使ってネットワーク接続を管理・設定する CLI ベースのツールです。netctl は古い netcfg ユーティリティを置き換える新しい Arch Linux の独自プロジェクトです。Netctl は Arch Linux の CLI ベースのネットワーク管理の将来(そして現在)です。
Contents |
インストール
netctl パッケージが公式リポジトリから利用できます。netctl をインストールすると netcfg が置き換えられます。
netctl と netcfg は衝突するパッケージです。プロファイルが正しく設定されていないと、netctl をインストールした後に接続を失う可能性があります。
必読
netctl を使う前に以下の man ページを読むのを推奨します:
設定
netctl はプロファイルを使ってネットワーク接続を管理します。プロファイルファイルは /etc/netctl/ に保存されています。ユーザーがネットワーク接続を設定するのを助けるために、設定のサンプルファイルが提供されています。これらのサンプルプロファイルが置かれている場所は /etc/netctl/examples/ です。一般的な設定として以下が用意されています:
- ethernet-dhcp
- ethernet-static
- wireless-wpa
- wireless-wpa-static
サンプルプロファイルを使うには、プロファイルのどれかを /etc/netctl/examples/ から /etc/netctl/ にコピーしてあなたの設定にあわせてプロファイルを修正して下さい:
# cp /etc/netctl/examples/wireless-wpa /etc/netctl/profile
プロファイルを作成したら、新しく作ったプロファイルを使って接続を確立するために次を実行して下さい:
# netctl start profile
上のコマンドが失敗する場合、journalctl -xn や netctl status profile を使って失敗の詳細情報を取得して下さい。そして設定を修正してから再テストして下さい。
自動操作
プロファイルを(一つのインターフェイスに)一つしか使わなかったり、手動でプロファイルを切り替える場合、基本的な方法を使って下さい。一般的な例として、サーバー・ワークステーション・ルーターなどがあります。
頻繁に複数のプロファイルを切り替える必要がある時は、プロファイルの自動切り替えを使って下さい。一般的な例として、ラップトップがあります。
基本的な方法
この方法では、インターフェイス毎に一つのプロファイルを固定して起動することができます。最初にプロファイルが問題なく起動することを手動で確認して、それから次のコマンドで enabled にしてください:
# netctl enable profile
このコマンドによって systemd サービスが作成・有効にされ、コンピュータが立ち上がる時にサービスが起動するようになります。
プロファイルの自動切り替え
netctl は自動でプロファイルを切り替えるために2つの特別な systemd サービスを用意しています: 無線接続用の netctl-auto@interface.service と有線接続用の netctl-ifplugd@interface.service です。netctl-auto@interface.service を使うと、あなたがあるネットワークの圏内から他のネットワークの圏内に移動したときに netctl のプロファイルが変更されます。netctl-ifplugd@interface.service を使うと、あなたがケーブルを抜き差しするたびに netctl プロファイルが変更されます。
まず必要なパッケージをインストールしてください:
-
netctl-auto@interface.serviceを使うには wpa_actiond パッケージが必要です。 -
netctl-ifplugd@interface.serviceを使うには ifplugd パッケージが必要です。
そして netctl-auto@interface.service や netctl-ifplugd@interface.service が起動できるプロファイルを全て設定してください。これらのサービスによって自動的に起動しないようにしたい場合は、そのプロファイルに ExcludeAuto=yes を加える必要があります。また、Priority= を使うことで複数のプロファイルが利用可能な場合に、どのプロファイルを優先的に使うか設定できます。詳しくは netctl.profile(5) を見て下さい。
プロファイルを設定して、動作するのを確認したら、systemctl を使ってサービスを有効にしてください:
# systemctl enable netctl-auto@interface.service # systemctl enable netctl-ifplugd@interface.service
netcfg からの移行
netctl はプロファイルの保存に /etc/netctl を使います。/etc/network.d (netcfg のプロファイル保存場所) ではありません。
netcfg からの移行をするためには、最低でも以下の操作が必要です:
- netcfg サービスを無効にする:
systemctl disable netcfg.service - netcfg をアンインストールして netctl をインストールする。
- ネットワークプロファイルファイルを新しいディレクトリに移動する。
-
netctl.profile(5)に従ってプロファイル内の変数の名前を修正する (ほとんどの変数の名前はUpperCamelCaseです、つまりCONNECTIONはConnectionになります)。 - 固定 IP 設定では、
Address変数で IP の後ろにネットマスクを付ける (例:Address=('192.168.1.23/24' '192.168.1.87/24')サンプルプロファイルより)。 -
wireless-wpa-configsectionサンプルに従って無線プロファイルを設定している場合、定義済みのwpa_supplicantオプションを上書きしてしまうので注意してください。隠された無線ネットワークに接続するには、{{ic|wireless-wpa-configsection} 内でscan_ssid=1をオプションに追加してください。;Hidden=yesは効果がありません。 - interface 変数などクオートが必要ない変数のクォーテーションを外す (これは見た目を整えるためです)。
- 前の
NETWORKSに設定していたプロファイルごとにnetctl enable profileを実行する。'last' はこの方法では使えません、netctl.special(7)を見て下さい。 - netcfg-menu の代わりに
netctl list/netctl start profileを使う。wifi-menu は使い続けられます。
パスワードの暗号化 (256-bit PSK)
パスワードを平文で保存したくない場合、256-bit Encrypted PSK を生成するという方法があります。これはパスフレーズと SSID から標準アルゴリズムを使って計算します。
- 方法 1:
wifi-menu -oを実行して/etc/netctlに設定ファイルを生成する - 方法 2: 手順に従って手動設定する。パスフレーズが失敗する場合、Key= の中の \" を削除してみてください (下の Note を見て下さい)
どちらの方法でも、chmod 600 /etc/netctl/<config_file> をしてパスワードにユーザーがアクセスできないようにするのを提案します。
wpa_passphrase を使ってあなたの 256-bit Encrypted PSK を生成してください:
wpa_passphrase archlinux freenode
network={
ssid="archlinux"
#psk="freenode"
psk=64cf3ced850ecef39197bb7b7b301fc39437a6aa6c6a599d0534b16af578e04a
}
新しいターミナルを開き、サンプルファイル wireless-wpa を /etc/netctl/examples から /etc/netctl にコピーしてください。
# cp /etc/netctl/examples/wireless-wpa /etc/netctl/wireless-wpa
それからお好きなテキストエディタを使って /etc/netctl/wireless-wpa を編集する必要があります。先に wpa_passphrase を使って生成された Encrypted Pre-shared Key (psk) をプロファイルの Key 変数に追加してください。
256-bit Encrypted PSK を含むネットワークプロファイル wireless-wpa は以下のようになるはずです:
/etc/netctl/wireless-wpa
Description='A simple WPA encrypted wireless connection using 256-bit Encrypted PSK' Interface=wlp2s2 Connection=wireless Security=wpa IP=dhcp ESSID=archlinux Key=\"64cf3ced850ecef39197bb7b7b301fc39437a6aa6c6a599d0534b16af578e04a
サポート
公式アナウンススレッド: https://bbs.archlinux.org/viewtopic.php?id=157670
Tips and Tricks
'netcfg current' の代用
2013年4月現在、netcfg current のかわりになるコマンドは netctl にありません。タイル型ウィンドウマネージャのステータスバーなどでこのコマンドを使っている場合は、次のコマンドで代用できます:
# netctl list | awk '/*/ {print $2}'
もしくは、netctl-auto を使って接続している場合:
# wpa_cli -i interface status | sed -n 's/^id_str=//p'
Eduroam
いくつかの大学では "Eduroam" という名前のシステムを使って無線ネットワークを管理しています。このシステム用に、以下のフォーマットの WPA config-section プロファイルが利用できます:
/etc/netctl/wlan0-eduroam
Description='Eduroam-profile for <user>' Interface=wlan0 Connection=wireless Security=wpa-configsection IP=dhcp WPAConfigSection=( 'ssid="eduroam"' 'proto=RSN' 'key_mgmt=WPA-EAP' 'pairwise=CCMP' 'auth_alg=OPEN' 'eap=PEAP' 'identity="<user>"' 'password="<password>"' )
ボンディング
- Linux bonding ドライバは複数のネットワークインターフェースを単一の論理的な「結合された」インターフェースに統合する手段を提供します。結合されたインターフェースの動作はモードに依存します。一般に言われる事ですが、モードはホットスタンバイまたは負荷分散サービスを提供します。加えて、リンクの保全監視が実現されます。
ロードバランシング
netctl とボンディングを使うには、公式リポジトリから追加のパッケージをインストールする必要があります: ifenslave.
/etc/netctl/examples/bonding を /etc/netctl/bonding にコピーして、以下のように編集してください:
/etc/netctl/bonding
Description='Bond Interface'
Interface='bond0'
Connection=bond
BindsToInterfaces=('eth0' 'eth1')
IP=dhcp
IP6=stateless
古い設定を無効にして、bonding を自動的に起動するよう設定してください。新しいプロファイルに切り替えるには:
# netctl switch-to bonding
Wired to wireless failover
This example describes how to use bonding to fallback to wireless when the wired ethernet goes down. The presence of network connection on each interface is detected and dhcpcd is started when connection on either or both interfaces is established.
You'll need additional packages from the official repositories: ifplugd, ifenslave and wpa_supplicant.
First configure the bonding driver to use active-backup:
/etc/modprobe.d/bonding.conf
options bonding mode=active-backup options bonding miimon=100 options bonding primary=eth0 options bonding max_bonds=0
The max_bonds option avoids the Interface bond0 already exists error.
Next, configure a netctl profile to enslave the two hardware interfaces:
/etc/netctl/failover
Description='A wired connection with failover to wireless'
Interface='bond0'
Connection=bond
BindsToInterfaces=('eth0' 'wlan0')
IP='no'
SkipNoCarrier='no'
Enable the profile on startup.
# netctl enable failover
Configure wpa_supplicant to associate with known networks. This can be done with a netctl profile (remember to use IP='no') and a wpa_supplicant service running constantly, or on-demand with wpa_cli. Ways to do this are covered on the wpa_supplicant page.
Create an ifplugd action for automatic DHCP assignment on the bonded interface:
/etc/ifplugd/bond_dhcp.action
#!/bin/sh
case "$2" in
up)
systemctl start "dhcpcd@$1.service" && exit 0
;;
down)
systemctl stop "dhcpcd@$1.service" && exit 0
;;
*)
echo "Wrong arguments" > /dev/stderr
;;
esac
exit 1
and make it executable
# chmod +x /etc/ifplugd/bond_dhcp.action
Then create the systemd service which starts ifplugd for bond0:
/etc/systemd/system/net-auto-bonded@.service
[Unit] Description=Provides automatic dhcp resolution for bonded failover connection Requires=netctl@failover.service After=netctl@failover.service [Service] ExecStart=/usr/bin/ifplugd -i %i -r /etc/ifplugd/bond_dhcp.action -fIns [Install] WantedBy=multi-user.target
Enable the net-auto-bonded service and reboot:
# systemctl enable net-auto-bonded@bond0.service # reboot
If you have a wired and wireless connection to the same network, you can probably now disconnect and reconnect the wired connection without losing connectivity. In most cases, even streaming music won't skip!