!!!Windows2k, XPでコマンドラインからIPアドレスを設定する方法
{{category Windows}}
----
netshコマンドを使用する。
基本的な書式は
netsh interface ip set address "インターフェース名" static 192.168.0.2 255.255.255.0 192.168.0.254
netsh interface ip set dns "インターフェース名" 192.168.0.1
的な IPaddress Netmask Gateway の列挙方式だが、
どうも長さ制限があるようで、これだと良く失敗する。
netsh interface ip dump > dump.txt
を実行することで、現在の設定をテキストに切り出せるので、
これを使ってやるといい。
切り出したテキストは
netsh exec dump.txt
とnetshに食わせてやればそのまま反映できる。
ちなみにdhcpにしたい場合は
netsh interface ip set address "インターフェース名" dhcp
netsh interface ip set dns "インターフェース名" dhcp
で問題なく変更できる。
参考:
切り出したテキストはこんな感じ。
# ----------------------------------
# インターフェイス IP 構成
# ----------------------------------
pushd interface ip
# "fxp0" のインターフェイス IP 構成
set address name = "fxp0" source = static addr = 10.0.156.10 mask = 255.255.255.0
set address name = "fxp0" gateway = 10.0.156.254 gwmetric = 1
set dns name = "fxp0" source = static addr = 10.0.156.20
add dns name = "fxp0" addr = 61.194.228.178
set wins name = "fxp0" source = static addr = 10.0.156.20
popd
# インターフェイス IP 構成の最後