window用ssh连接本机虚拟机中的ubuntu

来自:

http://www.cnblogs.com/linjiqin/p/3148337.html

 

window用ssh连接本机虚拟机中的ubuntu

主机和虚拟机间通信,需将2台机器的IP地址设为同一网段。

1、设置虚拟机: 虚拟机–> 设置–> Hardware –> Network Adapter,在网络连接处设置为 “桥接:直接连接到物理网络”,“NAT:使用已共享的主机IP地址”处打勾。

2、window和虚拟机下ubuntu的IP地址设为同一网段
Ubuntu配置和修改IP地址请看:http://www.tieguanyin168.com/index.php/ubuntu-ip-1641.html

其实在第一步中,哪一步中设为桥接模式,并勾选下面那个复选框,就是同一个网段

采用桥接设置才可以PING 通网关

最好设置个静态IP:
sudo vi /etc/network/interfaces,将原有动态IP屏蔽掉
并用下面的行来替换有关eth0的行:在# The primary network interface之后,或在末尾加上
auto eth0
iface eth0 inet static
address 192.168.3.90
gateway 192.168.3.1
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255

将上面的ip地址等信息换成你自己就可以了.用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart

3、互ping下,判断windows与linux是否互相ping通。
i、C:\Users\jiqinlin>ping 192.168.11.88   #192.168.11.88虚拟机下ubuntu的ip

正在 Ping 192.168.11.88 具有 32 字节的数据:
来自 192.168.11.88 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.11.88 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.11.88 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.11.88 的回复: 字节=32 时间<1ms TTL=64

192.168.11.88 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

ii、root@ubuntu:~# ping 192.168.11.74   #192.168.11.74 windows下ip
PING 192.168.11.74 (192.168.11.74) 56(84) bytes of data.
64 bytes from 192.168.11.74: icmp_req=1 ttl=64 time=0.242 ms
64 bytes from 192.168.11.74: icmp_req=2 ttl=64 time=0.268 ms
64 bytes from 192.168.11.74: icmp_req=3 ttl=64 time=0.251 ms

出现类似信息表示windows与linux已互通。

4、连接ssh,在连接前记得在window下安装SSH Secure Shell Client客户端

操作步骤如下:
在win7下通过ssh连接虚拟机的ubuntu,连接失败,提示信息见下图:

然后我在ubuntu终端下输入:ssh localhost,见下图:


ssh : connect to host localhost port 22: Connection refused,原来没有装sshd,也就是openssh-server。
输入命令: sudo apt-get install openssh-server

也可能会出现:Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

再:apt-get update
然后输入命令:ssh localhost,见下图

此时可以通过ssh工具连虚拟机的ubuntu系统了。

 

vmware虚拟机上ubuntu 10.04不能连上外网解决办法

http://blog.csdn.net/lys07962000/article/details/26173055

 

ubuntu apt-get update 失败解决。 

 http://blog.csdn.net/ronghua_liu/article/details/8609450

 

当运行apt-get update后出现如下错误时:
E: Some index files failed to download, they have been ignored, or old ones used instead.

可以将目录下/var/lib/apt/lists/partial/所有的文件清掉,再次运行apt-get update即可!自带源在大陆不好。


出现以下错误:

  1. /etc/apt$ sudo apt-get update  
  2. Err http://security.ubuntu.com precise-security InRelease  
  3.     
  4. Err http://security.ubuntu.com precise-security Release.gpg  
  5.   Temporary failure resolving 'security.ubuntu.com'  
  6. Err http://cn.archive.ubuntu.com precise InRelease  
  7.     
  8. Err http://cn.archive.ubuntu.com precise-updates InRelease  
  9.     
  10. Err http://cn.archive.ubuntu.com precise-backports InRelease  
  11.     
  12. Err http://cn.archive.ubuntu.com precise Release.gpg  
  13.   Temporary failure resolving 'cn.archive.ubuntu.com'  
  14. Err http://cn.archive.ubuntu.com precise-updates Release.gpg  
  15.   Temporary failure resolving 'cn.archive.ubuntu.com'  
  16. Err http://cn.archive.ubuntu.com precise-backports Release.gpg  
  17.   Temporary failure resolving 'cn.archive.ubuntu.com'  
  18. Reading package lists... Done  
  19. W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise/InRelease    
  20.   
  21. W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease    
  22.   
  23. W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-backports/InRelease    
  24.   
  25. W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/InRelease    
  26.   
  27. W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/Release.gpg  Temporary failure resolving 'security.ubuntu.com'  
  28.   
  29. W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise/Release.gpg  Temporary failure resolving 'cn.archive.ubuntu.com'  
  30.   
  31. W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-updates/Release.gpg  Temporary failure resolving 'cn.archive.ubuntu.com'  
  32.   
  33. W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-backports/Release.gpg  Temporary failure resolving 'cn.archive.ubuntu.com'  
  34.   
  35. W: Some index files failed to download. They have been ignored, or old ones used instead.  
  36. xinju@xinjuOffice:/etc/apt$ cd ../network  
/etc/apt$ sudo apt-get update
Err http://security.ubuntu.com precise-security InRelease
  
Err http://security.ubuntu.com precise-security Release.gpg
  Temporary failure resolving 'security.ubuntu.com'
Err http://cn.archive.ubuntu.com precise InRelease
  
Err http://cn.archive.ubuntu.com precise-updates InRelease
  
Err http://cn.archive.ubuntu.com precise-backports InRelease
  
Err http://cn.archive.ubuntu.com precise Release.gpg
  Temporary failure resolving 'cn.archive.ubuntu.com'
Err http://cn.archive.ubuntu.com precise-updates Release.gpg
  Temporary failure resolving 'cn.archive.ubuntu.com'
Err http://cn.archive.ubuntu.com precise-backports Release.gpg
  Temporary failure resolving 'cn.archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise/InRelease  

W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease  

W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-backports/InRelease  

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/InRelease  

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/precise-security/Release.gpg  Temporary failure resolving 'security.ubuntu.com'

W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise/Release.gpg  Temporary failure resolving 'cn.archive.ubuntu.com'

W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-updates/Release.gpg  Temporary failure resolving 'cn.archive.ubuntu.com'

W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise-backports/Release.gpg  Temporary failure resolving 'cn.archive.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.
xinju@xinjuOffice:/etc/apt$ cd ../network

 


阿里源:

  1. deb http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  
  2. deb http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  
  3. deb http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  
  4. deb http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  
  5. deb http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  
  6. deb-src http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse  
  7. deb-src http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse  
  8. deb-src http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse  
  9. deb-src http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse  
  10. deb-src http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse  
deb http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ raring main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ raring-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ raring-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ raring-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ raring-backports main restricted universe multiverse


 

修改ip:

  1. # This file describes the network interfaces available on your system  
  2. # and how to activate them. For more information, see interfaces(5).  
  3.   
  4. # The loopback network interface  
  5. auto lo  
  6. iface lo inet loopback  
  7.   
  8. # The primary network interfacea  
  9. auto eth0  
  10. iface eth0 inet static  
  11. address 192.168.2.170  
  12. netmask 255.255.255.0  
  13. broadcast 192.168.2.255  
  14. gateway 192.168.2.1  
  15. dns-nameservers 192.168.2.1  
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interfacea
auto eth0
iface eth0 inet static
address 192.168.2.170
netmask 255.255.255.0
broadcast 192.168.2.255
gateway 192.168.2.1
dns-nameservers 192.168.2.1


 


修改dns:

1,重启生效:

sudo vi /etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)

在里面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4

如果有多个DNS就一行一个

修改好保存,然后执行

sudo resolvconf -u

再看/etc/resolv.conf,最下面就多了2行:

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。


 

2,重启失效:

配置文件地址 /etc/resolv.conf

使用编辑器打开

改为如下内容:
search localdomain
nameserver 202.96.128.86 希望修改成的DNS
nameserver 202.96.128.166 备用DNS

重启网络:sudo /etc/init.d/networking restart。即可

 在目录:/var/lib/apt/lists/partial  输入:

 /etc/init.d/networking restart

提示:sh:0 :getcwd() failed: NO such file or directory//出现这个问题是该目录已经被删除

.....

cd / 之后  /etc/init.d/networking restart   就没上面哪个问题

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值