Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active December 22, 2015 07:42
Show Gist options
  • Select an option

  • Save stknohg/2b033479e40c38d9912f to your computer and use it in GitHub Desktop.

Select an option

Save stknohg/2b033479e40c38d9912f to your computer and use it in GitHub Desktop.
VagrantでWindowsゲストのNIC名が日本語の場合でもIPアドレスの設定を行える様にするパッチ。
--- ./guest_network.rb.orig 2015-01-06 13:42:26.000000000 +0900
+++ ./guest_network.rb 2015-01-21 11:40:38.341846700 +0900
@@ -40,8 +40,8 @@
def configure_dhcp_interface(nic_index, net_connection_id)
@logger.info("Configuring NIC #{net_connection_id} for DHCP")
if !is_dhcp_enabled(nic_index)
- netsh = "netsh interface ip set address \"#{net_connection_id}\" dhcp"
- @communicator.execute(netsh)
+ command = "&{exit (Get-WMiObject Win32_NetworkAdapterConfiguration -Filter \"Index=#{nic_index}\").EnableDHCP().ReturnValue}"
+ @communicator.execute(command)
end
end
@@ -53,9 +53,8 @@
# @param [String] The network mask to use with the static IP.
def configure_static_interface(nic_index, net_connection_id, ip, netmask)
@logger.info("Configuring NIC #{net_connection_id} using static ip #{ip}")
- #netsh interface ip set address "Local Area Connection 2" static 192.168.33.10 255.255.255.0
- netsh = "netsh interface ip set address \"#{net_connection_id}\" static #{ip} #{netmask}"
- @communicator.execute(netsh)
+ command = "&{exit (Get-WMiObject Win32_NetworkAdapterConfiguration -Filter \"Index=#{nic_index}\").EnableStatic(@(\"#{ip}\"), @(\"#{netmask}\")).ReturnValue}"
+ @communicator.execute(command)
end
# Sets all networks on the guest to 'Work Network' mode. This is
@stknohg

stknohg commented Jan 20, 2015

Copy link
Copy Markdown
Author

このパッチについて

ゲストOSがWindowsで日本語環境の場合NICの名称が日本語("ローカルエリア接続"や"イーサネット")となり、vagrant up時にIPアドレスを設定する際にこの名称が文字化けしてIPアドレスの設定エラーになることがあります。
このパッチはNICの名称が日本語でもエラーにならない様にするパッチになります。

対象バージョン

Vagrant 1.7.2 - 1.7.4

  • 2015/12/22追記 Vagrant 1.8.0でこの問題は解決した様です。

やってること

guest_network.rb内部ではnetshコマンドを使用してIPアドレスの設定を行っています。
このnetshコマンドでIPアドレスを変更している部分をWin32_NetworkAdapterConfigurationクラスのEnableDHCP/EnableStaticメソッドを使う様に差し替えています。
これによりIPアドレスの設定にNIC名称を使うことが無くなるのでエラーを回避することが出来ます。

適用方法

`{インストール先}/Vagrant/embedded/gems/gems/vagrant-1.7.x/plugins/guests/windows/guest_network.rb 'に対して適用します。

適用例)

patch -u ./guest_network.rb < ./windows_guest_network_patch.diff

@stknohg

stknohg commented Jan 21, 2015

Copy link
Copy Markdown
Author

2015/1/21 コードを少し整理してパッチを上げなおしました。

@stknohg

stknohg commented Jul 21, 2015

Copy link
Copy Markdown
Author

対象バージョンを1.7.2-1.7.4に更新しました。

@stknohg

stknohg commented Dec 22, 2015

Copy link
Copy Markdown
Author

Vagrant 1.8.0でこの問題は解決した様です。
私の環境ではこのパッチが無くても日本語ネットワークアダプタ名の設定がうまくいく様になりました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment