菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
137
0

虚拟机利用Host-only实现在不插网线的情况下,虚拟机与主机实现双向通信,实现ssh连接以及samba服务实现共享

原创
05/13 14:22
阅读数 78282

  • 为了不影响其他的虚拟网卡,我们在VMware下在添加一块虚拟网卡:

image

image

然后点击Next,选择连接方式:

image

点击Finish即可。

重新启动虚拟机,如果这是你手动添加的第一块虚拟网卡,那么应该是eth1。

  • 配置eth1的ip信息

image

可以看到,VMnet1的type就是Host-only,我们看一下他的DHCP setting信息:

image

根据上面的信息,可以将eth1设置为跟VMnet1处于同一个网段,并将设置信息填写在 /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 static
address 192.168.8.129
netmask 255.255.255.0
network 192.168.8.0
broadcast 192.168.8.255
gateway 192.168.8.1

auto eth0:1
iface eth0:1 inet static
address 192.168.253.129
netmask 255.255.255.0

auto eth1
iface eth1 inet static
address 192.168.229.129
netmask 255.255.255.0

这里只需要看eth1的配置即可,不用看其他的。

然后重新启动网络服务   sudo /etc/init.d/networking restart

image

  • 测试(为了准确点,拔掉网线)

在宿主机下面ping虚拟机   

image

在虚拟机下面ping宿主机:

image

或者虚拟机可以ping一下宿主机的其他ip,比如我的宿主机上网的ip是192.168.8.129

image

  • 用samba服务实现共享(samba的配置过程这里不介绍),同样为了准确一些,还是拔掉网线。

image

image

点击完成即可。这样就可以在我的电脑下面出现一个映射出来的网络驱动器。

  • SSH连接,同样为了准确一些,还是拔掉网线。这里使用secureCRT作为客户端

image

image 

 

进行连接测试:

image

 

image

 

image

 

连接成功。

发表评论

0/200
137 点赞
0 评论
收藏