DHCP가 범위를 벗어난 경우 쉘 스크립트를 사용하여 어떻게 경고를 보낼 수 있습니까?

DHCP가 범위를 벗어난 경우 쉘 스크립트를 사용하여 어떻게 경고를 보낼 수 있습니까?

CentOS 6.5에 DHCP 서버를 설치하고 구성했습니다. 또한 다음과 같이 파일에 서브넷을 추가했습니다 dhcpd.conf.

subnet 192.168.1.0 netmask 255.255.255.0 {
  option domain-name-servers 192.168.1.2, 8.8.8.8;
  default-lease-time 600;
  max-lease-time 7200;
  range dynamic-bootp 192.168.1.10 192.168.1.30;
  option broadcast-address 192.168.1.255;
  option routers 192.168.1.1;
  option ip-forwarding off;
}

보시다시피 DHCP 서버는 20개의 IP 주소만 할당할 수 있습니다. 쉘 스크립트를 사용하여 20개의 주소가 모두 할당된 후 DHCP 서버가 시스템 관리자에게 경고를 보내도록 할 수 있습니까?

답변1

lease옵션 중 하나는 신고된 수량을 계산하는 것입니다.dhcpd.리스:

dhcpd.leases(5) - Linux man page

Name

dhcpd.leases - DHCP client lease database

....

the Lease Declaration

lease ip-address { statements... }

Each lease declaration includes the single IP address that has been leased to the
client. The statements within the braces define the duration of the lease and to
whom it is assigned.

따라서 다음으로 시작하는 줄 수만 세어보면 lease얼마나 많은 IP 주소가 할당되었는지 알 수 있습니다 .

COUNT=$(grep -c '^lease' /var/lib/dhcpd/dhcpd.leases)

if [[ $COUNT eq 20 ]]
then
    #do something here
fi

답변2

on commit이는 직접적인 해결책은 아니지만 DHCP 구성 파일의 기능을 활용할 수 있는 것 같습니다 . 다음은 이 기사의 예입니다.ISC DHCP가 새 임대를 배포할 때 스크립트 실행.

dhcpd.conf파일에서는 임대가 발행되는 경우와 같은 다양한 이벤트에 대한 작업을 생성할 수 있습니다.

subnet 192.168.1.0 netmask 255.255.255.0 {
    option routers  192.168.1.2;

    on commit {
        set clip = binary-to-ascii(10, 8, ".", leased-address);
        set clhw = binary-to-ascii(16, 8, ":", substring(hardware, 1, 6));
        execute("/usr/local/sbin/dhcpevent", "commit", clip, clhw, host-decl-name);
    }
    ...

위 스크립트 dhcpevent가 실행되면 4개의 매개변수가 전달됩니다.

execute_statement argv[0] = /usr/local/sbin/dhcpevent
execute_statement argv[1] = commit
execute_statement argv[2] = 192.168.1.40
execute_statement argv[3] = 11:aa:bb:cc:dd:ee
execute_statement argv[4] = d1.jp

clipw& clhw는 변수입니다. 이 예에서는 메타데이터의 다른 부분이 스크립트를 실행하기 전에 구문 분석되어 저장됩니다. 그런 다음 이러한 변수는 다른 항목과 함께 이벤트 스크립트에 전달됩니다.

이 방법을 임대된 IP 수를 추적할 수 있는 스크립트로 구현하거나 DHCP 서버에 실제 임대 상태 파일( /var/lib/dhcpd/dhcpd.leases)에서 이 정보를 추적하도록 요청한 다음 파일의 임대 수가 할당량을 초과하는지 보고할 수 있습니다.

인용하다

관련 정보