今天解决了VirtualBox的一个困扰我已久的问题。
我的host是Win7,guest是ubuntu10.04.
我想在host中很方便的使用ubuntu中的东西。例如,我要在linux中运行django,然后在windows中127.0.0.1,因为我不知道我的ubuntu的IP是多少,也不想去了解。把下列内容存为*.bat:
VBoxManage setextradata Ubuntu10.04 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/django/Protocol" TCP
VBoxManage setextradata Ubuntu10.04 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/django/GuestPort" 8000
VBoxManage setextradata Ubuntu10.04 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/django/HostPort" 8000
VBoxManage setextradata Ubuntu10.04 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
VBoxManage setextradata Ubuntu10.04 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
VBoxManage setextradata Ubuntu10.04 "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
然后到C:\Program Files\Sun\VirtualBox运行该文件,ssh可以了,为什么不能127.0.0.1呢?原来,运行django必须:
python manage.py runserver 0:8000
为什么如此呢,因为“Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g.
192.168.2.1) or
0.0.0.0.”
参考资料:http://blogs.oregonstate.edu/paynez/2009/06/24/django-development-in-virtualbox
http://forums.virtualbox.org/viewtopic.php?f=8&t=19221&p=82997&hilit=django#p82997