bat文件设置dns服务器,.bat文件设置IP、DNS
這幾天遇到個煩心事,每次開機之后都要去手動去設(shè)置一下IP地址,一大串的數(shù)字還是有點麻煩,于是就想寫個批處理文件設(shè)置IP
注意:在DOS下設(shè)置IP時需要管理員權(quán)限運行
1.查看機子設(shè)置IP需要用到的名字
名字是Ethernet
2.查看機子在DOS下設(shè)置IP和DNS命令的格式
C:\Windows\system32>netsh
netsh>interface
In future versions of Windows, Microsoft might remove the Netsh functionality
for TCP/IP.
Microsoft recommends that you transition to Windows PowerShell if you currently
use netsh to configure and manage TCP/IP.
Type Get-Command -Module NetTCPIP at the Windows PowerShell prompt to view
a list of commands to manage TCP/IP.
Visit http://go.microsoft.com/fwlink/?LinkId=217627 for additional information
about PowerShell commands for TCP/IP.
netsh interface>ip
netsh interface ipv4>set address
One or more essential parameters were not entered.
Verify the required parameters, and reenter them.
The syntax supplied for this command is not valid. Check help for the correct syntax.
Usage: set address [name=]
[[source=]dhcp|static]
[[address=][/] [[mask=]]
[[gateway=]|none [gwmetric=]]
[[type=]unicast|anycast]
[[subinterface=]]
[[store=]active|persistent]
Parameters:
Tag Value
name - Interface name or index.
source - One of the following values:
dhcp: Enables DHCP for configuring IP addresses for
the specified interface.
static: Disables DHCP for configuring IP addresses for
the specified interface. This value must be
specified if an address or a gateway is being
configured.
address - IPv4 address to add or modify, optionally followed by
the subnet prefix length.
mask - The IP subnet mask for the specified IP address.
gateway - One of the following values:
: A specific default gateway for the
static IP address you are setting.
none: No default gateways are set. This is the default.
gwmetric - The metric for the default gateway. This field should
be set only if gateway is specified.
type - One of the following values:
unicast: Marks the address as a unicast address.
This is the default.
anycast: Marks the address as an anycast address.
subinterface - LUID of the subinterface on which the default gateway
exists. This parameter is only needed on interfaces
with multiple subinterfaces.
store - One of the following values:
active: Set only lasts until next boot.
persistent: Set is persistent. This is the default.
Remarks: Used to enable or disable DHCP for IP address configuration.
Also removes any previous static IP addresses and default gateways,
and can add a new static IP address and default gateway.
Examples:
set address name="Wired Ethernet Connection" source=dhcp
set address "Wired Ethernet Connection" static 10.0.0.9 255.0.0.0 10.0.0.1 1
netsh interface ipv4>set dns
One or more essential parameters were not entered.
Verify the required parameters, and reenter them.
The syntax supplied for this command is not valid. Check help for the correct syntax.
Usage: set dnsservers [name=] [source=]dhcp|static
[[address=]|none]
[[register=]none|primary|both]
[[validate=]yes|no]
Parameters:
Tag Value
name - The name or index of the interface.
source - One of the following values:
dhcp: Sets DHCP as the source for configuring DNS
servers for the specific interface.
static: Sets the source for configuring DNS servers
to local static configuration.
address - One of the following values:
: An IP address for a DNS server.
none: Clears the list of DNS servers.
register - One of the following values:
none: Disables Dynamic DNS registration.
primary: Register under the primary DNS suffix only.
both: Register under both the primary DNS suffix, as
well as under the connection-specific suffix.
validate - Specifies whether validation of the DNS server setting
will be performed. The value is yes by default.
Remarks: Sets DNS server configuration to either DHCP or static mode. Only
when source is 'static', is the 'addr' option also available for
configuring a static list of DNS server IP addresses for the
specified interface. If Validate switch is yes, then
the newly set DNS server is validated.
Examples:
set dnsservers name="Wired Ethernet Connection" source=dhcp
set dnsservers "Wired Ethernet Connection" static 10.0.0.1 primary
netsh interface ipv4>
格式分別是
set address name="Wired Ethernet Connection" source=dhcp ?(自動獲取IP)
set address "Wired Ethernet Connection" static 10.0.0.9 255.0.0.0 10.0.0.1 1 (靜態(tài)設(shè)置)
set dnsservers name="Wired Ethernet Connection" source=dhcp (自動獲取DNS)
set dnsservers "Wired Ethernet Connection" static 10.0.0.1 primary (靜態(tài)設(shè)置)
3.寫批處理文件
在家里時自動分配IP
HOME.bat
netsh interface ip set address "Ethernet" source=dhcp
netsh interface ip set dns "Ethernet" source=dhcp
上班時
WORK.bat
netsh
netsh interface ip set dnsservers "Ethernet" static 202.103.44.151
4.管理員權(quán)限運行
修改后的IP和DNS
有了這兩個文件之后就不用手動配啦
bat文件設(shè)置ip自動和靜態(tài)ip切換
下載地址:https://i.cnblogs.com/Files.aspx win10系統(tǒng): @echo off cd /d %~dp0 %1 start "" mshta vbs ...
PC問題-使用BAT方法設(shè)置IP地址
::------以下為批處理文件內(nèi)容---- @echo off ::set slection1= set/p slection1=請輸入IP地址: netsh interface ip set ad ...
BAT-使用BAT方法設(shè)置IP地址
::------以下為批處理文件內(nèi)容---- @echo off ::set slection1= set/p slection1=請輸入IP地址: netsh interface ip set ad ...
bat文件設(shè)置環(huán)境變量
::獲取管理員權(quán)限 @echo off%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute(" ...
bat文件設(shè)置環(huán)境變量腳本
:: 獲取管理員權(quán)限 @echo off % mshta vbscript:CreateObject()(window.close)&&exit cd /d "%~dp0&q ...
做一個自動修改本機IP和mac的bat文件
原文:做一個自動修改本機IP和mac的bat文件 1.ip bat修改理論探討 前兩天我突然萌生了一個念頭:能不能做一個小程序來實現(xiàn)自動配置或修改IP和mac,達到一鍵搞定的目的,這樣尤其適合那些帶著 ...
windows命令行設(shè)置IP與DNS
用dos命令修改IP等本地連接屬性 平時我們改IP通常都在是窗口界面本地連接直接修改, 那在命令行也可以設(shè)置IP地址?當(dāng)然可以,這里要用到netsh命令 .點擊“開始”->“運行”,輸入“cmd ...
批處理文件設(shè)置IP以及DNS
先附上批處理文件代碼(批處理文件怎么創(chuàng)建自己另行百度,這里不再贅述) Echo offecho ==============請輸入序號修改辦公區(qū)===========echo *********1.家 ...
windows自動修改ip的bat文件
@echo off title --IP自動設(shè)置 -- MODE con: COLS=80 lines=30 color 0a :main cls echo 按提示操作 echo. echo 設(shè)置為無 ...
隨機推薦
JavaScript、全選反選-課堂筆記
class.forname()用法 轉(zhuǎn)
主要功能 Class.forName(xxx.xx.xx)返回的是一個類 Class.forName(xxx.xx.xx)的作用是要求JVM查找并加載指定的類, 也就是說JVM會執(zhí)行該類的靜態(tài)代碼段 ...
解讀Python發(fā)送郵件
解讀Python發(fā)送郵件 Python發(fā)送郵件需要smtplib和email兩個模塊.也正是由于我們在實際工作中可以導(dǎo)入這些模塊,才使得處理工作中的任務(wù)變得更加的簡單.今天,就來好好學(xué)習(xí)一下使用Pyt ...
js工具類 ----正則
function(value){??if(value){???var reg=new RegExp("^[a-zA-Z0-9_-]+$");???return reg.test(v ...
HTTP Status 404(The requested resource is not available)的幾種解決方法
原因:servlet沒有配置正確?,查看web.xml確認正確,以及自己的請求路徑正確 在IE中提示“404”錯誤有以下三種情況 1.未部署Web應(yīng)用 2.URL輸入錯誤 排錯方法: 首先,查看URL ...
2014.8.3情人節(jié)歡樂賽【Benny的農(nóng)場】
Benny的農(nóng)場 (farm.pas/.c/.cpp) 時間限制:1s.空間限制:128MB 題目描述: Benny有一片農(nóng)田需要灌溉.農(nóng)田的形狀為矩形,并被分為許多小塊.每一塊中都有一些水管.共有1 ...
luogu 1026 統(tǒng)計單詞個數(shù)
此題 字符串匹配+dp 確實我的kmp,哈希需要練一練了,忘干凈可咋辦 補救用下string,十分方便 e.g: 1.詢問a[i]是否是x子串,可以截取并判斷前綴 x為截取串?x.find(a[i]) ...
什么是Base64算法?什么情況下用Base64算法?
base64 編碼的本質(zhì):將 8bit 二進制數(shù)轉(zhuǎn)化為 6bit 的可打印字符. Base64編碼用于需要將二進制數(shù)據(jù)轉(zhuǎn)為文本數(shù)據(jù)進行儲存和傳輸?shù)膱鼍? Javascript內(nèi)部的字符串,都以utf- ...
selenium學(xué)習(xí)筆記(webdriver下載配置)
selenium安裝后默認安裝firefox可以直接使用,當(dāng)然可以通過其它瀏覽器 博主這里整理了:chrome . IE 首先是下載地址 http://docs.seleniumhq.org/down ...
總結(jié)
以上是生活随笔為你收集整理的bat文件设置dns服务器,.bat文件设置IP、DNS的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: annexb avcc
- 下一篇: UOS桌面专业版:修改应用图标和应用名称