如何启用/禁用 VRDP 对 VirtualBox VM 的访问(无论状态如何)

如何启用/禁用 VRDP 对 VirtualBox VM 的访问(无论状态如何)

在文档中https://www.virtualbox.org/manual/ch07.html

他们告诉你你可以使用

$ VBoxManage modifyvm VM-name --vrde on

但这仅在虚拟机关闭时才有效。

虚拟机开启时可以执行此操作吗?怎么做?

--

词汇表:

RDP:远程桌面协议

VM:虚拟机

真空干燥机:VirtualBox 远程桌面扩展

答案1

是的。

列出虚拟机(获取名称)

$ VBoxManage list vms
"Debian_11_Server_64bit" {3d**6e14-3846-4673-aacb-726****283af}
"emptyVM" {8a**643a-f470-4ab0-931a-5da6****5ce4}

- 当虚拟机关闭时启用/禁用 VRDP

# Power off
$ vboxmanage controlvm emptyVM   poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

# Turn off VRDP
$ VBoxManage modifyvm emptyVM --vrde off

# Turn on VRDP
$ VBoxManage modifyvm emptyVM --vrde on

- 当虚拟机开启(或关闭)时启用/禁用 VRDP

# We start the VM
$ vboxmanage startvm emptyVM  --type headless
Waiting for VM "emptyVM" to power on...
VM "emptyVM" has been successfully started.

# Try the previous command
$ VBoxManage modifyvm emptyVM --vrde on
VBoxManage: error: The machine 'emptyVM' is already locked for a session (or being unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 640 of file VBoxManageModifyVM.cpp

当虚拟机处于开启状态时,无法使用“modifyvm”更改 VRDP 设置。

但我们仍然可以用“controlvm”来改变它们。

$ VBoxManage controlvm emptyVM vrde off

$ VBoxManage controlvm emptyVM vrde on

- 我如何知道它是否已启用/禁用以及端口?

$ vboxmanage showvminfo emptyVM | grep VRDE
VRDE:                        enabled (Address 0.0.0.0, Ports 3394, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE port:                   3394
VRDE property               : TCP/Ports  = "3394"
VRDE property               : TCP/Address = <not set>
VRDE property               : VideoChannel/Enabled = <not set>
VRDE property               : VideoChannel/Quality = <not set>
VRDE property               : VideoChannel/DownscaleProtection = <not set>
VRDE property               : Client/DisableDisplay = <not set>
VRDE property               : Client/DisableInput = <not set>
VRDE property               : Client/DisableAudio = <not set>
VRDE property               : Client/DisableUSB = <not set>
VRDE property               : Client/DisableClipboard = <not set>
VRDE property               : Client/DisableUpstreamAudio = <not set>
VRDE property               : Client/DisableRDPDR = <not set>
VRDE property               : H3DRedirect/Enabled = <not set>
VRDE property               : Security/Method = <not set>
VRDE property               : Security/ServerCertificate = <not set>
VRDE property               : Security/ServerPrivateKey = <not set>
VRDE property               : Security/CACertificate = <not set>
VRDE property               : Audio/RateCorrectionMode = <not set>
VRDE property               : Audio/LogPath = <not set>
VRDE Connection:             not active

- 如何更改端口

$ vboxmanage controlvm emptyVM  vrdeport 12345

- 当虚拟机关闭时,使用“controlvm”所做的更改是否会保留?

下面我们关闭虚拟机,禁用 VRDP,打开电源,修改 VRDP,关闭电源并检查。显然,更改是持久的。

$ vboxmanage controlvm emptyVM   poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ VBoxManage modifyvm emptyVM --vrde off

$ vboxmanage showvminfo emptyVM | grep VRDE
VRDE:                        disabled

$ vboxmanage startvm emptyVM  --type headless
Waiting for VM "emptyVM" to power on...
VM "emptyVM" has been successfully started.

$ vboxmanage showvminfo emptyVM | grep VRDE
VRDE:                        disabled
VRDE Connection:             not active

$ vboxmanage controlvm emptyVM  vrde on vrdeport 12345

$ vboxmanage showvminfo emptyVM | grep VRDE
VRDE:                        enabled (Address 0.0.0.0, Ports 12345, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE port:                   12345
VRDE property               : TCP/Ports  = "12345"
VRDE property               : TCP/Address = <not set>
VRDE property               : VideoChannel/Enabled = <not set>
VRDE property               : VideoChannel/Quality = <not set>
VRDE property               : VideoChannel/DownscaleProtection = <not set>
VRDE property               : Client/DisableDisplay = <not set>
VRDE property               : Client/DisableInput = <not set>
VRDE property               : Client/DisableAudio = <not set>
VRDE property               : Client/DisableUSB = <not set>
VRDE property               : Client/DisableClipboard = <not set>
VRDE property               : Client/DisableUpstreamAudio = <not set>
VRDE property               : Client/DisableRDPDR = <not set>
VRDE property               : H3DRedirect/Enabled = <not set>
VRDE property               : Security/Method = <not set>
VRDE property               : Security/ServerCertificate = <not set>
VRDE property               : Security/ServerPrivateKey = <not set>
VRDE property               : Security/CACertificate = <not set>
VRDE property               : Audio/RateCorrectionMode = <not set>
VRDE property               : Audio/LogPath = <not set>
VRDE Connection:             not active

$ vboxmanage controlvm emptyVM   poweroff
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

$ vboxmanage showvminfo emptyVM | grep VRDE
VRDE:                        enabled (Address 0.0.0.0, Ports 12345, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE property               : TCP/Ports  = "12345"
VRDE property               : TCP/Address = <not set>
VRDE property               : VideoChannel/Enabled = <not set>
VRDE property               : VideoChannel/Quality = <not set>
VRDE property               : VideoChannel/DownscaleProtection = <not set>
VRDE property               : Client/DisableDisplay = <not set>
VRDE property               : Client/DisableInput = <not set>
VRDE property               : Client/DisableAudio = <not set>
VRDE property               : Client/DisableUSB = <not set>
VRDE property               : Client/DisableClipboard = <not set>
VRDE property               : Client/DisableUpstreamAudio = <not set>
VRDE property               : Client/DisableRDPDR = <not set>
VRDE property               : H3DRedirect/Enabled = <not set>
VRDE property               : Security/Method = <not set>
VRDE property               : Security/ServerCertificate = <not set>
VRDE property               : Security/ServerPrivateKey = <not set>
VRDE property               : Security/CACertificate = <not set>
VRDE property               : Audio/RateCorrectionMode = <not set>
VRDE property               : Audio/LogPath = <not set>

相关内容