用主机win7中的Xshell访问虚拟机ubuntu。

环境:

主机:win7 32位;

虚拟机:ubuntu 11.04 . 32位

Vbox:4.2.8

1、配置网络:host-only与NAT两种方式>实现虚拟机可以访问外网,且虚拟机与主机形成可以互相访问的局域网。

    参考:http://blog.csdn.net/xinghun_4/article/details/7969894 

    虚拟机在安装好之后,默认情况下是通过NAT的网络连接方式(如图1),这样的情况下,虚拟机可以正常上网,但是无法和主机通讯。  

 

    我们需要做的就是启用第二个网络接口,并将改接口改为HostOnly方式(如图2)。这个接口的用途用来跟主机进行通信的。在VBox安装好之后,物理主机系统会自动生成一个网卡(VirtualBox Host-Only Network)(如图3),默认情况下该网卡IP为192.168.56.1,记住一定要将该网卡设为启用。

用主机win7中的Xshell访问虚拟机ubuntu。用主机win7中的Xshell访问虚拟机ubuntu。用主机win7中的Xshell访问虚拟机ubuntu。

 

    将虚拟机启动后,会有两个网卡,一个是原先的网卡,ip地址一般情况下会是10.0.2.x,此网卡是通过NAT方式与主机连接的,主要用来访问网络,另外会有一个新的网卡出现,将该网卡的ip设为192.168.56.x, 网关设为192.168.56.1,该网卡的用途就是用来跟物理机器进行通信。如图4

用主机win7中的Xshell访问虚拟机ubuntu。

 

    经过一番设置之后,虚拟机应该就可以通过IP被物理机器访问了,并可以同时访问网络。注意在这种配置方式下,如果物理主机是在一个局域网内,那么局域网其他的主机是无法通过ip访问到的。( 如果需要局域网内其他主机访问该虚拟机,则需要将该虚拟机的网络连接方式由host only 改为Bridged Adapter,并选择物理主机上的实际物理的网络接口作为接入接口。如果该网络是通过DHCP获得Ip的话,那么虚拟机就可以获得一个和物理机器同等地位的IP地址,就好像一台新的物理机器接入该局域网内一样。如果没有DHCP,那么手工设置一个同物理主机同等的IP地址,也可以得到同样的效果。)

主机与虚拟机互相ping

ping 192.168.56.1

ping 192.168.56.102

    如果还是互相ping不通,请关闭主机和虚拟机的防火墙。

 

2、ubuntu 11.04上检查与安装ssh

     如果在1基础上,两边都互相ping通了,主机用xshell登陆虚拟机的话,还是会出现如下错误:

     Could not connect to ‘192.168.56.102‘ (port 22): Connection failed

     因为ubuntu种没有ssh服务端。

  

先检查是否安装了ssh

dpkg --list|grep ssh

 

发现其实Ubuntu 11.04已经默认安装了客户端,所以我们只要安装服务端就OK了,如果实在没安装,试试这个命令:

#sudo apt-get install openssh-client

 

安装服务端server 命令(备注1)

#sudo apt-get install openssh-server 

 

启动ssh服务:

#sudo /etc/init.d/ssh start

停止ssh服务:

#sudo /etc/init.d/ssh stop

重启ssh服务:

#sudo /etc/init.d/ssh restart

 

启动ssh后,就可以 用xshell登陆utuntu查看代码了。

 

 

备注1:a、执行sudo apt-get install openssh-server 指令时,有时会发生不能获取package的错误,提示需要更新 apt-get update 。

         

b、 执行sudo apt-get update ,出现如下错误错误:(参考:http://blog.csdn.net/chaihuasong/article/details/17009641)

       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/restricted Sources
       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/universe Sources
       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/multiverse Sources
       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/main i386 Packages
       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/restricted i386 Packages
       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/universe i386 Packages
       404 Not Found [IP: 91.189.91.14 80]
       Err http://security.ubuntu.com natty-security/multiverse i386 Packages
       404 Not Found [IP: 91.189.91.14 80]

  解决方法为:发现很多源找不到,需要重新寻找更新源,最后把/etc/apt/sources.list文件中的地址替换如下163内容:

deb http://mirrors.163.com/ubuntu/ lucid main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ lucid-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ lucid-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ lucid-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ lucid-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ lucid main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ lucid-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ lucid-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ lucid-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ lucid-backports main restricted universe multiverse 

发现了这个源超级快的,是网易163更新服务器,亲测可用。国内的源就是牛x

c、接着回到sudo apt-get install openssh-server 出现如下问题:
openssh-server : Depends: openssh-client (= 1:5.3p1-3ubuntu7.1) but 1:5.8p1-1ubuntu3 is to be installed

用主机win7中的Xshell访问虚拟机ubuntu。

解决办法为:sudo apt-get install openssh-client== 1:5.3p1-3ubuntu7.1  

参考:http://www.cnblogs.com/xiaowenhu/p/3185631.html

 

再次回到:sudo apt-get install openssh-server 成执行了。

 

用主机win7中的Xshell访问虚拟机ubuntu。

上一篇:Photoshop将外景婚片调成柔美的粉橙色


下一篇:PhotoshopMM照片简单美白