我有一个Ubuntu虚拟机运行在我的Windows 7机器上。我如何设置它,以便我可以通过SSH从外部访问web服务器?

我发现步骤(在VirtualBox主机和客户虚拟机之间设置SSH访问)能够从我的主机SSH到我的客户,但这仍然留给我通过路由器访问它的问题。

我想我可以在我的Windows机器上安装一个SSH服务器,然后隧道几次(虽然我不是100%确定在本地,动态等方面使用什么,或者如何设置多个隧道?),但是有没有一种方法可以让虚拟机直接访问我的路由器,这样我就可以直接端口转发到它?


当前回答

将VirtualBox中的适配器类型更改为桥接,并将客户机设置为使用DHCP或在DHCP范围之外设置静态IP地址。这将使虚拟机像家庭网络上的普通客户一样工作。然后,您可以移植向前。

其他回答

对于Windows主机,您可以:

在virtualbox管理器中: 在virtualbox管理器中选择ctrl+G, 然后进入网络面板 添加专用网络 确保“激活DHCP”未选中 网管(windows) 选择新创建的virtualbox主机专用适配器和物理网卡 右键选择“制作桥” 享受

使用NAT网卡和添加端口转发。注明实际主机ip。不要使用127.0.0.1或localhost。

在主机上使用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.

简单地将网络设置设置为桥接就可以了。

当你这样做时,你的IP会改变。然而,在我的情况下,它并没有立即改变。Ifconfig返回相同的ip。我重启了虚拟机,然后砰的一声,ip设置为1,从192开始。*我立即被允许ssh访问。

优麒麟 18.04 LTS

配置桥接以查看服务器ip,并且连接时没有“端口转发”

VirtualBox >右键单击服务器>设置> Network > enable适配器2 > select " bridging " >混杂模式:允许所有>检查>启动服务器连接的线缆

在ubuntu服务器上编辑sudo nano /etc/netplan/*init.yaml文件,

我的示例文件:

network:
    ethernets:
        enp0s3:
            addresses: []
            dhcp4: true
        enp0s8:
            addresses: [192.168.0.200/24]
            dhcp4: no
            dhcp6: no
            nameservers:
               addresses: [8.8.8.8, 8.8.4.4]
    version: 2

这些命令将帮助你

nano /etc/netplan/file.yaml     # file to specify the rules of network
reboot now                      # restart ubuntu server right now
netplan apply                   # do after edited *.yaml, to apply changes
ifconfig -a                     # show interfaces with ip, netmask, broadcast, etc...
ping google.com                 # to see if there is internet

在Ubuntu 18.04 LTS服务器上配置静态IP地址-使用NetPlan