Faybo28 2022-09-30 17:36 采纳率: 33.3%
浏览 57
已结题

怎样批量删除电脑现有的dns地址,并重新添加新的dns

win7电脑现有6个dns地址,这6个地址需要全部删除,同时添加2个新地址,请问批处理指令怎样写

  • 写回答

1条回答 默认 最新

  • 游一游走一走 2022-09-30 17:51
    关注
    @ECHO ON
    netsh interface ipv4 show dns
    SETLOCAL EnableDelayedExpansion
     
    SET adapterName=
     
    FOR /F "tokens=* delims=:" %%a IN ('IPCONFIG ^| FIND /I "以太网适配器"') DO (
    SET adapterName=%%a
    REM Removes "Ethernet adapter" from the front of the adapter name
    SET adapterName=!adapterName:~7!
    REM Removes the colon from the end of the adapter name
    SET adapterName=!adapterName:~0,-1!
    echo %%adapterName
     
    netsh interface ipv4 delete dns name="!adapterName!" all
    netsh interface ipv4 set dns name="!adapterName!" static 223.5.5.5 primary
    netsh interface ipv4 add dns name="!adapterName!" 8.8.8.8 index=2
    )
     
    ipconfig /flushdns
    netsh interface ipv4 show dns
     
    :EOF
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 10月11日
  • 已采纳回答 10月3日
  • 创建了问题 9月30日