クライアント切断時の DHCPD クリーンリース

クライアント切断時の DHCPD クリーンリース

クライアントが切断された直後に、ISC DHCPD に静的リースの有効期限切れまたは解放を強制的にトリガーさせる方法はありますか?

クライアントが接続した直後 (「コミット時」DHCPD イベント) および切断した直後 (「有効期限切れ時」または「リリース時」DHCPD イベント) にスクリプトをトリガーしたいと考えています。

最初のものはうまく機能しますが、後者はまったくトリガーされません。何かアドバイスはありますか?

編集: 設定スニップレット(テスト スクリプト付き):

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.40 192.168.1.49;

  on commit {
    set ip = binary-to-ascii (10, 8, ".", leased-address);
   execute ("/usr/local/bin/dhcp-test", "commit", ip);
  }
  on release {
    set ip = binary-to-ascii (10, 8, ".", leased-address);
    execute ("/usr/local/bin/dhcp-test", "release", ip);
  }
  on expiry {
    set ip = binary-to-ascii (10, 8, ".", leased-address);
    execute ("/usr/local/bin/dhcp-test", "expiry", ip);
  }
}

答え1

私が正しく理解していれば、静的リースを作成するには、構成に次のような内容を含める必要があります。

host static-1 {
    hardware ethernet 00:01:02:03:04:05;
    fixed-address 192.168.1.40;
}

これは期待どおりに動作しますが、この IP アドレスは解放されません (クライアントが DHCPRELEASE を送信するかどうかは関係ありません) - これは dhcpd の観点からは静的 IP であるためです。

動的 IP を作成する必要があります (これも dhcpd の観点から)。そうすれば、dhcpd はそれを追跡します。次のように実行できます。

# First create pseudo class
class "static-ip" { match suffix(hardware, 6); }

# Here you will declare all MAC of your clients and make it a subclass of "static-ip"
# class "<UNIQ-CLASSNAME>" { match if suffix(hardware, 6) = <CLIENT-MAC-ADDRESS>; } subclass "static-ip" <CLIENT-MAC-ADDRESS>;
# Example
class "static-1" { match if suffix(hardware, 6) = 00:01:02:03:04:05; } subclass "static-ip" 00:01:02:03:04:05;

# Next allocate an address for every client (inside subnet declaration):

subnet 192.168.1.0 netmask 255.255.255.0 {
  on commit {
    set ip = binary-to-ascii (10, 8, ".", leased-address);
   execute ("/usr/local/bin/dhcp-test", "commit", ip);
  }
  on release {
    set ip = binary-to-ascii (10, 8, ".", leased-address);
    execute ("/usr/local/bin/dhcp-test", "release", ip);
  }
  on expiry {
    set ip = binary-to-ascii (10, 8, ".", leased-address);
    execute ("/usr/local/bin/dhcp-test", "expiry", ip);
  }

 # pool { range <ip-addr>; allow members of "<UNIQ-CLASSNAME>"; }
   pool { range 192.168.1.40; allow members of "static-1"; }
 # pool { range 192.168.1.41; allow members of "static-2"; }
 #... so on
}

設定をより柔軟にするために、クラスサブクラスとプール範囲の宣言を別のファイルに入れて、含むメインのdhcpd.confに

#dhcpd.conf
authoritative;
min-lease-time ...;
... etc.

include "/path/to/classes.conf";
include "/path/to/subnet.conf";

ご覧のとおり、すべてのクライアントを独自のクラスに配置し、それを「static-ip」クラスにサブクラス化しました。これは、静的 IP 割り当てのない別のサブネットが必要な場合に使用します。例:

subnet 192.168.2.0 netmask 255.255.255.0 {
 range 192.168.2.10 192.168.2.100;
 deny members of "static-ip";
}

次に、静的IP割り当てを持つクライアントがこのサブネットからIPを取得することを拒否する必要があります(拒否キーワード)。

この方法では、動的 IP を取得します (dhcpd の観点から)。ただし、実際には変更されることはありません (クライアントの観点から)。

答え2

DHCP は通常、後で再接続するクライアントに同じリースを再発行するために、リースを有効期限まで保持します。新しいクライアントからスコープに圧力がかかった場合にのみ、候補を解放し始めます。

これにより、クライアントはセッション間の間隔をあまり長くせずに再度接続したときに同じアドレスを再取得でき、ほぼ静的なアドレス指定のように見えます。

タイマーが切れるまでスクリプトが(設計上)実行されない可能性があります。スコープ内の競合を増やすか、タイマーの持続時間を短縮してプロセスを迅速化することで、これを強制することができます。

答え3

@TomTom のおかげで、RFC2131 をさらに詳しく調べて、静的リースのこの動作を確認できました。

...DHCP supports three mechanisms for IP address allocation.  In
"automatic allocation", DHCP assigns a permanent IP address to a
client.  In "dynamic allocation", DHCP assigns an IP address to a
client for a limited period of time (or until the client explicitly
relinquishes the address).  In "manual allocation", a client's IP
address is assigned by the network administrator, and DHCP is used
simply to convey the assigned address to the client. 

    Dynamic allocation is the only one of the three mechanisms that
allows automatic reuse of an address that is no longer needed by the
client to which it was assigned...

以前に見つけられなかった理由は「静的リース「と呼ばれる」永続RFC 内の " と Ctrl+F には AI が組み込まれていません (残念ながら)

そのため、ネットワークから切断されたクライアントを処理するための実用的な方法をまだ模索しています。

関連情報