VirtualBox在NAT下的端口映射

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

1查看设备名称

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

00:00:00.688 [/Devices/e1000/0/LUN#0/] (level 4)
 00:00:00.688   Driver <string>  = "NAT" (cb=4)

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

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

VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/http/Protocol" TCP

VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/http/GuestPort" 8080

VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/http/HostPort" 8080


VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/shell/Protocol" TCP

VBoxManage.exe  setextradata "ubuntu" "VBoxInternal/Devices/e1000/0/LUN#0/Config/shell/GuestPort" 22

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系统。

相关推荐