Win10设置Virtual Box主机和虚拟机互通,同时访问外网

更改网络适配器

点击自己要共享网络的网卡,我这里是WLAN,在属性面板选择共享,在家庭网络连接里选择自己的虚拟机网卡名,我这里的VitrubalBox就是虚拟机的。
在这里插入图片描述

注意:第一次设置会提示要把IP变为192.168.137.1,同时设置成动态ip,按要求设置即可。在这里插入图片描述

设置虚拟机网络参数配置

点击要设置的虚拟机设置网卡1为NET模式:

在这里插入图片描述

设置网卡2位host-only模式

在这里插入图片描述

配置虚拟机网卡

启动虚拟机,ifconfig查看当前网卡信息
在这里插入图片描述
这里看到有2个,分别是enp0s3和enp0s8,然后在/etc/sysconfig/network-scripts/目录下找到对应网卡配置:

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-enp0s3  ifdown-eth   ifdown-post    ifdown-TeamPort  ifup-eth   ifup-plip    ifup-sit       init.ipv6-global
ifcfg-enp0s8  ifdown-ib    ifdown-ppp

enp0s3对应网卡1,内容如下:

[root@localhost network-scripts]# cat ifcfg-enp0s3 
TYPE="Ethernet"
NAME="enp0s3"
HWADDR=08:00:27:11:46:D3
ONBOOT="yes"
BOOTPROTO="DDHCP"

enp0s8对应网卡2,内容如下:

[root@localhost network-scripts]# cat ifcfg-enp0s8
DEVICE=enp0s8
HWADDR=08:00:27:43:62:90
TYPE=Ethernet
NAME=enp0s8
ONBOOT=yes
#BOOTPROTO=dhcp
GATEWAY=192.168.137.1
NETMASK=255.255.255.0
IPADDR=192.168.137.20

重启网络环境

[root@localhost network-scripts]# service network restart 
Restarting network (via systemctl):                        [  确定  ]

测试

使用ping测试下:

[root@localhost ~]# ping csdn.net
PING csdn.net (47.95.164.112) 56(84) bytes of data.
64 bytes from 47.95.164.112: icmp_seq=1 ttl=90 time=46.4 ms
64 bytes from 47.95.164.112: icmp_seq=2 ttl=90 time=13.4 ms
64 bytes from 47.95.164.112: icmp_seq=3 ttl=90 time=13.2 ms
64 bytes from 47.95.164.112: icmp_seq=4 ttl=90 time=12.9 ms
64 bytes from 47.95.164.112: icmp_seq=5 ttl=90 time=14.4 ms
^C64 bytes from 47.95.164.112: icmp_seq=6 ttl=90 time=54.4 ms

如果无法ping通,尝试配置下DNS再试:

[root@localhost network-scripts]# cat /etc/resolv.conf 
# Generated by NetworkManager
search workgroup
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 140.207.198.6

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值