当前位置:首页 >> 脚本专栏

用注册表更改DNS的代码分享

最进我这里DNS老是间歇性掉,很不稳定,广州地区,如果你的DNS经常需要更换,试试这个批处理,

论坛很多人发过了更改DNS的批处理,但改的过程批处理等待有点缓慢,还有的同志的本地连接有2到N位的,改时很不方便.

批处理内容:

复制代码 代码如下:
echo off
regedit /s \\\\server\\xx\\xx.reg
cls

\\\\server\\xx\\xx.reg为你的远程路劲.,不要用我的,只需修改红色部分为你的远程路劲,

下面是DNS的注册表项,我的是2000,

复制代码 代码如下:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters\\Interfaces\\{B130BF2A-0BD5-4B4D-B3A9-55A94FC46694}]
"UseZeroBroadcast"=dword:00000000
"EnableDeadGWDetect"=dword:00000001
"EnableDHCP"=dword:00000000
"IPAddress"=hex(7):31,00,39,00,32,00,2e,00,31,00,36,00,38,00,2e,00,32,00,2e,00,  32,00,30,00,31,00,00,00,00,00
"SubnetMask"=hex(7):32,00,35,00,35,00,2e,00,32,00,35,00,35,00,2e,00,32,00,35,  00,35,00,2e,00,30,00,00,00,00,00
"DefaultGateway"=hex(7):31,00,39,00,32,00,2e,00,31,00,36,00,38,00,2e,00,32,00,  2e,00,32,00,35,00,34,00,00,00,00,00
"DefaultGatewayMetric"=hex(7):31,00,00,00,00,00
"NameServer"="202.96.128.166,61.144.56.100"
"Domain"=""
"DisableDynamicUpdate"=dword:00000000
"EnableAdapterDomainNameRegistration"=dword:00000000
"InterfaceMetric"=dword:00000001
"TCPAllowedPorts"=hex(7):30,00,00,00,00,00
"UDPAllowedPorts"=hex(7):30,00,00,00,00,00
"RawIPAllowedProtocols"=hex(7):30,00,00,00,00,00
"NTEContextList"=hex(7):30,00,78,00,30,00,30,00,30,00,30,00,30,00,30,00,30,00,  32,00,00,00,00,00
"DhcpClassIdBin"=hex:
"DhcpServer"="255.255.255.255"
"Lease"=dword:00000e10
"LeaseObtainedTime"=dword:45090a44
"T1"=dword:4509114c
"T2"=dword:45091692
"LeaseTerminatesTime"=dword:45091854
"IPAutoconfigurationAddress"="0.0.0.0"
"IPAutoconfigurationMask"="255.255.0.0"
"IPAutoconfigurationSeed"=dword:92437cc6
"AddressType"=dword:00000000

保存REG然后放到你的服务器远程共享目录里,只需要修改上面红色字体的DNS为你自己的DNS.

如有人不知道怎么远程执行,举个列子,

比如我服务器名是sever,在服务器上建立的共享名是xx$ $表示隐藏,你可加也可以不加,

我把上面的注册表项保存为a.reg,那我就把这个a.reg注册表放到xx$的共享目录里,

那批处理就这样写:

复制代码 代码如下:
echo off
regedit /s \\\\server\\xx$\\a.reg
cls

保存bat,把这个批处理丢到启动项就可以了,开机运行,1秒就改完了,及时生效,无需缓慢的等待!