我如何MAC过滤DHCP服务器

我想只允许某些MAC地址从我的DHCP服务器获得IP,目前我使用dnsmasq,而不是更改DHCP服务器,但我也打开其他软件。 但是,我需要能够为特定的MAC地址设置静态IP地址。

目前我的dnsmasq conf文件有一堆条目,为一系列MAC地址指定静态IP,如下所示:

dhcp-host=00:11:22:33:44:55,192.168.1.100 dhcp-host=00:11:22:33:44:56,192.168.1.101 dhcp-host=00:11:22:33:44:57,192.168.1.102 

有没有一种方法,以便所有的MAC地址不是以上述方式指定不知道IP?

你可以通过只指定一个静态范围来做到这一点

DHCP-范围= 192.168.0.0,静态

编辑:更改上面的地址范围,以满足您的要求。

在没有指定dynamic范围的情况下,dnsmask将只为具有相应dhcp-hostconfiguration的主机提供地址

 # Specify a subnet which can't be used for dynamic address allocation, # is available for hosts with matching --dhcp-host lines. Note that # dhcp-host declarations will be ignored unless there is a dhcp-range # of some type for the subnet in question. # In this case the netmask is implied (it comes from the network # configuration on the machine running dnsmasq) it is possible to give # an explicit netmask instead. #dhcp-range=192.168.0.0,static 

作为@ Chopper3解决scheme的替代scheme,您可以添加像这样的iptables规则

 # Create the DHCP_clients chain in the 'raw' table iptables -t raw -N DHCP_clients # Incoming DHCP, pass to chain processing DHCP iptables -t raw -A PREROUTING -p udp --dport 67 -j DHCP_clients # Allowed DHCP clients iptables -t raw -A DHCP_clients -m mac --mac-source 00:11:22:33:44:55 -j ACCEPT iptables -t raw -A DHCP_clients -m mac --mac-source 00:11:22:33:44:56 -j ACCEPT iptables -t raw -A DHCP_clients -m mac --mac-source 00:11:22:33:44:57 -j ACCEPT # Deny other clients not listed above iptables -t raw -A DHCP_clients -j DROP 

编辑:如果您需要添加额外的“已知”/允许的客户端,只需为每个额外的客户端执行以下操作:

 # We insert a rule at the head of the chain using the '-I' command iptables -t raw -I DHCP_clients -m mac --mac-source $CLIENT_MAC -j ACCEPT 

(注意:它使用-I (插入)而不是-A (追加),所以新规则将成为第一个要检查的规则。如果我们不插入,附加规则将被-j DROP

 # Ignore any clients which are not specified in dhcp-host lines # or /etc/ethers. Equivalent to ISC "deny unknown-clients". # This relies on the special "known" tag which is set when # a host is matched. #dhcp-ignore=tag:!known 

如果您只希望特定MAC获取DHCP地址,则只需创build预留列表,然后将范围设置为仅覆盖那些IP地址。 这样就不会有更多的地址了。

我不得不不同意以前的修复。 除了pepoluan的回答。

虽然我不知道pepoluan是不是一个真正的白名单技术,这是接近正确的答案。 阻止所有数据到错误的mac是你的目标。 只是禁用dhcp非注册的mac是不是一个修复,如果他们设置手动ip的,这通常是3个范围之一… 10.0.0.x,192.168.1.x或192.168.0.x does not回答这个问题。

如果你使用另一个build议的答案,不向未知的mac发送dhcp,同样也要改变你的路由器地址到一个独特的不可猜测的选项,并将你的ip范围改变成一个非常奇怪的。 例如192.168.43.x,路由器是192.168.43.43或其他东西。 这会使他们猜测你的子网范围,并且没有连接到networking。

这不是完美的,但它是一个更好的方式来保护您的networking。