---
title: "用bat设置ip"
author: "letitbe"
date: "2008-08-14T00:53:00Z"
tags: []
slug: "bat-ip"
draft: false
lastmod: "2008-08-14T00:53:00Z"
id: 238225
url: "https://letitbe.iteye.com/blog/238225"
---

1,设置ip  
@echo off  
echo 正在设置ip,子网,请稍候......  
rem "本地连接"为网卡名称，可在网络连接中查询，如"本地连接"  
netsh interface ip set address name="本地连接" source=static addr=192.168.0.10 mask=255.255.255.0  gateway=192.168.0.1 gwmetric=1  
echo.  
echo 正在设置DNS,请稍候.....  
netsh int ip set dns name="本地连接" source=static addr=202.116.1.10  
netsh int ip add dns name="本地连接" addr=192.168.0.3 index=2  
echo 设置完毕!  
ipconfig  
pause  
close

2,设置为"自动获得"  
@echo off  
echo 快速设置IP地址和DNS为"自动获得"  
echo.  
netsh int ip set addr "本地连接" dhcp  
netsh int ip set dns "本地连接" dhcp

todo:把以上两个用一个命令实现

[简单批处理内部命令简介](http://hi.baidu.com/ff8shi/blog/item/c265ce08e7af3035e924888c.html)  
(1)rem为注释