ccran 的个人博客 ccran 的个人博客

记录精彩的程序人生

目录
Windows与VirtualBox虚拟机互访
/  

Windows与VirtualBox虚拟机互访

Windows与VirtualBox虚拟机互访

  1. 在VirtualBox的网络设置页面打开网卡1设置为网络地址转换(NAT),网卡2设置为仅主机(Host-Only)网络
  2. 登录虚拟机CentOS7,查看IP地址,可以看到有lo,enp0s3,enp0s8三张网卡
[ccran@localhost]$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:10:93:2f brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 85781sec preferred_lft 85781sec
    inet6 fe80::a00:27ff:fe10:932f/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:61:06:97 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.100/24 brd 192.168.56.255 scope global enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe61:697/64 scope link
       valid_lft forever preferred_lft forever
  1. 进入配置文件,其中,ifcfg-enp0s3是NAT连接方式对应的网卡配置文件,ifcfg-enp0s8是Host-Only连接方式对应的网卡配置文件;若不存在ifcfg-enp0s8,可以复制ifcfg-enp0s3文件作为ifcfg-enp0s8。
# 进入网络配置文件
[ccran@localhost]$ cd /etc/sysconfig/network-scripts/
[ccran@localhost network-scripts]$ ls ifcfg-enp*
ifcfg-enp0s3  ifcfg-enp0s8
  1. vim修改host-only对应网卡的配置文件(本例子中是ifcfg-enp0s8)
HWADDR=08:00:27:61:06:97 # MAC地址
TYPE=Ethernet
BOOTPROTO=static # 静态IP
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s8 # 网卡名称
ONBOOT=yes # 系统启动时激活网卡
IPADDR=192.168.56.100  # IP地址
GATEWAY=192.168.56.1 # 网关
NETMASK=255.255.255.0 # 子网掩码
  1. 重启网卡、重启机器
# 重启网卡
[ccran@localhost]$ systemctl restart network
[ccran@localhost]$ reboot
  1. 可以通过SSH登录虚拟机192.168.56.100愉快的玩耍了!

标题:Windows与VirtualBox虚拟机互访
作者:ccran
地址:https://ccran.online/articles/2021/03/22/1616423514579.html