NetworkManager (日本語)
| 概要 |
|---|
| NetworkManager のインストールと設定について – ネットワークをシンプルに簡単に設定するツールセット。 |
| 概括 |
Arch Linux ではネットワークを設定するために netctl を提供しています。デスクトップやサーバーにおいて、netctl は有線接続または無線接続のセットアップやローミングをサポートし、ネットワーク設定の管理を容易にします。NetworkManager や Wicd は人気のある代替です。
|
NetworkManager はネットワークの検知とシステムの設定を自動で行いネットワークに接続するプログラムです。NetworkManager の機能は無線・有線両方のネットワークに使うことができます。無線ネットワークでは、NetworkManager は既知の無線ネットワークを優先し、一番信頼性のあるネットワークに切り替えることができます。NetworkManager 対応アプリケーションはオンラインとオフラインを切り替えることが可能です。また、NetworkManager では無線接続よりも有線接続が優先され、モデム接続や特定の VPN に対応しています。NetworkManager はもともとは Red Had によって開発されていましたが、現在では GNOME プロジェクトによってホストされています。
ベースインストール
NetworkManager は公式リポジトリにある networkmanager パッケージでインストールできます。
VPN サポート
Network Manager の VPN サポートはプラグインシステムをベースにしています。NetworkManager で VPN のサポートが必要なときは公式リポジトリから以下のパッケージの内どれかをインストールしてください:
グラフィカルフロントエンド
NetworkManager を簡単に使えるようにするためのアプレットをインストールすることができます。この GUI フロントエンドはシステムトレイ(や通知エリア)に収納され、NetworkManager のネットワーク選択や設定が可能です。異なるデスクトップにあわせて様々なアプレットが存在します。
GNOME
GNOME の network-manager-applet は軽量で全ての環境で動作します。
認証情報 (Wireless/DSL) を保存して接続設定を "全てのユーザーから使えるようにする" には GNOME Keyring をインストール・設定してください。
KDE
KNetworkManager フロントエンドは Plasma ウィジェットであり、公式リポジトリの kdeplasma-applets-networkmanagement として利用可能です。
Plasma ウィジェットと nm-applet の両方をインストールしていて、KDE を使っているときは nm-applet を起動したくないときは、次の行を /etc/xdg/autostart/nm-applet.desktop に加えて下さい:
NotShowIn=KDE
詳しくは Userbase page を見て下さい。
XFCE
network-manager-applet が XFCE で動作しますが、通知(とエラーメッセージ)を表示するために nm-applet には Freedesktop デスクトップ通知 (Galapago Project を見て下さい) の実装が必要です。通知を有効にするには xfce4-notifyd パッケージをインストールしてください。仕様を満たした実装を提供します。
通知デーモンがないと、nm-applet アプレットは以下のエラーを標準出力に表示します:
(nm-applet:24209): libnotify-WARNING **: Failed to connect to proxy ** (nm-applet:24209): WARNING **: get_all_cb: couldn't retrieve system settings properties: (25) Launch helper exited with unknown return code 1. ** (nm-applet:24209): WARNING **: fetch_connections_done: error fetching connections: (25) Launch helper exited with unknown return code 1. ** (nm-applet:24209): WARNING **: Failed to register as an agent: (25) Launch helper exited with unknown return code 1
nm-applet は問題なく動作しますが、通知は表示されません。
新しい wifi ネットワークに接続したときに nm-applet がパスワードを訊かないで、すぐに切断してしまう場合、おそらく gnome-keyring をインストールする必要があります。
Openbox
Openbox で正しく動作させるには、XFCE と同じ理由で GNOME アプレットに xfce4-notifyd 通知デーモンが必要です。また、システムトレイにアプレットを表示するには gnome-icon-theme パッケージが必要です。
認証情報 (Wireless/DSL) を保存するには gnome-keyring をインストール・設定してください。
nm-applet は autostart ファイルを /etc/xdg/autostart/nm-applet.desktop にインストールします。これに問題が発生する場合 (例: nm-applet が二度起動する、全く起動しない)、Openbox (日本語)#Autostart ディレクトリ や [1] を見て解決してください。
他のデスクトップ・ウィンドウマネージャ
その他の場合は GNOME アプレットを使うことを推奨します。アプレットを表示するには gnome-icon-theme もインストールしておく必要があります。
接続情報を保存するには gnome-keyring をインストール・設定してください。
システムトレイを使わずに nm-applet を動作させるために、trayer や stalonetray を使うことができます。例えば、以下のようなスクリプトを追加できます:
nmgui
#!/bin/sh nm-applet > /dev/null 2>/dev/null & stalonetray > /dev/null 2>/dev/null killall nm-applet
stalonetray ウィンドウを閉じたときに、nm-applet も終了するので、ネットワーク設定で無駄なメモリが使われません。
コマンドライン
networkmanager パッケージは version 0.8.1 から nmcli を含んでいます。
設定
NetworkManager には正しく機能させるために必要なことがあります。
次に進む前に /etc/hosts が正しいことを確認してください。この手順を行う前に接続を試すと、NetworkManager が設定を変えてしまうことがあります。/etc/hosts の例:
/etc/hosts
127.0.0.1 localhost ::1 localhost
nss-myhostname を使っていない場合:
/etc/hosts
127.0.0.1 my-laptop localhost ::1 my-laptop localhost
NetworkManager を有効にする
NetworkManager デーモンが起動すると、自動的に設定済みの有効な "システム接続" に接続します。"ユーザー接続"や設定していない接続には nmcli やアプレットを使って設定・接続する必要があります。
次のコマンドで起動時に NetworkManager を有効にできます:
# systemctl enable NetworkManager
次のコマンドですぐに NetworkManager デーモンを起動できます:
# systemctl start NetworkManager
NetworkManager Wait Online を有効にする
ネットワークが立ち上がる前にサービスが起動して失敗する場合、NetworkManager サービスにあわせて NetworkManager-wait-online.service を使って下さい。ただし、ネットワークが設定されていないときでも殆どのネットワークデーモンは正しく立ち上がるので、これが必要になるのは稀です。
次のコマンドで起動時に NetworkManager Wait Online を有効にできます:
# systemctl enable NetworkManager-wait-online
それでもサービスが正しく起動できない場合:
NetworkManager-wait-online.service: main process exited, code=exited, status=1/FAILURE Failed to start Network Manager Wait Online Unit NetworkManger-wait-online.service entered failed state Starting Network. Reached target Network.
これは /usr/lib/systemd/system/NetworkManager-wait-online.service のタイムアウト設定が短すぎることが原因です。デフォルトのタイムアウトである 30 を高い値に修正してください。
PolicyKit パーミッションの設定
ワーキングセッションの設定については General Troubleshooting#Session permissions を参照してください。
With a working session, you have several options for granting the necessary privileges to NetworkManager:
Option 1. Run a PolicyKit authentication agent when you log in, such as /usr/lib/polkit-gnome/polkit-gnome-authentication-agent-1 (part of polkit-gnome). You will be prompted for your password whenever you add or remove a network connection.
Option 2. Add yourself to the wheel group. You will not have to enter your password, but your user account may be granted other permissions as well, such as the ability to use sudo without entering the root password.
Option 3. Add yourself to the network group and create the following file:
/etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules
polkit.addRule(function(action, subject) {
if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0 && subject.isInGroup("network")) {
return polkit.Result.YES;
}
});
All users in the network group will be able to add and remove networks without a password. This will not work under systemd if you do not have an active session with systemd-logind.
ネットワークサービスと NetworkManager dispatcher
NetworkManager がインターフェースを立ち上げるまで動かしたくないネットワークサービスというのが相当数存在します。OpenNTPD や様々なタイプのネットワークファイルシステムマウント (例: netfs) が好例です。NetworkManager には、あなたがネットワークに接続したときにこれらのサービスを起動して、切断したときにサービスを停止する機能があります。この機能を有効にするには NetworkManager-dispatcher サービスを有効化・起動してください:
# systemctl start NetworkManager-dispatcher
# systemctl enable NetworkManager-dispatcher
機能が有効にすれば、スクリプトを /etc/NetworkManager/dispatcher.d ディレクトリに追加することができます。スクリプトは実行可能でユーザーのパーミッションがなければなりません。セキュリティ上、スクリプトの所有者を root:root にして書き込み権限を所有者だけに与えるとよいでしょう。
接続時にアルファベット順でスクリプトは実行され、切断時にはアルファベットの逆順で実行されます。スクリプトには2つの引数が渡されます: インターフェースの名前 (例: eth0) と状態 (up か down) です。起動する順番を正確に決めるために、しばしばスクリプトの名前の前に数字が使われます (例: 10_portmap や 30_netfs (これでポートマップが NFS マウントよりも先に実行されます)。
OpenNTPD を起動
以下の例ではインターフェースが上がった時に OpenNTPD デーモンを起動しています。このファイルを /etc/NetworkManager/dispatcher.d/20_openntpd として保存して実行可能にしてください。
#!/bin/sh
interface=$1 status=$2
case $status in
up)
systemctl start openntpd
;;
down)
if ! nm-tool | awk '/State:/{print $2}' | grep -qs connected; then
systemctl stop openntpd
fi
;;
esac
リモートフォルダを sshfs でマウント
As the script is run in a very restrictive environment, you have to export SSH_AUTH_SOCK in order to connect to your SSH agent. There are different ways to accomplish this, see this link for more information. The example below works with gnome-keyring, and will ask you for the password if not unlocked already. In case NetworkManager connects automatically on login, it is likely gnome-keyring has not yet started and the export will fail (hence the sleep). The UUID to match can be found with the command nmcli con status or nmcli con list.
#!/bin/sh
USER='username'
REMOTE='user@host:/remote/path'
LOCAL='/local/path'
interface=$1 status=$2
if [ "$CONNECTION_UUID" = "<uuid>" ]; then
case $status in
up)
export SSH_AUTH_SOCK=$(find /tmp -maxdepth 1 -type s -user "$USER" -name 'ssh')
su "$USER" -c "sshfs $LOCAL $REMOTE"
;;
down)
fusermount -u "$LOCAL"
;;
esac
fi
dispatcher を使ってネットワーク接続が確立された後に VPN に接続する
In this example we want to connect automatically to a previously defined VPN connection after connecting to a specific WiFi network. First thing to do is to create the dispatcher script that defines what to do after we are connected to the network.
- 1. Create the dispatcher script:
/etc/NetworkManager/dispatcher.d/vpn-up
#!/bin/sh
VPN_NAME="name of VPN connection defined in NetworkManager"
ESSID="wifi network ESSID (not connection name)"
interface=$1 status=$2
case $status in
up|vpn-down)
if iwgetid | grep -qs ":\"$ESSID\""; then
nmcli con up id "$VPN_NAME"
fi
;;
down)
if iwgetid | grep -qs ":\"$ESSID\""; then
if nmcli con status id "$VPN_NAME" | grep -qs activated; then
nmcli con down id "$VPN_NAME"
fi
fi
;;
esac
Remember to make it executable with chmod +x and to make the VPN connection available to all users.
Trying to connect using this setup will fail and NetworkManager will complain about 'no valid VPN secrets', because of the way VPN secrets are stored which brings us to step 2:
- 2. Edit your VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring that will be inaccessible for root: open up
/etc/NetworkManager/system-connections/<name of your VPN connection>and change thepassword-flagsandsecret-flagsform1to0.
プロクシ設定
NetworkManager は直接プロクシ設定を扱いませんが、GNOME を使っている場合、NetworkManager の情報を使ってプロクシ設定を管理する proxydriver を使うことができます。AUR の proxydriver パッケージを探して下さい。
proxydriver でプロクシ設定を変更できるようにするには、GNOME スタートアッププロセスの一部として、次のコマンドを実行する必要があります (System -> Preferences -> Startup Applications):
xhost +si:localuser:your_username
参照: Proxy settings
テスト
ログイン時に NetworkManager アプレットがロードされるようになっているので、ほとんどの場合さらに設定をする必要はありません。既に前のネットワーク設定を無効にしてネットワークから切断している場合、NetworkManager が動作するかどうかテストすることができます。まず networkmanager デーモンを起動してください。
アプレットは .desktop ファイルを提供するので、NetworkManager アプレットはアプリケーションメニューからロードすることができます。アプレットがない場合、コマンドを探すか、一度ログアウトしてからログインしなおしてアプレットを起動してください。アプレットが起動すれば、DHCP サーバーの自動設定によってネットワーク接続のポーリングを開始します。
Awesome などの xdg 非互換のウィンドウマネージャで GNOME アプレットを起動するには:
nm-applet --sm-disable &
固定 IP を使うには NetworkManager を設定する必要があります。アプレットを右クリックして 'Edit Connections' などを選択してください。
トラブルシューティング
一般的な問題に対する修正。
PPTP トンネルを使って通信できない
PPTP 接続のログインが成功すると、適切な VPN IP の ppp0 インターフェースが表示されますが、リモートの IP に ping できません。これは標準の Arch の pppd に MPPE (Microsoft Point-to-Point Encryption) サポートがないのが原因です。まず標準の Arch の ppp を使って予期通り動作するか試すことを推奨します。
問題を解決するには AUR から ppp-mppe をインストールしてください。
Network management disabled
時々 NetworkManager を終了したときに pid (state) ファイルが削除されずに 'Network management disabled' というメッセージが表示されることがあります。これが発生した場合は、手動でファイルを削除する必要があります:
# rm /var/lib/NetworkManager/NetworkManager.state
再起動時に起こる場合は、/etc/rc.local に起動時に削除するアクションを追加することができます:
nmpid=/var/lib/NetworkManager/NetworkManager.state [ -f $nmpid ] && rm $nmpid
resolv.conf.head や resolv.conf.tail を使う
resolv.conf (日本語) を見て下さい。また、NetworkManager が dhclient ではなく dhcpcd を使うようにしてください。dhclient を使いたい場合、AUR の networkmanager-dispatch-resolv パッケージを試すことができます。
resolv.conf の変更を防ぐ
Resolv.conf (日本語) を参照。
DHCP に関する問題
DHCP を使って IP を取得するときに問題が起こるときは、以下を /etc/dhclient.conf に追加してみてください:
interface "eth0" {
send dhcp-client-identifier 01:aa:bb:cc:dd:ee:ff;
}
aa:bb:cc:dd:ee:ff は NIC の MAC アドレスに置き換えてください。MAC アドレスは iproute2 パッケージの ip link show eth0 コマンドを使うことでわかります。
ルーターによっては、/etc/dhcpcd.conf (dhcpd.conf とは別のファイルです) 内の次の行をコメントアウトしないと正しく接続できないことがあります:
require dhcp_server_identifier
ネットワーク上で複数の DHCP サーバーを使ってなければこの修正によって問題が起こることはありません。詳細は このページ を見て下さい。
ホストネーム問題
次の行を /etc/NetworkManager/NetworkManager.conf に加えて:
dhcp=dhcpcd
再起動してください。
systemctl restart NetworkManager
ソース: https://bbs.archlinux.org/viewtopic.php?id=152376
デフォルトの route が見つからない
On at least one KDE4 system, no default route was created when establishing wireless connections with NetworkManager. Changing the route settings of the wireless connection to remove the default selection "Use only for resources on this connection" solved the issue.
3G モデムが検知されない
NetworkManager (v0.7.999 以上) が 3G モデムを検知しないのに、wvdial を使って接続できる場合、modemmanager をインストールして systemctl restart NetworkManager を実行して NetworkManager デーモンを再起動してみてください。また、モデムを再接続したり再起動する必要があるかもしれません。このユーティリティは NetworkManager のデフォルトデータベースにはないハードウェアをサポートしています。
ラップトップで WLAN をオフに切り替える
ラップトップについているスイッチを使って WiFi アダプタを無効にしてその後また有効にした時に NetworkManager が動作しないことがしばしばあります。これはほとんど rfkill の問題です。公式リポジトリから rfkill をインストールして、ドライバが rfkill に無線アダプタの状態を通知しているかどうか確かめるために次のコマンドを実行してください:
$ watch -n1 rfkill list all
アダプタの切り替えを行った後に identifier がブロックされたままの場合、手動でブロックを解除することができます (X は上のコマンドで出力された identifier の番号に置き換えてください):
# rfkill event unblock X
固定 IP 設定を DHCP に戻す
Due to an unresolved bug, when changing default connections to static IP, nm-applet may not properly store the configuration change, and will revert to automatic DHCP.
To work around this issue you have to edit the default connection (e.g. "Auto eth0") in nm-applet, change the connection name (e.g. "my eth0"), uncheck the "Available to all users" checkbox, change your static IP settings as desired, and click Apply. This will save a new connection with the given name.
Next, you will want to make the default connection not connect automatically. To do so, run nm-connection-editor (not as root). In the connection editor, edit the default connection (eg "Auto eth0") and uncheck "Connect automatically". Click Apply and close the connection editor.
ノーマルユーザーで接続を編集できない
#PolicyKit パーミッションの設定 を見て下さい。
隠れた無線ネットワークの削除
Since hidden network are not displayed in the selection list of the Wireless view, they cannot be forgotten (removed) with the GUI. You can delete one with the following command:
# rm /etc/NetworkManager/system-connections/[SSID]
This works for any other connection.
VPN が Gnome で動作しない
When setting up openconnect or vpnc connections in NetworkManager while using Gnome, you'll sometimes never see the dialog box pop up and the following error appears in /var/log/errors.log:
localhost NetworkManager[399]: <error> [1361719690.10506] [nm-vpn-connection.c:1405] get_secrets_cb(): Failed to request VPN secrets #3: (6) No agents were available for this request.
This is caused by the Gnome NM Applet expecting dialog scripts to be at /usr/lib/gnome-shell, when NetworkManager's packages put them in /usr/lib/networkmanager. As a "temporary" fix (this bug has been around for a while now), make the following symlink(s):
# For OpenConnect ln -s /usr/lib/networkmanager/nm-openconnect-auth-dialog /usr/lib/gnome-shell/
# For VPNC (i.e. Cisco VPN) ln -s /usr/lib/networkmanager/nm-vpnc-auth-dialog /usr/lib/gnome-shell/
This may need to be done for any other NM VPN plugins as well, but these are the two most common.
Tips and tricks
wifi でインターネット接続を共有する
nm を使って数クリックでインターネット接続 (例: 3G または有線) を共有することができます。サポートされた wifi カードが必要になります (Atheros AR9xx や AR5xx を使っているカードがおそらく最適です)。
Ad-hoc
- Install the dnsmasq package to be able to actually share the connection.
- custom dnsmasq.conf may interfere with nm (not sure about this, but i think so)
- Click on nm-applet -> Create new wireless network
- Follow wizard (if using WEP be sure to use 5 or 13 charactes long password, different lengths will fail)
- Settings will remain stored for next time you'll need it
Real AP
Support of infrastructure mode (which is needed by Android phones as they don't intentionally support ad-hoc) is not currently supported by NetworkManager, but is in active development...
参照: http://fedoraproject.org/wiki/Features/RealHotspot
cron ジョブやスクリプトでネットワークが立ち上がっているか確認する
Some cron jobs require networking to be up to succeed. You may wish to avoid running these jobs when the network is down. To accomplish this, add an if test for networking that queries NetworkManager's nm-tool and checks the state of networking. The test shown here succeeds if any interface is up, and fails if they are all down. This is convenient for laptops that might be hardwired, might be on wireless, or might be off the network.
if [ `nm-tool|grep State|cut -f2 -d' '` == "connected" ]; then
#Whatever you want to do if the network is online
else
#Whatever you want to do if the network is offline - note, this and the else above are optional
fi
This useful for a cron.hourly script that runs fpupdate for the F-Prot virus scanner signature update, as an example. Another way it might be useful, with a little modification, is to differentiate between networks using various parts of the output from nm-tool; for example, since the active wireless network is denoted with an asterisk, you could grep for the network name and then grep for a literal asterisk.
ログインのあと自動でキーリングを解除する
GNOME
- Right click on the
nm-appleticon in your panel and select Edit Connections and open the Wireless tab - Select the connection you want to work with and click the Edit button
- Check the boxes “Connect Automatically” and “Available to all users”
Log out and log back in to complete.
- In
/etc/pam.d/gdm(or your corresponding daemon in/etc/pam.d), add these lines at the end of the "auth" and "session" blocks if they do not exist already:
auth optional pam_gnome_keyring.so session optional pam_gnome_keyring.so auto_start
- In
/etc/pam.d/passwd, use this line for the 'password' block:
password optional pam_gnome_keyring.so
- Next time you log in, you should be asked if you want the password to be unlocked automatically on login.
KDE
Put a script like the following in ~/.kde4/Autostart:
#!/bin/sh echo PASSWORD | /usr/bin/pam-keyring-tool --unlock --keyring=default -s
Similar should work with Openbox, LXDE, etc.
SLiM ログインマネージャ
SLiM (日本語)#SLiM と Gnome Keyring を見て下さい。
特定のデバイスを無視する
Sometimes it may be desired that NetworkManager ignores specific devices and does not try to configure addresses and routes for them.You can quickly and easily ignore devices by MAC by using the following in /etc/NetworkManager/NetworkManager.conf :
[keyfile] unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4
After you have put this in, restart NetworkManager, and you should be able to configure interfaces without NetworkManager altering what you have set.
接続の高速化
IPv6 を無効にする
NetworkManager の余計な IPv6 クエリーによって接続が遅くなったりネットワークの再接続が起こることがあります。ローカルネットワークで IPv6 をサポートしていない場合、NetworkManager が IPv6 の接続を確立しようとして結局タイムアウトするので、通常よりもネットワークへの接続に時間がかかるかもしれません。解決策は NetworkManager で IPv6 を無効にすることで、これによってネットワーク接続が高速になります。以下は接続するネットワークごとに実行する必要があります。
- ネットワーク状態アイコンを右クリック。
- "Edit Connections" をクリック。
- "Wired" か "Wireless" タブを見る。
- ネットワークの名前を選択。
- "Edit" をクリック。
- "IPv6 Settings" タブを見る。
- "Method" ドロップダウンから "Ignore/Disabled" を選択。
- "Save" をクリック。
DHCPCD の ARP probing を無効にして DHCP をスピードアップ
dhcpcd contains an implementation of a recommendation of the DHCP standard (RFC2131 section 2.2) to check via ARP if the assigned IP address is really not taken. This seems mostly useless in home networks, so you can save about 5 seconds on every connect by adding the following line to /etc/dhcpcd.conf:
noarp
This is equivalent to passing --noarp to dhcpcd, and disables the described ARP probing, speeding up connections to networks with DHCP.
OpenDNS サーバーを使う
/etc/resolv.conf.opendns を以下のネームサーバで作成してください:
nameserver 208.67.222.222 nameserver 208.67.220.220
もしくは Google DNS サーバーを使って下さい:
nameserver 8.8.8.8 nameserver 8.8.4.4
そして DHCP サーバーを OpenDNS サーバーに置き換える dispatcher を作って下さい:
/etc/NetworkManager/dispatcher.d/dns-servers-opendns
#!/bin/bash # Use OpenDNS servers over DHCP discovered servers cp -f /etc/resolv.conf.opendns /etc/resolv.conf
スクリプトを実行可能にします:
# chmod +x /etc/NetworkManager/dispatcher.d/dns-servers-opendns