我有一个Ubuntu虚拟机运行在我的Windows 7机器上。我如何设置它,以便我可以通过SSH从外部访问web服务器?
我发现步骤(在VirtualBox主机和客户虚拟机之间设置SSH访问)能够从我的主机SSH到我的客户,但这仍然留给我通过路由器访问它的问题。
我想我可以在我的Windows机器上安装一个SSH服务器,然后隧道几次(虽然我不是100%确定在本地,动态等方面使用什么,或者如何设置多个隧道?),但是有没有一种方法可以让虚拟机直接访问我的路由器,这样我就可以直接端口转发到它?
我有一个Ubuntu虚拟机运行在我的Windows 7机器上。我如何设置它,以便我可以通过SSH从外部访问web服务器?
我发现步骤(在VirtualBox主机和客户虚拟机之间设置SSH访问)能够从我的主机SSH到我的客户,但这仍然留给我通过路由器访问它的问题。
我想我可以在我的Windows机器上安装一个SSH服务器,然后隧道几次(虽然我不是100%确定在本地,动态等方面使用什么,或者如何设置多个隧道?),但是有没有一种方法可以让虚拟机直接访问我的路由器,这样我就可以直接端口转发到它?
当前回答
您还可以在网络设置中使用桥接网络(或“桥接适配器”,在较新的版本中)。这将使您的VM与您的机器处于一个VLAN中。你可以像这样ssh进入VM。
ssh user@IP_OF_VM
其他回答
您还可以在网络设置中使用桥接网络(或“桥接适配器”,在较新的版本中)。这将使您的VM与您的机器处于一个VLAN中。你可以像这样ssh进入VM。
ssh user@IP_OF_VM
在主机上使用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.
将VirtualBox中的适配器类型更改为桥接,并将客户机设置为使用DHCP或在DHCP范围之外设置静态IP地址。这将使虚拟机像家庭网络上的普通客户一样工作。然后,您可以移植向前。
使用NAT网卡和添加端口转发。注明实际主机ip。不要使用127.0.0.1或localhost。
为了从您的主机上ssh到运行在VirtualBox中的Ubuntu VM,您需要为VM设置两个网络适配器。
首先,如果尚未关闭,请关闭虚拟机。
然后选择虚拟机,在VirtualBox工具栏中单击“设置”菜单:
设置适配器1
设置适配器2
(注意:不需要设置端口转发)
就是这样。设置完成后,就可以启动VM了。在你的虚拟机中,网络配置如下所示,你也可以上网:
同样在你的主机上,你可以ssh到你的VM:
确保虚拟机中已安装并运行SSH服务器。
$ ps aux | grep sshd
root 864 0.1 0.5 65512 5392 ? Ss 22:10 0:00 /usr/sbin/sshd -D
如果没有,请安装:
$ sudo apt-get install openssh-server
另外供您参考:
我的VirtualBox版本:5.2.6 r120293 (Qt5.6.2), 2018 我的Ubuntu版本:Ubuntu 16.04.3 LTS 我的主机:Windows 10