0
0

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 1 year has passed since last update.

Hyper-V で使う NAT スイッチを作成する方法

Last updated at Posted at 2023-05-19

Win10 の Hyper-V の NAT をよく壊してしまい、そのたびに調べてるので、再作成方法のメモ。
(壊してしまうのは、vEthernet のデバイスを削除してしまうからです)

  • VM Switch のタイプ 内部ネットワーク (Internal)
  • VM Switch の名前 NAT 10.255.255.254/24
  • vNIC のアドレス 10.255.255.254
  • ネットワークセグメント 10.255.255.0/24

VM Swirch の削除と作成

Get-VMSwitch -Name "NAT 10.255.255.254/24" | Select-Object -Property Name,Id | Format-List
Write-Host "既存の NAT 10.255.255.254/24 スイッチを強制削除します"
Get-VMSwitch -Name "NAT 10.255.255.254/24" | Remove-VMSwitch -Force
Write-Host "NAT 10.255.255.254/24 スイッチを作成します"
New-VMSwitch -name "NAT 10.255.255.254/24" -SwitchType Internal

既存の NAT の削除と再定義

Write-Host "既存の NAT 設定があるか確認します (あれば表示します)"
Get-NetNat | Where-Object {$_.Name -like "NAT 10.255.255.254"} | Format-List
Write-Host "NAT 10.255.255.254 の NAT 設定を削除します"
Get-NetNat -Name "NAT 10.255.255.254" | Remove-NetNat -Confirm:$false
Write-Host "NAT 10.255.255.254 の NAT 設定します"
New-NetNat -Name "NAT 10.255.255.254" -InternalIPInterfaceAddressPrefix 10.255.255.0/24

| Where-Object {$_.Name -like "~"} でフィルタする方法と -Name '*~*' でフィルタする方法があります。なので、それぞれの書き方をしてみました。

| Where-Object {$_.Name -like "~"}-Like,-noLike はワイルドカード比較、-Match, -noMatch で正規表現比較ができます。

Remove-NetNat に失敗するときは、レジストリで削除できる
https://taktak.jp/2022/04/29/4416/
https://www.thomasmaurer.ch/2016/05/set-up-a-hyper-v-virtual-switch-using-a-nat-network/#comment-659842

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nsi{eb004a20-9b1a-11d4-9123-0050047759bc}\6
中のバイナリ値を削除する

IPアドレスの設定

上の二つはコマンド貼り付けで連続実行させても問題ないですが、このコマンドは上の行のコマンドと一緒に貼るとエラーになるので (ビルド 19045.2956 現在)、New-NetNat が終わってから別途実行しましょう。

Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "*NAT 10.255.255.254*" | New-NetIPAddress -AddressFamily IPv4 -IPAddress 10.255.255.254 -PrefixLength 24

あと DHCP は...どうするんだっけ?
まぁ、使わないからいいや。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?