首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用DHCP服务器进行MAC过滤器?

如何使用DHCP服务器进行MAC过滤器?
EN

Server Fault用户
提问于 2011-08-18 08:31:03
回答 5查看 17.7K关注 0票数 7

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

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

代码语言:javascript
运行
复制
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?

EN

回答 5

Server Fault用户

回答已采纳

发布于 2011-08-18 09:29:17

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

dhcp-范围=192.168.0.0,静态

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

如果没有指定的动态范围,dnsmask将只向具有相应dhcp主机配置的主机提供地址。

代码语言:javascript
运行
复制
# 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
票数 7
EN

Server Fault用户

发布于 2011-08-18 09:00:54

或者,对于@Chopper3 3 's解决方案,您可以添加如下的iptables规则

代码语言:javascript
运行
复制
# 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

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

代码语言:javascript
运行
复制
# 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 (insert)而不是-A (追加),因此新规则将是要检查的第一个规则。如果不插入,附加的规则将被带有-j DROP的规则覆盖)

票数 10
EN

Server Fault用户

发布于 2013-04-09 13:54:28

代码语言:javascript
运行
复制
# 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
票数 4
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/302445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档