Linux: dhcpd cooking

Para asignar diferentes IPs en funcion de la MAC address y ademas ejecutar un script cuando se asigna o se libera una IP del pool.

#
# Configuration file for ISC dhcpd for Ubuntu 10.04
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...
#option domain-name "XXXXX.es";
#option domain-name-servers 192.168.X.A, 192.168.X.B;
#option routers 192.168.X.Y;

default-lease-time 600;
max-lease-time 7200;

log-facility local7;

#######

authoritative;

class "vmware" {
  match if substring(binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)), 0, 7) = "0:50:56";
}
class "vmtest" {
  match if substring(binary-to-ascii(16, 8, ":", substring(hardware, 1, 6)), 0, 8) = "40:50:60";
}

shared-network internal {
  set myip = binary-to-ascii(10, 8, ".", leased-address);
  set mymac = lcase(concat(
      suffix(concat("0", binary-to-ascii(16, 8, "", substring(hardware, 1, 1))), 2), ":",
      suffix(concat("0", binary-to-ascii(16, 8, "", substring(hardware, 2, 1))), 2), ":",
      suffix(concat("0", binary-to-ascii(16, 8, "", substring(hardware, 3, 1))), 2), ":",
      suffix(concat("0", binary-to-ascii(16, 8, "", substring(hardware, 4, 1))), 2), ":",
      suffix(concat("0", binary-to-ascii(16, 8, "", substring(hardware, 5, 1))), 2), ":",
      suffix(concat("0", binary-to-ascii(16, 8, "", substring(hardware, 6, 1))), 2)
    ));

  # TEST
  #subnet 169.254.0.0 netmask 255.255.0.0 {
  #  pool {
  #    allow members of "vmtest";
  #    range 169.254.169.1 169.254.169.249;
  #  }
  #}

  # NETWORK
  subnet 192.168.X.0 netmask 255.255.255.0 {
    option domain-name "XXXX.es";
    option domain-name-servers 192.168.X.B, 192.168.X.B;
    option routers 192.168.X.Y;
    pool {
      allow members of "vmtest";
      range 192.168.X.119 192.168.X.119;
      option domain-name-servers 192.168.X.A, 192.168.X.B;
      option routers 192.168.X.C;
    }
    pool { # vmware
      allow members of "vmware";
      range 192.168.X.121 192.168.X.129;
    }
    pool { # unknown
      deny members of "vmware";
      deny members of "vmtest";
      range 192.168.X.131 192.168.X.139;
    }
  }

  # Maybe you need modify:
  # /etc/apparmor.d/usr.sbin.dhcpd3
  # + /etc/dhcp3/dhcpd-hooks.d/event.sh Uxr,
  # invoke-rc.d apparmor reload
  # chmod +x /etc/dhcp3/dhcpd-hooks.d/event.sh
  on commit {
    execute("/etc/dhcp3/dhcpd-hooks.d/event.sh", "commit", myip, mymac);
  }
  on release {
    execute("/etc/dhcp3/dhcpd-hooks.d/event.sh", "release", myip, mymac);
  }
  on expiry {
    execute("/etc/dhcp3/dhcpd-hooks.d/event.sh", "expiry", myip, mymac);
  }
}
#
# http://blog.fortytwo.ch/
# http://manpages.ubuntu.com/manpages/lucid/en/man5/dhcp-eval.5.html
#
#!/bin/bash
# File: /etc/dhcp3/dhcpd-hooks.d/event.sh
echo $* >> /tmp/dhcp.log

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: