Loading... 在Windows7Windows10使用命令更改IP地址DNS服务DHCP服务遇到这个问题的前提是我们公司新版本的内网访问工具总是莫名其妙的修改DNS地址,把公网dns改成内部的dns地址,总是需要去给办公人员修改,要不然就上不了外网。所以干脆做一个批处理命令,让他们自行设置,目前电脑系统主要有windows7和windows10,两种设置有一些区别。 <h1>1、首先确认网卡名称</h1> 作为公司的网络管理员,首先你大概要知道公司设备的本地连接名称,我下方截图的是windows7系统的默认基本都是“本地连接”,这边windows10系统的都是“以太网”,你可以看下你们自己公司的,记住这个名称。以下所有操作请右键使用管理权限操作:  <h1>2、关于windows10系统相关命令分析</h1> 知道以上连接名称的话,win10系统以“以太网”给大家分析以下命令 禁用当前网卡: <pre class="corepress-code-pre"><code>netsh interface set interface name="以太网" admin=DISABLE</code></pre> 开启当前网卡: <pre class="corepress-code-pre"><code>netsh interface set interface name="以太网" admin=ENABLE</code></pre> 调整当前网卡为DHCP动态获取ip地址: <pre class="corepress-code-pre"><code>netsh interface ip set address name="以太网" source=dhcp</code></pre> 调整当前网卡为固定ip地址: <pre class="corepress-code-pre"><code>netsh interface ip set address name="以太网" source=static addr=10.10.10.100 mask=255.255.255.0 gateway=10.10.10.1</code></pre> 以上IP地址、掩码、网关请根据实际内网地址填写。 调整当前网卡为DNS动态获取地址: <pre class="corepress-code-pre"><code>netsh interface ip set dns name="以太网" source=dhcp</code></pre> 调整当前网卡为DNS地址为固定地址: 主DNS地址,或者默认DNS地址 <pre class="corepress-code-pre"><code>netsh interface ip set dns name="以太网" source=static addr=223.5.5.5 register=primary</code></pre> 备用DNS地址设置: <pre class="corepress-code-pre"><code>netsh interface ip add dns name="以太网" addr=8.8.8.8 index=2</code></pre> 以上是相关命令的使用方法,关于我是如何挑选好的DNS,会在下面给给各位写出来。 以下是我根据我单位的情况写的批处理命令,我主要是希望设置固定的DNS地址: <pre class="corepress-code-pre"><code>echo off echo ------------------------------------------------------------------------------- echo 一键设置DHCP服务,固定DNS批处理命令,代码只对win10系统生效。请右键使用管理员运行 echo ------------------------------------------------------------------------------- echo 命令即将运行 echo 等待执行禁用本地连接 ping -n 3 127.0.0.1>nul echo 禁用本地连接 netsh interface set interface name="以太网" admin=DISABLE echo 等待执行开启本地连接 ping -n 5 127.0.0.1>nul echo 开启本地连接 netsh interface set interface name="以太网" admin=ENABLE echo 等待重启完成 echo 网卡重启操作完成 ping -n 10 127.0.0.1>nul echo 网卡刷新中 echo 网卡设置成自动获取 netsh interface ip set address name="以太网" source=dhcp echo 网卡自动获取完毕 echo 等待设置DNS地址 ping -n 5 127.0.0.1>nul echo DNS设置223.5.5.5/114.114.114.114 netsh interface ip set dns name="以太网" source=static addr=223.5.5.5 register=primary netsh interface ip add dns name="以太网" addr=114.114.114.114 index=2 echo 新的DNS设置成功! echo 等待测试网络连接 ping -n 5 127.0.0.1>nul echo 测试DNS设置情况,如果显示“来自 某个ip地址 的回复: 字节=32 时间=22ms TTL=52”,则网络DNS恢复正常,显示超时请联系IT人员 ping www.baidu.com -n 10 pause</code></pre> <h1>3、关于windows7系统相关命令分析</h1> 知道以上连接名称的话,win7系统以“本地连接”给大家分析以下命令 禁用当前网卡: <pre class="corepress-code-pre"><code>netsh interface set interface 本地连接 disabled</code></pre> 开启当前网卡: <pre class="corepress-code-pre"><code>netsh interface set interface 本地连接 enabled</code></pre> 调整当前网卡为DHCP动态获取ip地址: <pre class="corepress-code-pre"><code>netsh interface ip set address name="本地连接" source=dhcp</code></pre> 调整当前网卡为固定ip地址: <pre class="corepress-code-pre"><code>netsh interface ip set address "本地连接" static 10.10.10.100 255.255.255.0 10.10.10.1</code></pre> 以上IP地址、掩码、网关请根据实际内网地址填写。 调整当前网卡为DNS动态获取地址: <pre class="corepress-code-pre"><code>netsh interface ip set dns "本地连接" dhcp</code></pre> 调整当前网卡为DNS地址为固定地址: <pre class="corepress-code-pre"><code>netsh interface ip set dns "本地连接" source=static addr=223.5.5.5</code></pre> 以下是我根据我单位的情况写的批处理命令,我主要是希望设置固定的DNS地址: <pre class="corepress-code-pre"><code>echo off echo ------------------------------------------------------------------------------- echo 一键设置DHCP服务,固定DNS批处理命令,代码只对win7系统生效。请右键使用管理员运行 echo ------------------------------------------------------------------------------- echo 命令即将运行 echo 等待执行禁用本地连接 ping -n 3 127.0.0.1>nul echo 禁用本地连接 netsh interface set interface 本地连接 disabled echo 等待执行开启本地连接 ping -n 5 127.0.0.1>nul echo 开启本地连接 netsh interface set interface 本地连接 enabled echo 等待重启完成 ping -n 5 127.0.0.1>nul echo 网卡重启操作完成 ping -n 5 127.0.0.1>nul echo 网卡设置成自动获取 netsh interface ip set address name="本地连接" source=dhcp echo 网卡自动获取完毕 echo 等待设置DNS地址 ping -n 5 127.0.0.1>nul echo DNS设置223.5.5.5 netsh interface ip set dns "本地连接" source=static addr=223.5.5.5 echo 新的DNS设置成功! echo 等待测试网络连接 ping -n 5 127.0.0.1>nul echo 测试DNS设置情况,如果显示“来自 某个ip地址 的回复: 字节=32 时间=22ms TTL=52”,则网络DNS恢复正常,显示超时请联系IT人员 ping www.baidu.com -n 10 pause</code></pre> <h1> 4、关于如何挑选好的DNS地址</h1> 目前主流的DNS地址有以下这些: <table border="0" cellpadding="0" cellspacing="0" width="463" height="247" style="border-collapse: collapse; width: 347.27pt;"> <tbody> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">名称</td> <td colspan="2" class="et2" width="294" x:str="" style="width: 220.50pt;">DNS 服务器 IP 地址</td> </tr> <tr height="38" style="height: 28.50pt;"> <td class="et2" height="38" width="169" x:str="" style="height: 28.50pt; width: 126.75pt;">114 DNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">114.114.114.114</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">114.114.115.115</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">阿里AliDNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">223.5.5.5</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">223.6.6.6</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">百度 BaiduDNS</td> <td colspan="2" class="et2" width="294" x:str="" style="width: 220.50pt;">180.76.76.76</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et3" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">DNSPod DNS+</td> <td class="et3" width="148" x:str="" style="width: 111.00pt;">119.29.29.29</td> <td class="et3" width="146" x:str="" style="width: 109.50pt;">119.29.29.29</td> </tr> <tr height="38" style="height: 28.50pt;"> <td class="et2" height="38" width="169" x:str="" style="height: 28.50pt; width: 126.75pt;">CNNIC SDNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">1.2.4.8</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">210.2.4.8</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">oneDNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">117.50.11.11</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">52.80.66.66</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et4" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">DNS 派</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">101.226.4.6</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">218.30.118.6</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">Google DNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">8.8.8.8</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">8.8.4.4</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">OpenDNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">208.67.222.222</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">208.67.220.220</td> </tr> <tr height="19" style="height: 14.25pt;"> <td class="et2" height="19" width="169" x:str="" style="height: 14.25pt; width: 126.75pt;">V2EX DNS</td> <td class="et2" width="148" x:str="" style="width: 111.00pt;">199.91.73.222</td> <td class="et2" width="146" x:str="" style="width: 109.50pt;">178.79.131.110</td> </tr> </tbody> </table> 可能还有其它更好的DNS地址,我这边就暂时查到这些。因为每个地方的DNS解析的速度不同,我这边建议,直接使用ping命令,ping以上的DNS服务器地址,延迟越低越好,其实国内都差不多,我这边主要用的就是阿里和114的,国际建议使用Google DNS,解析速度会好一点,也可以在互联网上使用工具分析你所在网络使用那个好一点。 版权声明 ▶ 本网站名称:网友小宋 ▶ 本文链接:https://www.xyzbz.cn/archives/468/ ▶ 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行核实删除。 ▶ 转载本站文章需要遵守:商业转载请联系站长,非商业转载请注明出处!! 最后修改:2022 年 10 月 05 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏