Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Suppose I have a bunch of hosts set up like this:

host host2 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.2; }
host host3 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.3; }
# etc ...   

subnet 192.168.1.0 netmask 255.255.255.0 {
  option subnet-mask 255.255.255.0;
  option broadcast-address 192.168.1.255;
  option routers 192.168.1.254;
  option domain-name-servers 8.8.8.8, 8.8.4.4;

  # Unknown test clients get this pool.
  pool {
    max-lease-time 1800; # 30 minutes
    range 192.168.1.100 192.168.1.250;
    allow unknown-clients;
  }

  # MyHosts nodes get this pool
  pool {
    max-lease-time 1800;
    range 192.168.1.1 192.168.1.20;
    allow members of MyHosts;
    deny unknown-clients;
  }
}

I want to put these into a class and assign them to a pool so that I can ensure that only those hosts are allowed on that pool.

I tried defining them as:

class "MyHosts" {
  host host2 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.2; }
  host host3 { hardware ethernet 10:bf:48:xx:xx:xx; fixed-address 192.168.1.3; }
}

But this gave an error "host declarations not allowed here".

How do I do it?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

As you discovered, you cannot declare hosts inside a class. The class declaration can only contain match or match if statements. If you want to group your client requests into classes using the class construct, you could do it something like this:

class "MyHosts" {
    match hardware;
}
subclass "MyHosts" 1:10:bf:48:xx:xx:xx;  # host2
subclass "MyHosts" 1:10:bf:48:xx:xx:xx;  # host3

In the above, the match statement in the class declares that subclasses will be matched by the hardware attribute. (hardware evaluates to the concatenation of the hardware type and the MAC address of the client; for ethernet clients, the hardware type is 1, thus the 1: prefix in the data string of the subclass statements.)

When a client is a member of a subclass, it is also a member of the parent class, so now you can use allow and deny clauses in your pool declarations to ensure that members of MyHosts are assigned IPs from the desired pool, e.g.:

subnet 192.168.1.0 netmask 255.255.255.0 {
    ...
    pool {
        range 192.168.1.101 192.168.1.250;
        ...
        deny members of "MyHosts";
        ...
    }
    pool {
        range 192.168.1.1 192.168.1.20;
        ...
        allow members of "MyHosts";
        ...
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.