Detailed steps to configure a static IP for a Linux virtual machine in VMware (CentOs 7)

illustrate:

        The static IP configuration here is based on a Linux virtual machine connected to the network using NAT.

Step 1: Configure the ip of the Linux virtual machine and the windows host under a network segment:

  1. View the network segment where the ip assigned by VMware to the Linux virtual machine is located:
    (1) Right-click the [Edit] menu bar in VMware, open the [Virtual Network Editor], select [VMnet8], and click [NAT Settings];
    insert image description here
    (2) ) to view the network segment where the virtual machine's IP is assigned by default in VMware's virtual network configuration. Here you can see that the subnet IP in the NAT settings in my VMware is 192.168.145.0, and the decimal number in the third position here represents the network segment, so the ip assigned by my VMware to the Linux virtual machine is on the network 145 (
    insert image description here
    3) Supplementary instructions: The above two small steps only check the network segment where the ip assigned by VMware to the Linux virtual machine is located. You can also change the default network segment to another network segment. For example, it is seen above that the IP assigned to my virtual machine is on the 145 network segment, I can also modify it to the 143 network segment, the operation is as follows:
  1. Right-click the [Edit] menu bar in VMware, open the [Virtual Network Editor], then select [VMnet8], and then edit the subnet IP, just change [192.168.145.0] to [192.168.143.0], and then click [ OK]. In this way, the network segment of the IP allocated by VMware to the Linux virtual machine will become 143, that is, the IP allocated to the virtual machine will be in the range of 192.168.143.0 ~ 192.168.143.255.
    insert image description here
  1. Check the network segment of the IP configured in the [VMnet8] virtual network in Windows:
    (1) Click the [Windows key] in the window, search for [Network Status] and open it;
    insert image description here
    (2) Open [Change Adapter] in [Ethernet] Options]; insert image description here(3) Right-click [VMnet8], select View [Properties];
    insert image description here(4) Select [Internet Protocol Version 4 (TCP/IPv4)], and then click [Properties] to view the ip configuration;
    insert image description here
    (5) Check first 【Use the following IP address】, and then configure the IP. Because the Linux virtual machine and the Windows host need to communicate with each other without going through a gateway, the IP address configured here and the IP address of the virtual machine must be in the same network segment. And I have seen above that my virtual machine is on the 145 network segment, so the ip here should also be on the 145 network segment, that is, the IP here can be configured as (192.168.145.0, 192.168.145.255) any of the open range. An IP, I configured here is 192.168.145.1; then the subnet mask should be consistent with the subnet mask in the virtual machine; because the IP of the virtual machine and the window host are configured on the same network segment, communication does not need to go through Gateway, so the gateway here can be temporarily not configured. After the configuration is complete, click [OK];
    insert image description here

Step 2: Configure a static IP for the Linux virtual machine:

  1. Enter the command: [vim /etc/sysconfig/network-scripts/ifcfg-ens33], edit the configuration file;
  2. Then to add the following in the configuration file:
    insert image description here

Among them :

  1. IPADDR: Indicates the static IP you configured. Above, we have checked the network segment where the IP that VMware gave the virtual machine is located, and also configured the virtual network ip in the windows host on this network segment, so the static IP configured for the Linux virtual machine here is also on this network. part. For example, the network segment where my VMware IP is assigned is 145, so the static IP I configure for the Linux virtual machine here is also on the network segment 145, and the IP range of a network segment is 0~255, so here I specify the IP The value is: 192.168.145.0 ~ 192.168.145.255.
  2. GATEWAY: Indicates the configured gateway. Because the virtual machine needs to communicate with the perimeter, it needs to be configured, and this value is the gateway IP in the virtual network configuration of VMware viewed above.
    insert image description here
  3. DNS1: The value of DNS can also be configured to be the same as the value of GATEWAY.
  4. ONBOOT: The value of this property should be changed to yes.
  5. BOOTPROTO: The value of this property should be changed to static, indicating that static IP is enabled.
  1. Then save and exit: [:wq];

  2. Restart the network card: [service network restart];

  3. Check ip again: [ifconfig], you can see that the ip of the virtual machine is already the ip you configured. You can see that my IP is already 192.168.145.10;
    insert image description here

  4. The Linux virtual machine can successfully access Baidu on the external network: [ping www.baidu.com];
    insert image description here

  5. The Windows host can successfully connect to the virtual machine: Open the cmd window in Windows and enter the command [ping 192.168.145.10]; insert image description herenote that if it is unsuccessful, check whether the firewall of the virtual machine is turned off. If it is not closed, execute the command [systemctl stop firewalld] to close the firewall.

  6. The Linux virtual machine successfully connects to the Windows host;
    insert image description here
    note that if it is unsuccessful, you can first check whether the firewall of the Windows host is turned off. You can check if the firewall is turned off, or turn off the firewall by following the steps below:

  1. Press the [windows key] in Windows, and then search for [Firewall Status];
    insert image description here

  2. Open [Check Firewall Status], you can see that the firewall is on;
    insert image description here

  3. Click [Turn Windows Defender Firewall on or off];
    insert image description here

  4. Then check [Turn off Windows Defender Firewall] and click [OK];
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_55118477/article/details/121272999