1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

バッチでクライアントの静的DNSを変更する(メモ)

Last updated at Posted at 2018-10-10

静的DNSサーバーを設定しているクライアント用。
DNSサーバーの変更時、
このバッチをGPOのログオンスクリプトなどに登録して使用。

ネットワークアダプター名は下記を想定。
Windows7用に「ローカル エリア接続」「ワイヤレス ネットワーク接続」
Windows10用に「イーサネット」「Wi-Fi」

chgdns.bat
@echo off

setlocal

for /f "tokens=* usebackq" %%i in (`netsh interface ip show dns name^="ローカル エリア接続" ^| find "静的" ^| find "10.0.0.1"`) do (
 netsh dns add dnsserver name="ローカル エリア接続" address=10.1.1.1 validate=no
 netsh dns add dnsserver name="ローカル エリア接続" address=10.1.1.2 validate=no
 netsh dns delete dnsserver name="ローカル エリア接続" address=10.0.0.1 validate=no
 netsh dns delete dnsserver name="ローカル エリア接続" address=10.0.0.2 validate=no

)

for /f "tokens=* usebackq" %%i in (`netsh interface ip show dns name^="ワイヤレス ネットワーク接続" ^| find "静的" ^| find "10.0.0.1"`) do (
 netsh dns add dnsserver name="ワイヤレス ネットワーク接続" address=10.1.1.1 validate=no
 netsh dns add dnsserver name="ワイヤレス ネットワーク接続" address=10.1.1.2 validate=no
 netsh dns delete dnsserver name="ワイヤレス ネットワーク接続" address=10.0.0.1 validate=no
 netsh dns delete dnsserver name="ワイヤレス ネットワーク接続" address=10.0.0.2 validate=no

)

for /f "tokens=* usebackq" %%i in (`netsh interface ip show dns name^="イーサネット" ^| find "静的" ^| find "10.0.0.1"`) do (
 netsh dns add dnsserver name="イーサネット" address=10.1.1.1 validate=no
 netsh dns add dnsserver name="イーサネット" address=10.1.1.2 validate=no
 netsh dns delete dnsserver name="イーサネット" address=10.0.0.1 validate=no
 netsh dns delete dnsserver name="イーサネット" address=10.0.0.2 validate=no

)

for /f "tokens=* usebackq" %%i in (`netsh interface ip show dns name^="Wi-Fi" ^| find "静的" ^| find "10.0.0.1"`) do (
 netsh dns add dnsserver name="Wi-Fi" address=10.1.1.1 validate=no
 netsh dns add dnsserver name="Wi-Fi" address=10.1.1.2 validate=no
 netsh dns delete dnsserver name="Wi-Fi" address=10.0.0.1 validate=no
 netsh dns delete dnsserver name="Wi-Fi" address=10.0.0.2 validate=no

)
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?