dhcpcd

提供: ArchWiki
2015年1月6日 (火) 21:37時点におけるKusakata (トーク | 投稿記録)による版 (1版 をインポートしました)
ナビゲーションに移動 検索に移動

関連記事

dhcpcd は DHCP と DHCPv6 のクライアントです。現在は最も機能豊富なオープンソースの DHCP クライアントであり、ホームページに全ての機能のリストが載っています。

ノート: dhcpcd (DHCP client デーモン) は dhcpd (DHCP (server) デーモン) とは違います。

インストール

dhcpcd パッケージは公式リポジトリから入手できます。base グループに含まれているため、通常は既にあなたのシステムにインストールされているはずです。

また、dhcpcd デーモン (と任意で wpa_supplicant) の GTK+ フロントエンドである dhcpcd-uiAUR を使うこともできます。設定ダイアログで、パスフレーズを入力して無線ネットワークに接続することができます。

実行

dhcpcd は基本的にサービスファイル dhcpcd@.service で操作します、インターフェイス名を引数として指定します (詳しくは systemd#ユニットを使う を見て下さい):

# systemctl start dhcpcd@interface.service
# systemctl enable dhcpcd@interface.service

手動で dhcpcd を起動するには、次のコマンドを実行してください:

# dhcpcd interface
dhcpcd: version 5.1.1 starting
dhcpcd: interface: broadcasting for a lease
...
dhcpcd: interface: leased 192.168.1.70 for 86400 seconds

設定

メインの設定は /etc/dhcpcd.conf で行います、詳細は dhcpcd.conf(5) を参照してください。よく使われるオプションについては以下で説明します。

DHCP スタティックルート

If you need to add a static route client-side, create a new dhcpcd hook-script in /usr/lib/dhcpcd/dhcpcd-hooks. The example shows a new hook-script which adds a static route to a VPN subnet on 10.11.12.0/24 via a gateway machine at 192.168.192.5:

/usr/lib/dhcpcd/dhcpcd-hooks/40-vpnroute
ip route add 10.11.12.0/24 via 192.168.192.5

The 40 prefix means that it is the final hook-script to run when dhcpcd starts.

DHCP クライアント ID

The DHCP client may be uniquely identified in different ways by the server:

  • hostname (or the hostname value sent by the client),
  • MAC address of the network interface controller through which the connection is being made, linked to this is the third,
  • Identity Association ID (IAID), which is an abstraction layer to differentiate different use-cases and/or interfaces on a single host,
  • DHCP Unique Identifier (DUID).

For a further description, see RFC 3315.

It depends on the DHCP-server configuration which options are optional or required to request a DHCP IP lease. If the dhcpcd default configuration fails to obtain an IP, the following options are available to use in dhcpcd.conf:

  • hostname sends the hostname set in /etc/hostname
  • clientid sends the MAC address as identifier
  • IAID <interface> derives the IAID for the interface <interface> to use for DHCP discovery. Both have to be used together, but more frequently the next option is used:
  • duid triggers using a combination of DUID and IAID as identifier.

The DUID value is set in /etc/dhcpcd.duid.

Care must be taken on a network running Dynamic DNS to ensure that all three are unique. If duplicate DUID values are presented to the DNS server, e.g. in the case where a virtual machine has been cloned and the hostname and MAC have been made unique but the DUID has not been changed, then the result will be that as each client with the duplicated DUID requests a lease the server will remove the predecessor from the DNS record.

ARP プローブを無効にして 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.

予備の固定プロファイル

dhcpcd の中で固定プロファイルを設定して DHCP のリースが失敗したときに、そのプロファイルにフォールバックすることができます。常にマシンに接続できるようにするために固定プロファイルを"リカバリ"プロファイルとして使うことで、特に Raspberry Pi などの ヘッドレスマシンで役に立ちます。

The following example configures a static_eth0 profile with 192.168.1.1 as IP address, 192.168.1.23 as gateway and name server, and makes this profile fallback for interface eth0.

/etc/dhcpcd.conf
# define static profile
profile static_eth0
static ip_address=192.168.1.1
static routers=192.168.1.23
static domain_name_servers=192.168.1.23

# fallback to static profile on eth0
interface eth0
fallback static_eth0

arping オプションを使うなど、もっと複雑な設定をすることもできます。詳しくは dhcpcd.conf(5) を見て下さい。

フック

dhcpcd/usr/lib/dhcpcd/dhcpcd-hooks/ にあるスクリプトを辞書順で全て実行します。詳しくは dhcpcd(5)dhcpcd-run-hooks(8) を見て下さい。

ノート:
  • Each script can be disabled using the nohook option in dhcpcd.conf.
  • The env option can be used to set an environment variable for all hooks. For example, you can force the hostname hook to always set the hostname with env force_hostname=YES.

10-wpa_supplicant

The 10-wpa_supplicant hook automatically launches WPA supplicant on wireless interfaces. It is started only if:

  • no wpa_supplicant process is already listening on that interface.
  • a wpa_supplicant configuration file exists. dhcpcd checks
/etc/wpa_supplicant/wpa_supplicant-"$interface".conf
/etc/wpa_supplicant/wpa_supplicant.conf
/etc/wpa_supplicant-"$interface".conf
/etc/wpa_supplicant.conf

by default, in that order, but a custom path can be set by adding env wpa_supplicant_conf=configuration_file_path into /etc/dhcpcd.conf.

ノート: The hook stops at the first configuration file found, thus you should take this into consideration if you have several wpa_supplicant configuration files, otherwise dhcpcd might end up using the wrong file.

If you manage wireless connections with wpa_supplicant itself, the hook may create unwanted connection events. For example, if you stop wpa_supplicant the hook may bring the interface up again. To disable it, add nohook wpa_supplicant to dhcpcd.conf.

Tips and tricks

Remove old DHCP lease

The file /var/lib/dhcpcd/dhcpcd-interface.lease, where interface is the name of the interface on which you have a lease, contains the actual DHCP lease reply sent by the DHCP server. It is used to determine the last lease from the server, and its mtime attribute is used to determine when it was issued. This last lease information is then used to request the same IP address previously held on a network, if it is available. If you do not want that, simply delete this file.

トラブルシューティング

クライアント ID

また、MAC アドレスに基づくクライアント ID をフィルタリングしている DHCPv4 ネットワークを使う場合は、次の行を:

/etc/dhcpcd.conf
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 Client ID as per RFC4361. 
duid

以下のように変更してください:

/etc/dhcpcd.conf
# Use the hardware address of the interface for the Client ID (DHCPv4).
clientid

こうしないと、DHCP サーバーがあなたの DHCPv6 クライアント ID を正しく読み込めない可能性があります。詳しくは RFC 4361 を見て下さい。

まず IP を開放して DHCP の問題を確認する

DHCP が間違った IP の割り当てを取得している時、問題が起こることがあります。例えば2つのルーターが VPN で結び付けられている場合が考えられます。修正するには、コンソールで、root 権限を使って IP アドレスを開放してください:

# dhcpcd -k

それから新しい IP アドレスをリクエストしてください:

# dhcpcd

おそらくこの2つのコマンドを何度も実行する必要があります。

強情なルーターの問題

For some (incompliant) routers, you will not be able to connect properly unless you comment the line

require dhcp_server_identifier

in /etc/dhcpcd.conf. This should not cause issues unless you have multiple DHCP servers on your network (not typical); see this page for more information.

dhcpcd と systemd ネットワークインターフェイス

インターフェイスを指定しないで dhcpcd.service有効にすることもできますが、predictable network interface name を適用とする systemd-udevd と起動時に競合状態になる可能性があります:

error changing net interface name wlan0 to wlp4s0: Device or resource busy" 

これを避けるために、dhcpcd を有効にするときは #実行 で説明されているようにインターフェイスを指定して下さい。

参照