[Software installation] VMware installs the Centos7 virtual machine and sets a static IP to enable Windows and Centos7 networks to access each other.

This article mainly introduces how VMware installs a Centos7 virtual machine and sets a static IP to enable Windows and Centos7 networks to access each other.

Table of contents

1. Install Centos7 on VMware

1.1. Download Centos7 image

1.2. Install Centos7 system

2. Set a static IP address

2.1. Check the virtual machine network IP

2.2. Disable NetworkManager service

2.3. Modify ens33 network card information

2.4. Restart the ens33 network card

2.5. Is the network available?

2.6. Network communication between Windows and Centos7

(1) Windows access Centos7 network

(2) Centos network access Windows

2.7. SSH to connect to the virtual machine

(1) Check whether the SSH service has been installed

(2) Configure SSH information

(3) Restart the SSH service

(4) Turn off the firewall

(5) Connect to Centos7 system through SSH

3. Error reporting issues

3.1. Restart the network card and report an error

(1) Restart the network card and report an error

(2) Solution

3.2. The network card restarts successfully, but displays DOWN status.

(1) The network card is in DOWN state

(2) Solution

3.3. Error when CMD connects to SSH

(1) Error reported when cmd accesses ssh

(2) Solution


1. Install Centos7 on VMware

1.1. Download Centos7 image

First you need to download the VMware virtual machine software. You can go to the official website to download [Download VMware Workstation Pro]. The VMware Workstation16 version I use. Then you need to download the Centos7 system image, download address [http://mirror.nsc.liu.se/centos-store/7.8.2003/isos/x86_64/], as shown below:

After the VMware download is completed, install it in a fool-proof manner, and then install the Centos7 system.

1.2. Install Centos7 system

Select [New Virtual Machine] under [File], as shown below:

Select [Typical] and click Next.

Select to install the operating system later and click Next.

Select the Linux system type and click Next.

Fill in the virtual machine name, installation location, and click Next.

Select the disk space size according to your needs.

Click the [Customize Hardware] button.

Select the Centos7 system image you just downloaded, and select NAT mode for the network adapter.

Click [Close], and then click [Finish]. At this time, the new virtual machine of Centos7 is complete, as shown below.

Then start the Centos7 system and start the formal installation.

Select the second one and press Enter to enter the next interface.

After some time, you can start choosing fonts.

Then enter the next interface, as shown below:

Just select Shanghai time zone.

Then select the system installation location.

What I chose here is automatic partitioning.

At this point, you can click [Start Installation].

Then during the installation process, you can set a user password.

Enter the password of the root user and remember it yourself.

Finally, just wait until the installation is completed. After the installation is complete, click Restart.

After restarting, enter the Centos7 system terminal interface and enter the root user and password, as shown below:

The installation of the Centos7 system is now complete.Now let’s set the static IP of the Centos7 system.

2. Set a static IP address

2.1. Check the virtual machine network IP

In the VMware interface toolbar, select [Virtual Network Editor] under [Edit].

Wait for a while, it will be a little slow, and a window will pop up after a while.

Click [Change Settings] to enter the editing state, as shown below:

What needs to be modified: Check NAT mode, uncheck DHCP, remember the subnet IP address and subnet mask. Then click [NAT Settings], and a window will pop up, as shown below:

Click [OK], close the pop-up box, then click [Apply], and click [OK].

2.2. Disable NetworkManager service

Start the Centos7 system, enter the terminal interface, and first close the NetworkManager service. Because this NetworkManager service will conflict with network.service, causing the network card to be unavailable, you need to disable the NetworkManager service.

# 禁用NetworkManager服务
systemctl disable NetworkManager

The execution result is as follows:

Then stop the NetworkManager service and execute the command:

# 停止服务
systemctl stop NetworkManager
# 查看服务状态
systemctl status NetworkManager
# 设置开机不自动启动
chkconfig NetworkManager off

The execution result is as follows:

At this point, the NetworkManager service has been successfully disabled. Let’s start modifying the ens33 network card information.

2.3. Modify ens33 network card information

Enter the /etc/sysconfig/network-scripts directory and execute [vi ifcfg-ens33] to edit the ifcfg-ens33 file.

# 进入目录
cd /etc/sysconfig/network-scripts
# 编辑配置文件
vi ifcfg-ens33

As shown below:

In the ifcfg-ens33 configuration file, the following content needs to be added and modified:

Note: The IPADDR in the configuration file is the subnet IP address seen earlier. You can define the last digit yourself. I defined 100 here, which means that the IP address of my Centos virtual machine is 192.168. 17.100. The subnet mask and gateway IP address are consistent with those seen previously. After the modification is completed, press the ESC button, then enter [:] colon, and enter [wq] to save.

2.4. Restart the ens33 network card

Execute the command[service network restart]Restart the network card service, and then you can use [ip addr]Check the network card status.

2.5. Is the network available?

After the network card starts normally, you can test whether the Centos7 virtual machine system can access the network. Use[ping www.baidu.com]Command to check whether the Baidu address can be pinged normally. If the situation in the picture below appears, it means that the network can be accessed normally.

2.6. Network communication between Windows and Centos7

(1) Windows access Centos7 network

On our own Windows system, open the CMD command line window and use the ping command to access the IP address in the virtual machine Centos7 to check whether it can be accessed normally.

If the above situation occurs, it means that normal access is possible.

(2) Centos network access Windows

Then in the Centos virtual machine, use the ping command to access the IP address of the external host. The IP address of the external host can be viewed by opening the CMD window and entering [ipconfig].

Then in the Centos7 system, execute [ping 192.168.1.4] to check the results.

The above results show that the Centos7 virtual machine system and the external host network are interconnected.

2.7. SSH to connect to the virtual machine

In order to use SSH to connect to the Centos7 virtual machine system, you need to install and configure the SSH service. What I installed here is openssh-server.

(1) Check whether the SSH service has been installed

执行【rpm -qa | grep ssh】Instruction.

# 查看是否安装ssh服务
rpm -qa | grep ssh

After executing the above command, you can check which ssh services are installed. The results are as follows:

This means that I have installed the openssh-server service, so there is no need to install it. If you have not installed it, you can execute the following command:

# 安装openssh-server服务
yum install -y openssh-server

(2) Configure SSH information

Enter the [/etc/ssh/] directory, and then edit the [sshd_config] configuration file.

# 进入ssh目录
cd /etc/ssh/
# 修改ssh配置文件
vi sshd_config

As shown below:

The information that needs to be configured is as follows:

Basically just modify the above two information.

(3) Restart the SSH service

Execute the following command to restart the SSH service.

# 重启ssh服务
service sshd restart

As shown below:

(4) Turn off the firewall

If you cannot connect to the SSH service remotely, it is possible that the firewall is enabled in the Centos7 system, so you need to turn off the firewall or open port 22.

# 开放22端口
sudo firewall-cmd --zone=public --add-port=22/tcp --permanent
# 重启防火墙
sudo service firewalld restart  

# 关闭防火墙
systemctl stop firewalld

#禁用防火墙
systemctl disable firewalld

The execution command is shown in the figure below:

(5) Connect to Centos7 system through SSH

The MobaXterm software I use here connects to the Centos7 virtual machine through SSH.

At this point, SSH connection to the Centos7 virtual machine is successful.

3. Error reporting issues

3.1. Restart the network card and report an error

(1) Restart the network card and report an error

When executing[service network restart] when restarting the ens33 network card, the following error message appears:

Specific error log information:

# service network restart
Restarting network (via sustemctl):Job for network.service failed because the control process
exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
[FAILED]

You can't tell what the specific cause is from this log. You can execute the [journalctl -xe] command to see the specific error message. For example: My error message is that the host has been used.

The reason this occurs is that the virtual network I configured is occupied by other virtual machines, because I have created other virtual machines before ( If you installed it for the first time , this problem will not occur).

(2) Solution

To solve the above problem, you can restore the default settings of the virtual machine network directly in the virtual network editor. Note: You must first shut down the running virtual machine.

After restoration, you need to recheck the IP address information of the virtual network. For details, check the second step [Set a static IP address].

3.2. The network card restarts successfully, but displays DOWN status.

(1) The network card is in DOWN state

When the network card is restarted successfully, but when using [ip addr] to check the network card status, it is found that the network card is in the DOWN state, that is, it has not started successfully, as shown in the following figure:

Specific error log information:

[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER UP> mtu 65536 qdisc noqueue state UNKNON group default qlen 1008ink/loopback 88:08:9:9:00: brd 0g:00:00:08:0:00inet 12?.日.日.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid lft forever preferred lft forever
2: ens33: <NO-CARRIER,BRDADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether gg:c:29:9e:81:52 brd ff:ff:ff:ff:ff:ffinet 192.168.1?.100/24 brd 192.168.1?.255 scope global ens33valid lft forever preferred lft forever

(2) Solution

The reason for the above problem is that the VMware NAT Service in Windows has not been started. This NAT server needs to be started so that the network card in the virtual machine can be used normally.

After starting the NAT service, use the [ip addr] command again to check the network card status.

3.3. Error when CMD connects to SSH

(1) Error reported when cmd accesses ssh

In the CMD command line window of Windows system, you can also use the ssh command to connect to the remote SSH service. The format is:

# 连接ssh服务
ssh 用户名称@IP地址

# 举例
ssh [email protected]

If you execute the above command, the following error will be reported:

C:\Users\zhuyb>ssh [email protected]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ED25519 key sent by the remote host is
SHA256:kVNdSdR9ZfJvTV/hRPyOqBda3heZtklQ2JkngtzbaM4.
Please contact your system administrator.
Add correct host key in C:\\Users\\zhuyb/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in C:\\Users\\zhuyb/.ssh/known_hosts:5
Host key for 192.168.17.100 has changed and you have requested strict checking.
Host key verification failed.

(2) Solution

To solve the above error problem, just execute the following command:

ssh-keygen -R 你要访问的IP地址

# 举例
ssh-keygen -R 192.168.17.100

After executing the command, it looks like this:

At this point, installing the Centos virtual machine and configuring the network are complete.

In summary, this article is over. It mainly introduces VMware to install Centos7 virtual machine and set a static IP to realize mutual access between Windows and Centos7 networks.

Guess you like

Origin blog.csdn.net/qq_39826207/article/details/134887453