故用NAT方式,但是vb提供的初始NAT方式无法实现主机连到客户机,因为被一个叫vb engine的东西给隐藏起来了,
所以主机虚拟机无法通信。这个时候就要配置下vb了。具体如下:
You will need to know which ports on the guest the service uses and to decide which ports to use on the host (often but not always you will want to use the same ports on the guest and on the host). You can use any ports on the host which are not already in use by a service. For example, to set up incoming NAT connections to an ssh
server in the guest, use the following command:
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"
With the above example, all TCP traffic arriving on port 2222 on any host interface will be forwarded to port 22 in the guest. The protocol name tcp
is a mandatory attribute defining which protocol should be used for forwarding (udp
could also be used). The name guestssh
is purely descriptive and will be auto-generated if omitted. The number after --natpf
denotes the network card, like in other parts of VBoxManage.
To remove this forwarding rule again, use the following command:
VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"
If for some reason the guest uses a static assigned IP address not leased from the built-in DHCP server, it is required to specify the guest IP when registering the forwarding rule:
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,10.0.2.19,22"
This example is identical to the previous one, except that the NAT engine is being told that the guest can be found at the 10.0.2.19 address.
我自己的机器上就用VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"就可以了。
然后主机运行putty, ip填入localhost, 端口为2222,这里要大于1024.
这样主机就可以和虚拟机用ssh连入了。
不过缺点是主机和客户机无法使用我写的ipmsg来传文件了,因为不支持UDP广播。
看来要用FTP了,同样也要做个nat。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~从网上得到的~~~~~启示~~~~~~~~~~~~~~~~~~~~~~~~~~~~
其实呢,不必这么麻烦的。
只要再给vb增加一块网卡就解决问题了。
哈哈
一块是NAT,一块为Host only
Done! Cool!