局域网内主机ssh访问服务器宿主下VMWare 虚拟机(Ubuntu 12.04.1)并且实现虚拟机能上网的那点事

(1)首先虚拟机已安装ssh服务

1) 自动安装 ssh 服务

apt-get install openssh-server

安装完成后,将自动开启 ssh 服务。

2) 查看 ssh 服务是否已开启

netstat -pant | grep 22

若出现以上输出,则说明 ssh 服务安装成功并已开启。

注意:以下需通过 ssh 服务来实现远程登录。

(2)右键对应虚拟机-》属性-》虚拟机设置

如图设置

如果后面还不能访问将如下图红线框内的选项设置为“自动”

(3)进入虚拟机shell界面,执行ifconfig命令获取虚拟机的网络信息

需要将该虚拟机ip静态设置:/etc/network/interfaces

sudo vi /etc/network/interfaces

# 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 interface
#auto eth0
#iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.2.128
netmask 255.255.255.0
gateway 192.168.2.2

重启ubuntu的网卡
sudo /etc/init.d/networking restart

好啦可以试着用ssh远程工具访问该虚拟机。
(4)执行ping命令看虚拟机是否能上网

  ping www.baidu.com

结果 

PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.
64 bytes from 115.239.211.112: icmp_req=1 ttl=53 time=6.55 ms
64 bytes from 115.239.211.112: icmp_req=2 ttl=53 time=6.94 ms
64 bytes from 115.239.211.112: icmp_req=3 ttl=53 time=6.66 ms

则表示外网通了

posted @ 2015-12-16 11:09  火腿骑士  阅读(1065)  评论(0编辑  收藏  举报