株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

仮想ポートACLを構成することで、仮想マシンの通信を制御することができる。
特定のIPアドレス、ポートなどに基づきトラフィックを条件付けして、仮想マシンに対する通信の許可/拒否を制御することができる。
操作は、GUIのHyper-Vマネージャーからの操作はできず、Powershellのみから。

仮想マシン単位のファイアウォール的なイメージかな。
たぶん用途としては、同じネットワークに所属させるけれど、通信のブロックを行いたいときとかかな。

IPアドレスでの制御を行いたい場合、Add-VMNetworkAdapterACLコマンドを使う

# ACL確認すると何も入っていない
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1

# test1という仮想マシンに対して、192.168.0.38からのアクセスを拒否したい場合
PS C:\Users\administrator.CHASE> Add-VMNetworkAdapterAcl -Action Deny -Direction Inbound -VMName test1 -RemoteIPAddress 192.168.0.38

# ACL確認すると上で入力した設定が入っている(ping飛ばなくなる)
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1


VMName: test1
VMId: c258fcb2-3471-4423-8878-13fc8ae679cb
AdapterName: ネットワーク アダプター
AdapterId: Microsoft:C258FCB2-3471-4423-8878-13FC8AE679CB\CDD77A49-DCB5-428A-91E7-9C662FAB2FB4

Direction    Address                                                  Action
---------    -------                                                  ------
Inbound      Remote 192.168.0.38                                      Deny


VMName: test1
VMId: c258fcb2-3471-4423-8878-13fc8ae679cb
AdapterName: ネットワーク アダプター
AdapterId: Microsoft:C258FCB2-3471-4423-8878-13FC8AE679CB\5120F057-AD85-4BEF-9383-6BDC6A86AAB1

Direction    Address                                                  Action
---------    -------                                                  ------
Inbound      Remote 192.168.0.38                                      Deny


# 削除コマンドはAddをRemoveへ置き換える
PS C:\Users\administrator.CHASE> Remove-VMNetworkAdapterAcl -VMName test1  -Action Deny -Direction Inbound -RemoteIPAddress 192.168.0.38

# 削除されている
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1
PS C:\Users\administrator.CHASE>

# 削除コマンドこっちのほうが楽
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1 | Remove-VMNetworkAdapterAcl

ポートでの制御を行いたい場合は、Add-VMNetworkAdapterExtendedAclを使う

# ACLを確認
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterExtendedAcl

# test1という仮想マシンに対して、ポートTCP3389のみを許可する場合
PS C:\Users\administrator.CHASE> Add-VMNetworkAdapterExtendedAcl -VMName test1 -Action Allow -Direction Inbound -LocalPort 3389 -Protocol TCP -Weight 10 -Stateful $true

# ACLを確認(同じ設定がダブってでてくるのはなぜなんだろう・・・)
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterExtendedAcl -VMName test1


Direction          : Inbound
Action             : Allow
LocalIPAddress     : ANY
RemoteIPAddress    : ANY
LocalPort          : 3389
RemotePort         : ANY
Protocol           : TCP
Weight             : 10
Stateful           : True
IdleSessionTimeout : 255
IsolationID        : 0
ParentAdapter      : VMNetworkAdapter (Name = 'ネットワーク アダプター', VMName = 'test1') [VMId = 'c258fcb2-3471-4423-8878-13fc8ae679cb']
IsTemplate         : False
CimSession         : CimSession: .
ComputerName       : FORBIDDEN
IsDeleted          : False

Direction          : Inbound
Action             : Allow
LocalIPAddress     : ANY
RemoteIPAddress    : ANY
LocalPort          : 3389
RemotePort         : ANY
Protocol           : TCP
Weight             : 10
Stateful           : True
IdleSessionTimeout : 255
IsolationID        : 0
ParentAdapter      : VMNetworkAdapter (Name = 'ネットワーク アダプター', VMName = 'test1') [VMId = 'c258fcb2-3471-4423-8878-13fc8ae679cb']
IsTemplate         : False
CimSession         : CimSession: .
ComputerName       : FORBIDDEN
IsDeleted          : False


# 削除コマンド
PS C:\Users\administrator.CHASE> Remove-VMNetworkAdapterExtendedAcl -VMName test1 -Weight 10 -Direction Inbound
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterExtendedAcl
PS C:\Users\administrator.CHASE>

# 削除コマンドこっちのほうが楽
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterExtendedAcl -VMName test1  | Remove-VMNetworkAdapterExtendedAcl

通信量も確認することができる

# ACLを確認
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1

# 仮想マシンtest1に対して、192.168.0.0/24のIPアドレス範囲と通信するネットワークトラフィック量を測定する
PS C:\Users\administrator.CHASE> Add-VMNetworkAdapterAcl -Action Meter -Direction Both -VMName test1 -RemoteIPAddress 192.168.0.0/24

# Actionが増えたり減ったりする
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1


VMName: test1
VMId: c258fcb2-3471-4423-8878-13fc8ae679cb
AdapterName: ネットワーク アダプター
AdapterId: Microsoft:C258FCB2-3471-4423-8878-13FC8AE679CB\CDD77A49-DCB5-428A-91E7-9C662FAB2FB4

Direction    Address                                                  Action
---------    -------                                                  ------
Outbound     Remote 192.168.0.0/24                                    Meter (0 Mbytes)
Inbound      Remote 192.168.0.0/24                                    Meter (1 Mbytes)


VMName: test1
VMId: c258fcb2-3471-4423-8878-13fc8ae679cb
AdapterName: ネットワーク アダプター
AdapterId: Microsoft:C258FCB2-3471-4423-8878-13FC8AE679CB\5120F057-AD85-4BEF-9383-6BDC6A86AAB1

Direction    Address                                                  Action
---------    -------                                                  ------
Inbound      Remote 192.168.0.0/24                                    Meter (0 Mbytes)
Outbound     Remote 192.168.0.0/24                                    Meter (0 Mbytes)


# 削除コマンド
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1 | Remove-VMNetworkAdapterAcl
PS C:\Users\administrator.CHASE> Get-VMNetworkAdapterAcl -VMName test1
PS C:\Users\administrator.CHASE>

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)