配置静态IP后多出个169.254段的IP

配置好静态ip后出现如下状况

物理地址. . . . . . . . . . . . . : 00-22-64-55-76-8F
DHCP 已启用 . . . . . . . . . . . : 否
自动配置已启用. . . . . . . . . . : 是
自动配置 IPv4 地址 . . . . . . . : 169.254.1.193(首选)
子网掩码 . . . . . . . . . . . . : 255.255.0.0
IPv4 地址 . . . . . . . . . . . . : 192.168.1.123(复制)
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.1.1
TCPIP 上的 NetBIOS . . . . . . . : 已启用

原因–APIPA

Automatic Private IP Addressing (APIPA) is a DHCP fail-safe that protects a computer system from failure by invoking a standby mechanism for local Internet Protocol version 4 (IPv4) networks supported by Microsoft Windows. With APIPA, DHCP clients can obtain IP addresses even when DHCP servers are not functional. APIPA exists in all modern versions of Windows, including Windows 10.
How APIPA Works
Networks that are set up for dynamic addressing rely on a DHCP server to manage the pool of available local IP addresses. When a Windows client device attempts to join the local network, it contacts the DHCP server to request its IP address. If the DHCP server stops functioning, a network glitch interferes with the request, or some issue occurs on the Windows device, this process can fail.
When the DHCP process fails, Windows automatically assigns an IP address from the private range, which is 169.254.0.1 to 169.254.255.254. Using Address Resolution Protocol (ARP), clients verify that the chosen APIPA address is unique on the network before they use it . Clients then check back with the DHCP server at periodic intervals—usually every five minutes—and update their addresses automatically when the DHCP server is able to service requests.
When you start a computer running Windows Vista, for example, it waits for only six seconds for a DHCP server before using an IP from the APIPA range. Earlier versions of Windows look for a DHCP server for as long as three minutes.
All APIPA devices use the default network mask 255.255.0.0, and all reside on the same subnet.
APIPA is enabled by default in Windows whenever the PC network interface is configured for DHCP. This option is called autoconfiguration in Windows utilities such as ipconfig. A computer administrator can disable the feature by editing the Windows Registry and setting the following key value to 0:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/TcpipParameters/IPAutoconfigurationEnabled
Network administrators and experienced computer users recognize that failures in the DHCP process indicate network troubleshooting is needed to identify and resolve the issues that are preventing DHCP from working properly.

原因:
1.无论你的网卡是否设置为DHCP,APIPA都默认开启,当自动获取IP无法得到dhcp服务器的回应,会给它自动分配一个在169.254.0.1到169.254.255.254间的地址,防止网络冲突。(DHCP获取失败后,同样要发送ARP请求查看冲突,此时发送ip为0)
2. 即使手动设置了ip,任何接入网络的网卡接口首先会发送一个自身IP的ARP询问请求,确认网络中没有相同IP,保正IP唯一性,如果收不到arp回应则ok,如果收到有相同IP,则报IP冲突并自动分配一个IP.(此时发送的arp请求中发送ip和请求ip相同)

如何解决

如上所说临时解决可关闭此功能

  1. 打开注册表regedit
  2. 编辑项目,若未找到则新建选择 DWORD 值
    HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/TcpipParameters/IPAutoconfigurationEnabled
  3. 设置该值为0,退出
  4. 网卡禁用重启生效

解决

1 . 查找是否有相同IP
2. 抓包看是否arp询问请求回应是否正确

模拟arp回应

    struct ethernet_arp_packet *const parph = (struct ethernet_arp_packet *)pbuf;
    if(ntohs(parph->arp.hdr.ar_hrd)==ARPHRD_ETHER \
            && ntohs(parph->arp.hdr.ar_pro)==ETH_P_IP\
            && ntohs(parph->arp.hdr.ar_op)==ARPOP_REQUEST)
    {
        if(parph->arp.hdr.ar_hln==6&&parph->arp.hdr.ar_pln==IPVERSION)//ipv4
        {
            unsigned int ipval = *((unsigned int*)parph->arp.ip_sender);
            //ip_sender==0:dhcp arp, ip_sender==ip_target:ask whether there`s a same ip in network?
            if(0==ipval||0==memcmp(parph->arp.ip_sender,parph->arp.ip_target,4))
                return;
            arp_reply(ETH_NAME,rsk.h_src,parph->arp.mac_sender\
                      ,rsk.h_src,parph->arp.ip_target\
                      ,parph->arp.mac_sender,parph->arp.ip_sender);
        }
    }

linux

zeroconf
connman

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值