Oracle VM VirtualBox_7创建CentOS7
安装环境
-
新建虚拟电脑
-
设置内存和处理器
-
设置硬盘大小
-
完成
-
设置
-
查看光驱
-
设置启动顺序
-
点击启动
-
选择第1项
-
进入图形安装界面
-
选择安装位置,开始安装
-
设置root密码
-
重启
-
登录
-
查看本地文件夹
-
修改内存/处理器/磁盘
点击查看代码
- 选择或创建虚拟盘
- 下一步
配置网络
自动分配ip
- 连接wifi时查看宿主机
C:\Users\ychen
λ ipconfig
Windows IP 配置
以太网适配器 以太网:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
以太网适配器 以太网 2:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::f030:fc10:a7e3:f138%18
IPv4 地址 . . . . . . . . . . . . : 192.168.56.1
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . :
无线局域网适配器 本地连接* 9:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 本地连接* 10:
媒体状态 . . . . . . . . . . . . : 媒体已断开连接
连接特定的 DNS 后缀 . . . . . . . :
无线局域网适配器 WLAN:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::d535:a64f:ea6:410b%8
IPv4 地址 . . . . . . . . . . . . : 192.168.31.111
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 192.168.31.1
-
管理,工具,网络管理器
-
查看区间
-
设置,网络
# 启动虚拟机,进入如下目录
cd /etc/sysconfig/network-scripts
# 编辑
vi ifcfg-enp0s3
# 配置如下
BOOTPROTO=dhcp
ONBOOT=yes
# 重启网络服务
systemctl restart network
- 验证
# 查看ip
[root@MiWiFi-R3P-srv ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 group default qlen 1000
link/ether 08:00:27:2e:3e:57 brd ff:ff:ff:ff:ff:ff
inet 192.168.31.72/24 brd 192.168.31.255 scope global noprefixroute dynamic enp0s3
valid_lft 42543sec preferred_lft 42543sec
inet6 fe80::61e5:b3c9:7628:9097/64 scope link noprefixroute
valid_lft forever preferred_lft forever
# 测试外网
[root@MiWiFi-R3P-srv ~]# ping www.baidu.com
PING www.a.shifen.com (220.181.38.150) 56(84) bytes of data.
64 bytes from www.baidu.com (220.181.38.150): icmp_seq=1 ttl=52 time=34.0 ms
64 bytes from www.baidu.com (220.181.38.150): icmp_seq=2 ttl=52 time=31.9 ms
64 bytes from www.baidu.com (220.181.38.150): icmp_seq=3 ttl=52 time=43.4 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 31.917/36.479/43.458/5.014 ms
# 宿主机测试
C:\Users\ychen
λ ping 192.168.31.72
正在 Ping 192.168.31.72 具有 32 字节的数据:
来自 192.168.31.72 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.31.72 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.31.72 的回复: 字节=32 时间<1ms TTL=64
192.168.31.72 的 Ping 统计信息:
数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
# 宿主机连接
C:\Users\ychen
λ ssh -p 22 root@192.168.31.72
The authenticity of host '192.168.31.72 (192.168.31.72)' can't be established.
ECDSA key fingerprint is SHA256:cfQ0OLaacAZlnDZ+bMVxxs+T7vEIlNq8yo51HjRXRPM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.31.72' (ECDSA) to the list of known hosts.
root@192.168.31.72's password:
Last login: Fri May 3 10:19:10 2024
[root@MiWiFi-R3P-srv ~]#
设置固定ip
模式名称 | 特点 |
---|---|
网络地址转换(NAT) | 连接这个网络可以访问外部网络,但是外部网络不可访问虚拟机 |
桥接网卡 | 这个网络完全可以共享主机网络,主机网络发生变化时,也跟随变化,ip也随之变动 |
仅主机(Host-Only)网络 | 这个网络也可以用来主机访问虚拟机以及虚拟机上web服务,但是虚拟机不可访问外网 |
- 先关闭虚拟机,否则设置没有效果
- 管理,工具,网络管理器
- 点击创建新的网络后,cmd -> ipconfig,以太网会发生变化
C:\Users\ychen
λ ipconfig
Windows IP Configuration
Ethernet adapter 以太网:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter 以太网 2:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::f46c:ac6b:5390:a107%18
IPv4 Address. . . . . . . . . . . : 192.168.215.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Wireless LAN adapter 本地连接* 9:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter 本地连接* 10:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter WLAN:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::d535:a64f:ea6:410b%8
IPv4 Address. . . . . . . . . . . : 192.168.31.111
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.31.1
-
打开控制面板,以太网会发生变化
-
设置2块网卡
- 启动虚拟机
# 进入如下目录
cd /etc/sysconfig/network-scripts/
# 编辑
vi ifcfg-enp0s3
# 配置如下
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.215.5
# 重启网络
systemctl restart network
- 验证
# 查看ip
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 group default qlen 1000
link/ether 08:00:27:2e:3e:57 brd ff:ff:ff:ff:ff:ff
inet 192.168.215.5/24 brd 192.168.215.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::61e5:b3c9:7628:9097/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:db:6f:c7 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.4/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s8
valid_lft 545sec preferred_lft 545sec
inet6 fe80::e7c0:ecbd:362f:c0b0/64 scope link noprefixroute
valid_lft forever preferred_lft forever
# 测试外网
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (220.181.38.149) 56(84) bytes of data.
64 bytes from www.baidu.com (220.181.38.149): icmp_seq=1 ttl=51 time=30.0 ms
64 bytes from www.baidu.com (220.181.38.149): icmp_seq=2 ttl=51 time=43.1 ms
64 bytes from www.baidu.com (220.181.38.149): icmp_seq=3 ttl=51 time=29.7 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 29.799/34.353/43.181/6.243 ms
# 宿主机测试
C:\Users\ychen
λ ping 192.168.215.5
Pinging 192.168.215.5 with 32 bytes of data:
Reply from 192.168.215.5: bytes=32 time<1ms TTL=64
Reply from 192.168.215.5: bytes=32 time<1ms TTL=64
Reply from 192.168.215.5: bytes=32 time<1ms TTL=64
192.168.215.5 的 Ping 统计信息:
数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
Control-C
# 宿主机连接
C:\Users\ychen
λ ssh -p 22 root@192.168.215.5
The authenticity of host '192.168.215.5 (192.168.215.5)' can't be established.
ECDSA key fingerprint is SHA256:cfQ0OLaacAZlnDZ+bMVxxs+T7vEIlNq8yo51HjRXRPM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.215.5' (ECDSA) to the list of known hosts.
root@192.168.215.5's password:
Last login: Fri May 3 12:26:57 2024
[root@localhost ~]#