V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
station
V2EX  ›  Linux

在哪查看 dhcp 租约信息 ? 如何让 dnsmasq dhcp 在 192.168.0.1 而非 0:0:0:0 ?

  •  
  •   station · 2017-08-25 07:23:10 +08:00 · 5875 次点击
    这是一个创建于 2647 天前的主题,其中的信息可能已经有所发展或是发生改变。
    虚拟机客户端 dhcp,没 google 到这方面的信息

    主机在搭建 nas+软路由: 调试配置中 dnsmasq 是在 0:0:0:0 上进行 dhcp 而非 192.168.0.1 上,google 没有什么收获...
    11 条回复    2017-08-25 15:49:59 +08:00
    exkernel
        1
    exkernel  
       2017-08-25 07:49:56 +08:00 via iPhone
    station
        2
    station  
    OP
       2017-08-25 08:43:07 +08:00
    @exkernel 我想说结果一样, dnsmasq dhcp server 还是在 0:0:0:0 上监听

    狂且我本就是如此写的 conf 文件
    xfspace
        3
    xfspace  
       2017-08-25 08:59:11 +08:00 via Android
    # 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.
    #interface=
    # Or you can specify which interface _not_ to listen on
    #except-interface=
    # Or which to listen on by address (remember to include 127.0.0.1 if
    # you use this.)
    #listen-address=
    # 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.
    #no-dhcp-interface=

    # 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


    都试试?
    predator
        4
    predator  
       2017-08-25 09:02:31 +08:00
    bind-interfaces
    需要写多这一条

    dhcp 租约需要加一句
    log-dhcp
    然后在输出日志上可以 tail 到详细的租约信息(最好注释掉 log-queries )
    station
        5
    station  
    OP
       2017-08-25 09:07:14 +08:00
    @xfspace 就是如此才是最恶心的
    station
        6
    station  
    OP
       2017-08-25 09:11:05 +08:00
    @predator 看我刚回复的

    客户机是台虚拟机,配合家庭服务器(nas+软路由)在调试配置
    so 我需要查看 dhcp 信息( 租约和续租时间 )
    predator
        7
    predator  
       2017-08-25 09:21:32 +08:00
    就两条配置就够了啊

    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
    predator
        8
    predator  
       2017-08-25 09:25:30 +08:00
    还有一个你可能用得上的是:

    dhcp-leasefile=/var/log/dhcp.leases

    这里可以记录到全部客户端的租约信息
    jasontse
        9
    jasontse  
       2017-08-25 09:25:41 +08:00 via Android
    DHCP 要接收广播消息,怎么可以限定地址。
    lazycat
        10
    lazycat  
       2017-08-25 09:33:36 +08:00
    DHCP 获取到地址之前客户端本身是没有 IP 地址的。。。先不说能不能限制如果你真做到了把 dnsmasq 限制监听 192.168.0.1 这个段后果就是新设备全部无法获取 IP 地址上不了网除非你手动分配一个这个网段的 IP,不过手动分配的话还要 DHCP 有什么用呢。。。
    lybtongji
        11
    lybtongji  
       2017-08-25 15:49:59 +08:00
    不如 mac 绑定吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1560 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:14 · PVG 01:14 · LAX 09:14 · JFK 12:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.