技术解析

在哪查看 dhcp 租约信息 ? 如何让 dnsmasq dhcp 在 192.168.0.1 而非 0:0:0:0 ?
0
2021-06-29 04:49:09
idczone
虚拟机客户端 dhcp,没 google 到这方面的信息

主机在搭建 nas+软路由: 调试配置中 dnsmasq 是在 0:0:0:0 上进行 dhcp 而非 192.168.0.1 上,google 没有什么收获...
https://wiki.debian.org/HowTo/dnsmasq#Choosing_Your_Interfaces

我想说结果一样, dnsmasq dhcp server 还是在 0:0:0:0 上监听
狂且我本就是如此写的 conf 文件

If you want dnsmasq to listen for DHCP and DNS requests only on
specified interfaces (and the loopback) give the name of the
interface (eg eth0) here.
Repeat the line for more than one interface.
/>Or you can specify which interface _not_ to listen on
/>Or which to listen on by address (remember to include 127.0.0.1 if
you use this.)
/>If you want dnsmasq to provide only DNS service on an interface,
configure it as shown above, and then use the following line to
disable DHCP and TFTP on it.
On systems which support it, dnsmasq binds the wildcard address,
even when it is listening on only some interfaces. It then discards
requests that it shouldn't reply to. This has the advantage of
working even when interfaces come and go and change address. If you
want dnsmasq to really bind only the interfaces it is listening on,
uncomment this option. About the only time you may need this is when
running another nameserver on the same machine.
/>都试试?

bind-interfaces
需要写多这一条
dhcp 租约需要加一句
log-dhcp
然后在输出日志上可以 tail 到详细的租约信息(最好注释掉 log-queries )

就是如此才是最恶心的


看我刚回复的
客户机是台虚拟机,配合家庭服务器(nas+软路由)在调试配置
so 我需要查看 dhcp 信息( 租约和续租时间 )

就两条配置就够了啊
log-dhcp
log-facility=/var/log/dnsmasq.log
然后再上面指定的日志文件里面就可以拿到详尽的 dhcp 信息:
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 available DHCP range: 192.168.1.201 -- 192.168.1.232
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 client provides name: iPhone
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 DHCPREQUEST(eth0) 192.168.1.227 44:00:10:a3:87:da
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 tags: eth0
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 DHCPACK(eth0) 192.168.1.227 44:00:10:a3:87:da iPhone
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 requested options: 1:netmask, 121:classless-static-route, 3:router,
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 requested options: 6:dns-server, 15:domain-name, 119:domain-search,
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 requested options: 252
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 next server: 192.168.1.1
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 1 option: 53 message-type 5
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 54 server-identifier 192.168.1.1
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 51 lease-time 2d
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 58 T1 1d
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 59 T2 1d18h
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 1 netmask 255.255.255.0
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 28 broadcast 192.168.1.255
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 6 dns-server 192.168.1.1
Aug 25 09:16:51 dnsmasq-dhcp[6353]: 1819931555 sent size: 4 option: 3 router 192.168.1.1

还有一个你可能用得上的是:
dhcp-leasefile=/var/log/dhcp.leases
这里可以记录到全部客户端的租约信息

DHCP 要接收广播消息,怎么可以限定地址。

DHCP 获取到地址之前客户端本身是没有 IP 地址的。。。先不说能不能限制如果你真做到了把 dnsmasq 限制监听 192.168.0.1 这个段后果就是新设备全部无法获取 IP 地址上不了网除非你手动分配一个这个网段的 IP,不过手动分配的话还要 DHCP 有什么用呢。。。

不如 mac 绑定吧

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服