virtualbox 网络最佳配置

实验室机器,没有路由,所以不能用bridged方式,搞了好久,都没有成功。因为vb不能从主机这里获取正确的IP。
故用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!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值