클라이언트 연결 끊김 시 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이기 때문입니다.

dhcpd의 관점에서 동적 IP를 생성해야 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 할당이 있는 클라이언트를 거부해야 합니다(부인하다예어).

이렇게 하면 dhcpd의 관점에서 동적 IP를 얻을 수 있지만 실제로는 (클라이언트의 관점에서) 결코 변경되지 않습니다.

답변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가 내장되어 있지 않습니다(안타깝게도).

그래서 저는 여전히 네트워크 연결이 끊어진 클라이언트를 처리할 수 있는 방법을 찾고 있습니다.

관련 정보