假设我有一堆这样设置的主机:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
我想将它们放入一个类中并将它们分配给一个池,以便我可以确保该池中只允许那些主机。
我尝试将它们定义为:
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; }
}
Run Code Online (Sandbox Code Playgroud)
但这给出了一个错误“此处不允许主机声明”。
我该怎么做?
Ste*_*day 11
正如您所发现的,您不能host在 a 中声明s class。该class声明只能包含match或match if语句。如果您想使用该class构造将客户端请求分组到类中,您可以这样做:
class "MyHosts" {
match hardware;
}
subclass "MyHosts" 1:10:bf:48:xx:xx:xx; # host2
subclass "MyHosts" 1:10:bf:48:xx:xx:xx; # host3
Run Code Online (Sandbox Code Playgroud)
在上面的match语句中,class声明子类将通过hardware属性进行匹配。(hardware计算硬件类型和客户端 MAC 地址的串联;对于以太网客户端,硬件类型为 1,因此1:是subclass语句数据字符串中的前缀。)
当客户端是子类的成员时,它也是父类的成员,因此现在您可以在声明中使用allowanddeny子句pool来确保为 的成员MyHosts分配了来自所需池的 IP,例如:
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";
...
}
}
Run Code Online (Sandbox Code Playgroud)