dhclient-script(8) dhclient-script(8) 名称 dhclient-script - DHCP クライアントのネットワーク設定スクリプト 解説 DHCP ク ラ イ ア ン ト の ネ ットワーク設定スクリプトは、時あるごとに dhclient(8) が呼び出します。 DHCP クライアントは、本スクリプトを使用 す る ことにより、アドレス要求に先立つ各インタフェースの初期設定と、付与さ れたアドレスの検査と、リース獲得時のインタフェースの最終設定を行いま す 。 リースが獲得されなかった場合、定義済みのリースが存在するならばこれを 検査するために本スクリプトは使用され、有効なリースが判明しなかった場 合 にももう 1 回このスクリプトが呼ばれます。 本 スクリプトは、エンドユーザにカスタマイズされることを意図していません 。ローカルなカスタマイズが必要な場合、これは入 (enter) と出 (exit) とい うフックを使用することで可能となります (詳細はフック参照)。これらのフッ クは、 /etc/resolv.conf 作成時に、クライアントのデフォルト動作をユー ザ がオーバライドできるようにします。 特 定のオペレーティングシステムでは、クライアントの実体は動作するとして も、標準のスクリプトが動作しないかもしれません。先駆的なユーザが新規 ス ク リプトを作成したり既存のものを修正したりする必要があることはもっとも なことです。一般的には、それぞれのコンピュータに固有のカスタマ イ ズ は ETCDIR/dhclient.conf スクリプトで行うべきです。 ETCDIR/dhclient.conf の カスタマイズ無しにできないカスタマイズや、入と出のフックの使用ではで き ないカスタマイズに気づいた場合には、バグレポートを送ってください。 フック 開 始時に、クライアントスクリプトはまずシェル関数を定義します。その関数 は make_resolv_conf であり、後に /etc/resolv.conf ファイルを作成する た め に使用されます。デフォルト動作をオーバライドするには、この関数を入の フックスクリプトで再定義してください。 make_resolv_conf 関数の定義の後、クライアントスクリプトは実 行 可 能 な ETCDIR/dhclient-enter-hooks スクリプトの存在を検査し、存在する場合には Bourne シェルの ’.’ コマンドを使用して本スクリプトをインラインで起動 し ま す。操作で記述されているすべての環境が本スクリプトで使用可能であり、 スクリプトの動作の変更が必要な場合には環境の修正が許されています。ス ク リ プト実行中にエラーが発生した場合、 exit_status 変数を非 0 値に設定す ることが可能であり、クライアント ス ク リ プ ト 終 了 直 後 に CLIENT- BINDIR/dhclient-script はそのエラーコードで終了します。 す べ て の 処 理の完了後に、 CLIENTBINDIR/dhclient-script は実行可能な ETCDIR/dhclient-exit-hooks スクリプトの存在を検査し、存在する場合 に は ’.’ コマンドでこれを起動します。 dhclient-script の終了状態は dhclient- exit-hooks の exit_status シェル変数に渡され、起動された仕事にスクリ プ トが成功した場合には値は常に 0 になります。 dhclient-enter-hooks の項で 前述したその他の環境も引き継がれます。 ETCDIR/dhclient-exit-hooks は exit_status に手を加えて dhclient-script の戻り値を変更できます。 操作 dhclient がクライアント設定スクリプトを起動する必要があるとき、様々な変 数を環境に定義してから CLIENTBINDIR/dhclient-script を起動します。す べ て の場合において、$reason にはスクリプトが起動される理由名が設定されま す。次の理由が現在定義されていま す: MEDIUM, PREINIT, BOUND, RENEW, REBIND, REBOOT, EXPIRE, FAIL, TIMEOUT。 MEDIUM DHCP クライアントは、インタフェースのメディアタイプの設定を求めています 。インタフェース名は $interface で渡され、メディアタイプは $medium で渡 されます。 PREINIT DHCP クライアントは、実際のアドレスを受け取る前にパケットを送信する目的 で、要求通りにインタフェースが設定されることを求めています。 BSD のソケ ットライブラリを使用するクライアントでは、 IP アドレス 0.0.0.0 かつブロ ードキャストアドレス 255.255.255.255 で、インタフェースを設定することを 意 味します。他のクライアントでは、実際に IP アドレスを与えることなく単 にインタフェースを設定することで実現されるでしょう。インタフェース名 は $interface で渡され、メディアタイプは $medium で渡されます。 IP エ イ リ アスが dhclient.conf で宣言されている場合、このアドレスが $alias_ip_address で渡されます。本 IP アドレスへの経路とともに、 本 IP アドレスを対象インタフェースから削除する必要があります。 BOUND DHCP クライアントは、新アドレスへの初期の結合を完了しました。新しい IP アドレスは $new_ip_address で渡され、インタフェース名は $interface で渡 されます。メディアタイプは $medium で渡されます。サーバから獲得したオプ ションは、dhcp-options で宣言されているオプション名で渡されます。例外と して、 有効なシェル変数とするためにダッシュ (’-’) はアンダスコア(’_’)で 置き換えられ、変数名は new_ で開始します。例えば、新しいサブネットマ ス クは $new_subnet_mask で渡されます。 ア ドレスを実際に設定する前に、dhclient-script は何らかの方法でそのアド レスに対して ARP を行い、返事を受け取った場合には非 0 の値で終了する べ きです。この場合クライアントは DHCPDECLINE メッセージをサーバに送信し、 違うアドレスを取得します。この作業は RENEW, REBIND, REBOOT 状態でも同様 に行いますが、必ずしも必要ではなく、実際好ましくないでしょう。 結 合が完了すると、ネットワークに関する多くのパラメータを設定する必要が あるでしょう。 $new_domain_name および $new_domain_name_servers (これに は 複数のサーバを空白で区切って列挙してあるかもしれません) を使用して、 新しい /etc/resolv.conf を作成する必要があります。デフォ ル ト 経 路 は 、$new_routers を 使 用 し て 設 定 す る 必 要があります。静的経路は 、$new_static_routes を使用して設定する必要があるかもしれません。 IP エイリアスが宣言されている場合、ここで設定する必要があります。エイリ ア スの IP アドレスは $alias_ip_address として記述され、エイリアス用に 設定される他の DHCP オプション (例えばサブネットマスク) は前述のよう に 変 数で渡されますが、 $new_ で開始するのではなく $alias_ で開始します。 エイリアスの IP アドレスが結合された IP アドレス ($new_ip_address) と同 じ 場合、これを使用してはならないことに注意してください。なぜなら、この 場合には他のエイリアスのパラメータが正しくない可能性があるからです。 RENEW 結合が更新されると、スクリプトは BOUND と同様に呼ばれますが、 $new_ で 開 始する全変数に加えて $old で開始する別の変数の組があるという例外があ ります。変更された可能性がある永続的な設定は、削除する必要があります 。 例 えば、結合されたアドレスに対するローカル経路が設定された場合、古いロ ーカル経路を削除する必要があります。デフォルト経路が変更された場合、 古 い デフォルト経路を削除する必要があります。静的経路が変更された場合、古 いものを削除する必要があります。その他については、BOUND と同様に処理 可 能です。 REBIND DHCP クライアントが、新規 DHCP サーバに再結合されました。これは RENEW と同様に扱えますが、IP アドレスが変わった場合には、 ARP 表をクリアす る 必要があります。 REBOOT DHCP クライアントは、リブート後に元のアドレスを再獲得することに成功しま した。これは BOUND と同様に処理可能です。 EXPIRE DHCP クライアントはリース更新と新規リース獲得に失敗し、リースの期限が切 れました。対象 IP アドレスを解放する必要があり、 RENEW および REBIND と 同様に、関連するパラメータを削除する必要があります。 FAIL DHCP クライアントは DHCP サーバに接続できず、また検査した IP アドレスに は 有効なものはありませんでした。最後に検査したリースのパラメータは、設 定解除する必要があります。これは、EXPIRE と同様に扱えます。 TIMEOUT DHCP クライアントはどの DHCP サーバにも接続できませんでした。しかしなが ら、古いリースが識別され、 BOUND と同様に、この古いリースのパラメータが 渡されました。クライアントの設定スクリプトは、このパラメータを検査し 、 これが有効であると信じる理由があるならば、値 0 で終了すべきです。そうで ないならば、非 0 の値で終了すべきです。 リースを検査する通常の方法は、REBIND と同様にネットワークを設定して (複 数のリースを検査するために呼ばれることがあるからです)、 $routers で定義 される最初のルータに ping することです。応答を受信した場合、インタフ ェ ー ス が 現 在 接 続 されているネットワークに対して、リースが有効です。 $new_static_routers に加えて $new_routers に列挙されている全ル ー タ に ping を試すようになれば、完全性が増すでしょう。しかし、現在のスクリプト はそうなっていません。 関連ファイル 類似したオペレーティングシステムに対するスクリプトファイルは似ていた り 全 く同じかもしれませんが、一般には、各オペレーティングシステム用に各々 のスクリプトファイルがあるべきです。 Internet Software Consortium の DHCP 配布に含まれるスクリプトファイルは、 client/scripts 以下の配布ツリ ーにあり、動作対象オペレーティングシステム名になっています。 バグ 複数インタフェースを使用する場合、サーバが提供する設定パラメータ同士 が 衝 突 し ないようにする明確な方法はありません。例えば、標準の dhclient- script は /etc/resolv.conf を再度書き換えてしまいます。すなわち、複数の イ ン タ フ ェ ー ス が設定されている場合、あるサーバから提供される値に /etc/resolv.conf が初期化された後に、別のサーバから提供される値に初期化 さ れるという動作を繰り返します。どちらのサーバから提供される情報も有効 である場合には、実際上問題とはならないものの、混乱のもとになりえます。 関連項目 dhclient.conf(5), dhclient.leases(5), dhclient(8) 作者 dhclient-script(8) は Ted Lemon が Vixie Enterprises と協力して Inter- net Software Consortium のために書きました。 Internet Software Consor- tium についてより詳しくは、 http://www.isc.org をご覧ください 。 Vixie Enterprises についてより詳しくは、 http://www.vix.com をご覧ください。 dhclient-script(8)
dhclient-script(8) dhclient-script(8) NAME dhclient-script - DHCP client network configuration script DESCRIPTION The DHCP client network configuration script is invoked from time to time by dhclient(8). This script is used by the dhcp client to set each interface’s initial configuration prior to requesting an address, to test the address once it has been offered, and to set the inter- face’s final configuration once a lease has been acquired. If no lease is acquired, the script is used to test predefined leases, if any, and also called once if no valid lease can be identified. This script is not meant to be customized by the end user. If local customizations are needed, they should be possible using the enter and exit hooks provided (see HOOKS for details). These hooks will allow the user to override the default behaviour of the client in creating a /etc/resolv.conf file, and to handle DHCP options not handled by default. No standard client script exists for some operating systems, even though the actual client may work, so a pioneering user may well need to create a new script or modify an existing one. In general, cus- tomizations specific to a particular computer should be done in the /etc/dhcp/dhclient.conf file. If you find that you can’t make such a customization without customizing /etc/dhcp/dhclient.conf or using the enter and exit hooks, please submit a bug report. HOOKS When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script. On after defining the make_resolv_conf function, the client script checks for the presence of an executable /etc/dhcp/dhclient-enter-hooks script, and if present, it invokes the script inline, using the Bourne shell ’.’ command. The entire environment documented under OPERATION is available to this script, which may modify the environment if needed to change the behaviour of the script. If an error occurs during the execution of the script, it can set the exit_status variable to a nonzero value, and /sbin/dhclient-script will exit with that error code immediately after the client script exits. After all processing has completed, /sbin/dhclient-script checks for the presence of an executable /etc/dhcp/dhclient-exit-hooks script, which if present is invoked using the ’.’ command. The exit status of dhclient-script will be passed to dhclient-exit-hooks in the exit_sta- tus shell variable, and will always be zero if the script succeeded at the task for which it was invoked. The rest of the environment as described previously for dhclient-enter-hooks is also present. The /etc/dhcp/dhclient-exit-hooks script can modify the valid of exit_sta- tus to change the exit status of dhclient-script. Immediately after dhclient brings an interface UP with a new IP address, subnet mask, and routes, in the REBOOT/BOUND states, it will check for the existence of an executable /etc/dhcp/dhclient-up-hooks script, and source it if found. This script can handle DHCP options in the environment that are not handled by default. A per-interface. /etc/dhcp/dhclient-${IF}-up-hooks script will override the generic script and be sourced when interface $IF has been brought up. Immediately before dhclient brings an interface DOWN, removing its IP address, subnet mask, and routes, in the STOP/RELEASE states, it will check for the existence of an executable /etc/dhcp/dhclient-down-hooks script, and source it if found. This script can handle DHCP options in the environment that are not handled by default. A per-interface /etc/dhcp/dhclient-${IF}-down-hooks script will override the generic script and be sourced when interface $IF is about to be brought down. OPERATION When dhclient needs to invoke the client configuration script, it defines a set of variables in the environment, and then invokes /sbin/dhclient-script. In all cases, $reason is set to the name of the reason why the script has been invoked. The following reasons are currently defined: MEDIUM, PREINIT, BOUND, RENEW, REBIND, REBOOT, EXPIRE, FAIL, STOP, RELEASE, NBI and TIMEOUT. MEDIUM The DHCP client is requesting that an interface’s media type be set. The interface name is passed in $interface, and the media type is passed in $medium. PREINIT The DHCP client is requesting that an interface be configured as required in order to send packets prior to receiving an actual address. For clients which use the BSD socket library, this means configuring the interface with an IP address of 0.0.0.0 and a broadcast address of 255.255.255.255. For other clients, it may be possible to simply con- figure the interface up without actually giving it an IP address at all. The interface name is passed in $interface, and the media type in $medium. If an IP alias has been declared in dhclient.conf, its address will be passed in $alias_ip_address, and that ip alias should be deleted from the interface, along with any routes to it. BOUND The DHCP client has done an initial binding to a new address. The new ip address is passed in $new_ip_address, and the interface name is passed in $interface. The media type is passed in $medium. Any options acquired from the server are passed using the option name described in dhcp-options, except that dashes (’-’) are replaced by underscores (’_’) in order to make valid shell variables, and the vari- able names start with new_. So for example, the new subnet mask would be passed in $new_subnet_mask. Before actually configuring the address, dhclient-script should somehow ARP for it and exit with a nonzero status if it receives a reply. In this case, the client will send a DHCPDECLINE message to the server and acquire a different address. This may also be done in the RENEW, REBIND, or REBOOT states, but is not required, and indeed may not be desirable. When a binding has been completed, a lot of network parameters are likely to need to be set up. A new /etc/resolv.conf needs to be cre- ated, using the values of $new_domain_name and $new_domain_name_servers (which may list more than one server, separated by spaces). A default route should be set using $new_routers, and static routes may need to be set up using $new_static_routes. If an IP alias has been declared, it must be set up here. The alias IP address will be written as $alias_ip_address, and other DHCP options that are set for the alias (e.g., subnet mask) will be passed in vari- ables named as described previously except starting with $alias_ instead of $new_. Care should be taken that the alias IP address not be used if it is identical to the bound IP address ($new_ip_address), since the other alias parameters may be incorrect in this case. RENEW When a binding has been renewed, the script is called as in BOUND, except that in addition to all the variables starting with $new_, there is another set of variables starting with $old_. Persistent settings that may have changed need to be deleted - for example, if a local route to the bound address is being configured, the old local route should be deleted. If the default route has changed, the old default route should be deleted. If the static routes have changed, the old ones should be deleted. Otherwise, processing can be done as with BOUND. REBIND The DHCP client has rebound to a new DHCP server. This can be handled as with RENEW, except that if the IP address has changed, the ARP table should be cleared. REBOOT The DHCP client has successfully reacquired its old address after a reboot. This can be processed as with BOUND. EXPIRE The DHCP client has failed to renew its lease or acquire a new one, and the lease has expired. The IP address must be relinquished, and all related parameters should be deleted, as in RENEW and REBIND. FAIL The DHCP client has been unable to contact any DHCP servers, and any leases that have been tested have not proved to be valid. The parame- ters from the last lease tested should be deconfigured. This can be handled in the same way as EXPIRE. STOP The dhclient has been informed to shut down gracefully, the dhclient- script should unconfigure or shutdown the interface as appropriate. RELEASE The dhclient has been executed using the -r flag, indicating that the administrator wishes it to release its lease(s). dhclient-script should unconfigure or shutdown the interface. NBI No-Broadcast-Interfaces...dhclient was unable to find any interfaces upon which it believed it should commence DHCP. What dhclient-script should do in this situation is entirely up to the implementor. TIMEOUT The DHCP client has been unable to contact any DHCP servers. However, an old lease has been identified, and its parameters have been passed in as with BOUND. The client configuration script should test these parameters and, if it has reason to believe they are valid, should exit with a value of zero. If not, it should exit with a nonzero value. The usual way to test a lease is to set up the network as with REBIND (since this may be called to test more than one lease) and then ping the first router defined in $routers. If a response is received, the lease must be valid for the network to which the interface is currently connected. It would be more complete to try to ping all of the routers listed in $new_routers, as well as those listed in $new_static_routes, but current scripts do not do this. FILES Each operating system should generally have its own script file, although the script files for similar operating systems may be similar or even identical. The script files included in Internet Systems Con- sortium DHCP distribution appear in the distribution tree under client/scripts, and bear the names of the operating systems on which they are intended to work. BUGS If more than one interface is being used, there’s no obvious way to avoid clashes between server-supplied configuration parameters - for example, the stock dhclient-script rewrites /etc/resolv.conf. If more than one interface is being configured, /etc/resolv.conf will be repeatedly initialized to the values provided by one server, and then the other. Assuming the information provided by both servers is valid, this shouldn’t cause any real problems, but it could be confus- ing. SEE ALSO dhclient(8), dhcpd(8), dhcrelay(8), dhclient.conf(5) and dhclient.leases(5). AUTHOR dhclient-script(8) has been written for Internet Systems Consortium by Ted Lemon in cooperation with Vixie Enterprises. To learn more about Internet Systems Consortium, see https://www.isc.org. To learn more about Vixie Enterprises, see http://www.vix.com. dhclient-script(8)
Copyright(C) linux-cmd.com All Rights Reserved. Author Takayuki Yukawa