局域网抓包dhcp查看客户端租期

Table of Contents

[TOC]

背景

20240417发现局域网内的三个主机老是ssh断联,所以就怀疑是否ip地址冲突,ip地址冲突的原因可能是dhcp获取ip地址的时间很短,所以想确定下当前局域网内的dhcp租期。

本方法适用于懒得用Windows主机连接当前局域网查看租期,恰好局域网内有Linux主机的场景。

查看DHCP租期方法

在Linux主机上,使用tcpdump,无法查看租期字段具体值。

命令如下,


pc@vm-ubuntu2204:~$ sudo tcpdump -vvv -tttt -n -c 1 -i ens33 'src 172.17.1.254 and udp port 67'
tcpdump: listening on ens33, link-type EN10MB (Ethernet), snapshot length 262144 bytes
2024-04-20 21:11:33.186161 IP (tos 0x0, ttl 16, id 0, offset 0, flags [none], proto UDP (17), length 328)
    172.17.1.254.67 > 172.17.1.131.68: [udp sum ok] BOOTP/DHCP, Reply, length 300, xid 0xea6e1fb5, Flags [none] (0x0000)
          Client-IP 172.17.1.231
          Your-IP 172.17.1.231
          Server-IP 172.17.1.254
          Client-Ethernet-Address 92:4b:54:29:11:23
          Vendor-rfc1048 Extensions
            Magic Cookie 0x63825363
            DHCP-Message (53), length 1: ACK
            Server-ID (54), length 4: 172.17.1.254
            Lease-Time (51), length 4: 86460
            Subnet-Mask (1), length 4: 255.255.255.0
            Default-Gateway (3), length 4: 172.17.1.254
            Domain-Name-Server (6), length 8: 223.6.6.6,8.8.8.8
            END (255), length 0
            PAD (0), length 0, occurs 22
1 packet captured
5 packets received by filter
0 packets dropped by kernel
pc@vm-ubuntu2204:~$ date
Sat Apr 20 09:46:41 PM CST 2024

其中租期字段是Lease-Time,值是86400,单位秒,也就是一天。