1.Oracle VM VirtualBox默认网络方式
Oracle VM VirtualBox创建的虚拟机默认使用的是:网络地址转换–端口转发的方式
2.默认虚拟机ip地址不是固定IP,不方便开发
修改Vagrantfile
config.vm.network "private_network", ip: "192.168.63.10"
这里的ip需要在物理机下使用如下方式找到
方式一:ipconfig命令找到
找到以太网适配器 VirtualBox Host-Only Network #3:中的IPv4 地址
C:\Users\dell>ipconfig
Windows IP 配置
以太网适配器 VirtualBox Host-Only Network #3:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::6d0a:95a1:f6eb:eacd%26
IPv4 地址 . . . . . . . . . . . . : 192.168.63.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
无线局域网适配器 WLAN:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 本地连接* 2:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 本地连接* 4:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
以太网适配器 以太网:
连接特定的 DNS 后缀 . . . . . . . : ultrapower.com.cn
IPv6 地址 . . . . . . . . . . . . : 240e:604:107:6:8546:51cf:6021:a14c
临时 IPv6 地址. . . . . . . . . . : 240e:604:107:6:9953:8f89:ecd7:522f
本地链接 IPv6 地址. . . . . . . . : fe80::8546:51cf:6021:a14c%18
IPv4 地址 . . . . . . . . . . . . : 192.168.10.87
子网掩码 . . . . . . . . . . . . : 255.255.254.0
默认网关. . . . . . . . . . . . . : fe80::c67d:4fff:fe09:e72e%18
192.168.10.1
以太网适配器 以太网 2:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
方式二: 控制面板->网络和 Internet->网络连接
重启虚拟机
C:\Users\Administrator>vagrant reload
==> default: Attempting graceful shutdown of VM...
==> default: Checking if box 'centos/7' version '2004.01' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Vagrant has detected a configuration issue which exposes a
==> default: vulnerability with the installed version of VirtualBox. The
==> default: current guest is configured to use an E1000 NIC type for a
==> default: network adapter which is vulnerable in this version of VirtualBox.
==> default: Ensure the guest is trusted to use this configuration or update
==> default: the NIC type using one of the methods below:
==> default:
==> default: https://www.vagrantup.com/docs/virtualbox/configuration.html#default-nic-type
==> default: https://www.vagrantup.com/docs/virtualbox/networking.html#virtualbox-nic-type
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Connection reset. Retrying...
default: Warning: Connection aborted. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/c/Users/Administrator/ => /vagrant
3.开启远程登陆
修改 /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
重启SSHD
systemctl restart sshd
使用Xshell或SecureCRT进行远程连接。