5
5

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.

Windows7 ごく簡単なネットワーク設定スクリプト

Last updated at Posted at 2014-05-13

前提

複数のサブネットを手動で、しかも頻繁に設定して使い分ける必要がある時に便利なスクリプト

  • 環境は Windows7
  • 今回は PowerShell は用いない。
    • *.ps1 はデフォルトで有効ではないという衝撃

スクリプト例

外部向け

  • 固定IPアドレス
  • デフォルトゲートウェイ有り
  • DNS 指定有り
  • ファイアウォール有効
外部ネットワーク.bat
netsh advfirewall set allprofiles state on
netsh interface ip set address "ローカル エリア接続" static 192.168.xxx.xxx 255.255.255.0 192.168.yyy.yyy
netsh interface ip set dns "ローカル エリア接続" static 192.168.aaa.aaa primary validate=no
netsh interface ip set dns "ローカル エリア接続" static 192.168.bbb.bbb validate=no

内部向け

  • 固定IPアドレス
  • デフォルトゲートウェイ無し
  • DNS 無効
  • ファイアウォール無効
内部ネットワーク.bat
netsh interface ip set address "ローカル エリア接続" static 192.168.xxx.xxx 255.255.255.0 none
netsh interface ip set dns "ローカル エリア接続" none
netsh advfirewall set allprofiles state off

変更結果表示

変更結果確認.bat
netsh interface ip show address "ローカル エリア接続"
netsh interface ip show dns "ローカル エリア接続"

readme

  • bat ファイルは管理者アカウントで実行

備考

  • 実際のスクリプトでは
    • 設定変更の処理をした後には、必ず変更結果表示させています
    • 最後に pause してます (エラー・変更結果確認のため)
  • "ローカル エリア接続" というのは、コンパネ/ネットワーク から設定できるアダプタ名です。

あとがき

  • 思い出しながら書いてるので、ところどころ怪しいです (という言い訳)
  • ちなみに XP 以前では netsh firewall コマンドらしい
5
5
2

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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?