2013年6月26日星期三

【转】VirtualBox在NAT下的端口映射

在win7下装的virualbox,虚拟系统为ubuntu下,网络设置为NAT,在ubuntu先安装tomcat,但是web应用程序由于框架的限制对firefox有点不兼容,只能用ie。但是在NAT下无法在局域网中访问ubuntu,只好采取端口映射。

 

1查看设备名称

  在VirtualBox菜单栏,单开“控制”--》“日志菜单”,点击查找写入关键字“NAT”查找类似以下内容

 

Java代码  收藏代码
  1. 00:00:00.688 [/Devices/e1000/0/LUN#0/] (level 4)  
  2. 00:00:00.688   Driver <string>  = "NAT" (cb=4)  

 

       /Devices/e1000/0/LUN#0/设备标识。

2 在cmd下执行以下命令,可以放在bat下执行

 

Java代码  收藏代码
  1. VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/http/Protocol" TCP  
  2.   
  3. VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/http/GuestPort" 8080  
  4.   
  5. VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/http/HostPort" 8080  
  6.   
  7.   
  8. VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/shell/Protocol" TCP  
  9.   
  10. VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/shell/GuestPort" 22  
  11.   
  12. VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/shell/HostPort" 22  

 上面对ssh端口和tomcat的端口(这里用的是8080)进行了映射,其中 VBoxManage.exe 安装在virtualBox目录下,

后面“ubuntu”是虚拟系统的名字,后面是设备标识,对照步骤1应该可以明白,config后面一个名字例如http和shell

可以任意取,GuestPort是虚拟机中所启动服务的端口,HostPost是主机上的映射端口。执行完毕之后,重新启动

虚拟机,就可以了。注意是启动虚拟机不是重启虚拟的ubuntu系统。


摘自:http://jiajw0426.iteye.com/blog/812647

没有评论: