我有一个Ubuntu虚拟机运行在我的Windows 7机器上。我如何设置它,以便我可以通过SSH从外部访问web服务器?
我发现步骤(在VirtualBox主机和客户虚拟机之间设置SSH访问)能够从我的主机SSH到我的客户,但这仍然留给我通过路由器访问它的问题。
我想我可以在我的Windows机器上安装一个SSH服务器,然后隧道几次(虽然我不是100%确定在本地,动态等方面使用什么,或者如何设置多个隧道?),但是有没有一种方法可以让虚拟机直接访问我的路由器,这样我就可以直接端口转发到它?
我有一个Ubuntu虚拟机运行在我的Windows 7机器上。我如何设置它,以便我可以通过SSH从外部访问web服务器?
我发现步骤(在VirtualBox主机和客户虚拟机之间设置SSH访问)能够从我的主机SSH到我的客户,但这仍然留给我通过路由器访问它的问题。
我想我可以在我的Windows机器上安装一个SSH服务器,然后隧道几次(虽然我不是100%确定在本地,动态等方面使用什么,或者如何设置多个隧道?),但是有没有一种方法可以让虚拟机直接访问我的路由器,这样我就可以直接端口转发到它?
当前回答
您也可以启动一个端口转发到您的主机,或任何其他服务器,从您的客户。这是特别有用的,如果你的客户是“锁定”或不能以其他方式完成ModifyVM选项(例如没有权限VBoxManage)。
三个次要要求是1)您是/可以登录到VirtualBox Guest(通过“控制台”GUI,另一个Guest等),2)您在VirtualBox主机(或其他服务器)上有一个帐户,3)SSH和TCP转发不被阻止。
假设你能满足这3个要求,以下是步骤:
On the Guest, run netstat -rn and find the Gateway address to the default route destination 0.0.0.0. Let's say it's "10.0.2.2". This 'Gateway' address is (one of) the VirtualBox Host virtual IP(s). On the Guest, run ssh -R 2222:localhost:22 10.0.2.2 where "10.0.2.2" is the VirtualBox server's IP address -OR- any other server IP you wish to port forward to. On the Host, run ssh 10.0.2.2 -p2222 where 10.0.2.2 is the default gateway/VBHost virtual IP found in step 1. If it is NOT the VirtualBox host you are port forwarding to, then the command is ssh localhost -p2222
其他回答
将VirtualBox中的适配器类型更改为桥接,并将客户机设置为使用DHCP或在DHCP范围之外设置静态IP地址。这将使虚拟机像家庭网络上的普通客户一样工作。然后,您可以移植向前。
在主机上使用putty(不支持端口转发)登录运行在虚拟机中的ubuntu虚拟机:
On Virtualbox manager select the vm, click on settings icon. Then go Networks and enable two adaptors as below: Adaptor 1 (For internet access): Attached to -> NAT, Advanced -> Check the cable connected. Adaptor 2: Attached to -> Host only adaptor, Advanced -> Check the cable connected and Promiscuous mode -> Allow all. Start the ubuntu vm. Login to the VM as root. Edit the file '/etc/network/interfaces' as below and save it: auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp auto eth1 iface eth1 inet dhcp Restart the VM. Login to the VM and run below command to check the IP allocated to eth1: ifconfig Use this IP to open putty session for the VM.
在安全网络上,将网络设置为网桥可能不起作用。管理员只能允许每个端口有一个mac地址,如果交换机在一个端口上检测到多个mac地址,则阻塞端口。
在我看来,最好的解决方案是设置额外的网络接口来处理您希望在计算机上运行的额外服务。所以我有一个桥接接口,当我把我的笔记本电脑带回家时,我可以从我网络上的其他设备SSH到它,当我想从我的笔记本电脑SSH到我的VM时,当我连接到校园的eduroam wifi网络时,我有一个主机适配器。
保留NAT适配器并添加第二个仅限主机的适配器效果非常好,而且对于笔记本电脑(外部网络总是在变化)至关重要。
http://muffinresearch.co.uk/archives/2010/02/08/howto-ssh-into-virtualbox-3-linux-guests/
记住要在virtualbox本身中创建一个主机专用网络(GUI -> settings -> network),否则您无法在客户端上创建主机专用接口。
登录Linux VirtualBox虚拟机的最佳方式是端口转发。缺省情况下,您应该已经有一个正在使用NAT的接口。然后进入“网络设置”,单击“端口转发”按钮。添加一个新规则。插入“ssh”作为规则名。作为“主机端口”,插入3022。作为“来宾端口”,插入22。规则的其他部分可以留空。
或者从命令行
VBoxManage modifyvm myserver --natpf1 "ssh,tcp,,3022,,22"
其中“myserver”是创建的虚拟机名称。查看已添加的规则:
VBoxManage showvminfo myserver | grep 'Rule'
这是所有!请确保您不要忘记在虚拟机中安装SSH服务器:
sudo apt-get install openssh-server
SSH进入客户虚拟机,如下所示:
ssh -p 3022 user@127.0.0.1
其中user是您在虚拟机中的用户名。