Joe*_*tar 7 dhcp mac-address dnsmasq
我想只允许某些 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
Run Code Online (Sandbox Code Playgroud)
有没有办法让所有未以上述方式指定的 MAC 地址都不会获得 IP?
pep*_*uan 10
替代@Chopper3 的解决方案,您可以添加这样的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
Run Code Online (Sandbox Code Playgroud)
编辑:如果您需要添加额外的“已知”/允许的客户端,只需为每个额外的客户端执行以下操作:
# 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
Run Code Online (Sandbox Code Playgroud)
(注意:它使用-I
(insert) 而不是-A
(append),因此新规则将是第一个要检查的规则。如果我们不插入,附加的规则将被带有 的规则覆盖-j DROP
)
你可以通过只指定一个静态范围来做到这一点
DHCP 范围=192.168.0.0,静态
编辑:更改上面的地址范围以满足您的要求。
如果没有指定动态范围,dnsmask 只会向具有相应 dhcp-host 配置的主机提供地址
# 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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15452 次 |
最近记录: |