Monday, December 22, 2008

virtualbox的NAT配置

工作需要, 要在服务器(ubuntu)下跑到个VM, 只要是linux不同的发行版本.

安装了一个virtualbox, 结果有一需求:
* 用户要指直login到虚拟机中

查了一把, 发现virtualbox主要有两种方式:
1. NAT转发
2. 搞个net-bridge, 这时, virtualbox有独立的IP

想了下, NAT转发比较easy. 就决定上这个( 没有需求一般是偷懒 )

本人一直深深知道服务器上, command才是王道, 所以, 主角是:
* VBoxManage命令!

sudo VBoxManage setextradata fedaro6 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/HostPort" 2222

sudo VBoxManage setextradata fedaro6 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/GuestPort" 22

sudo VBoxManage setextradata fedaro6 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/Protocol" TCP


查看一个VM被设置了哪些

jessinio@ubuntu-test-1:~$ sudo VBoxManage getextradata fedaro6 enumerate

VirtualBox Command Line Management Interface Version 2.0.2
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

Key: GUI/SaveMountedAtRuntime, Value: yes
Key: GUI/LastCloseAction, Value: powerOff
Key: GUI/LastWindowPostion, Value: 390,147,720,532
Key: GUI/Fullscreen, Value: off
Key: GUI/Seamless, Value: off
Key: GUI/AutoresizeGuest, Value: on
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/HostPort, Value: 2223
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/Protocol, Value: TCP
Key: VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/GuestPort, Value: 22

如果想remove上面的某条配置, 可以使用

sudo VBoxManage setextradata fedaro6 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/SSH/Protocol"
* 注意: 删除是等于set一个空值!

没有图形界面地启动VM:

sudo VBoxManage startvm redhat8 -type vrdp

问题又来了, 发现使用上面的启动命令行, 不能启动多个无界面的VM, 看一下

00:00:00.086 VirtualBox 2.0.2 r36488 linux.x86 (Sep 12 2008 14:56:22) release log
00:00:00.086 Log opened 2008-12-22T08:52:50.986863000Z
00:00:00.086 OS Product: Linux
00:00:00.086 OS Release: 2.6.22-14-generic
00:00:00.086 OS Version: #1 SMP Sun Oct 14 23:05:12 GMT 2007
00:00:00.092 VRDP: TCP server failed to bind to port 3389. (VERR_NET_ADDRESS_IN_USE)
00:00:00.092 VRDP: TCP server closed.
00:00:00.092 VRDP: Failed to start VRDP-IN thread, rc = VERR_NET_ADDRESS_IN_USE
00:00:00.094 Failed to launch VRDP server (VERR_NET_ADDRESS_IN_USE), error message: 'VRDP server port 3389 is already in use'
00:00:00.094 ERROR [COM]: aRC=NS_ERROR_FAILURE (0x80004005) aIID={d5a1cbda-f5d7-4824-9afe-d640c94c7dcf} aComponent={Console} aText={VRDP server port 3389 is already in use} aWarning=false, preserve=false
00:00:00.103 Power up failed (vrc=VERR_NET_ADDRESS_IN_USE, hrc=NS_ERROR_FAILURE (0X80004005))


* 重点: 'VRDP server port 3389 is already in use'

原来, sudo VBoxManage startvm redhat8 -type vrdp是默认使用了3389端口的. google得到别一命令:
* sudo VBoxVRDP -startvm redhat8 -vrdpport 3391

此命令可以指定port的. OK, 满足工作需求, 先这样吧

* 注意, 对Guest进行这些设置, 都是需要重启Guest的VM

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.