[Virtual machine construction - VMware setting fixed IP] How to set a fixed IP for CentOS in VMWare [unsuccessful hand-in-hand teaching]

1. Background

  • In daily work and study (for example, when a blogger was learning k8s before, windows built a virtual machine locally and restarted windows)
  • The IP of the virtual machine will change, so this article records in detail how to set a fixed IP for CentOS in VMWare
    insert image description here

2. Virtual machine installation

3. Windows configuration

3.1, virtual network card configuration

  • After VMWare is successfully installed, two virtual networks will be added at the network connection
    insert image description here
  • Because the NAT mode needs to use the host's VMnet8 network card to communicate between the virtual machine and the host, we need to find the VMnet8 network card on the host first
  • Find the IPv4 protocol and select Obtain an IP address automatically
    insert image description here

3.2. VMware's NAT and DHCP are automatically enabled

  • Click My Computer, click Manage, find Services and Applications
    insert image description here

4. VMWare network introduction

insert image description here

4.1, bridge mode (Bridged)

  • It is directly connected to the network through the host network card, assuming a bridge. Therefore, it enables the virtual machine to be assigned an independent IP in the network, and all network functions are exactly the same as the real machine in the network.
  • For a virtual machine in bridge mode, we just think of it as a real computer.
    insert image description here

4.2, NAT mode

  • NAT: Network Address Translation, network address translation
  • NAT mode is the easiest way to realize virtual machine Internet access
  • All the data that the Guest accesses the network is provided by the host, the Guest does not really exist in the network, and any machine in the host and the network cannot view and access the existence of the Guest
  • The Guest can access all the networks that the host can access, but the Guest is invisible to the host and other machines on the host network, and even the host cannot access the Guest

In NAT mode, the virtual machine network is connected to the VMnet8 of the host machine. At this time, the VMWare NAT Service server of the system acts as a router, responsible for converting the address of the packet sent by the virtual machine to VMnet8, and then sending it to the actual network. , and then send the packet returned on the actual network to the virtual machine through VMnet8 after address translation. VMware DHCP Service is responsible for providing DHCP services for virtual machines.

In NAT mode, the network card of the virtual machine is connected to the network card of VMnet8 of the host machine. When VMnet8 receives the data packet sent by the virtual machine, it will forward the data packet to the network card of the physical machine. It is equivalent to that the physical network card cannot directly contact the data packets of the virtual machine, but contacts VMnet8 for processing. In fact, VMnet8 is in NAT mode, with its own DHCP function, which can assign IP addresses to virtual machines.

insert image description here

4.3, host mode (Host-only Adapter)

  • This is a relatively complex mode that requires a relatively solid basic knowledge of the network to play. It can be said that the functions realized by the previous modes can be realized through the settings of the virtual machine and the network card in this mode [Let’s find out more].

5. Why use NAT mode

  • The configuration of the bridge mode is very simple, but if the network environment ip resources are scarce, or the ip management is strict, then the bridge mode is not applicable [the development computer is completely enough, don’t worry], because we can understand through the above Know that the bridge mode is to create a network environment at the same level as the host machine, which is the real IP address in the network address.

  • If we want the virtual machine to go online without occupying the real IP address, then we need to use the NAT mode is the best choice. The NAT mode uses the virtual NAT device and the virtual DHCP server to enable the virtual machine to be connected to the Internet.
    insert image description here

  • In NAT mode, the host network card is directly connected to the virtual NAT device, and then the virtual NAT device and the virtual DHCP server are connected to the virtual machine switch VMnet8, thus realizing the virtual machine networking.

6. VMware sets a fixed IP

6.1, VMware network configuration

  • Click Edit -> Virtual Network Editor
    insert image description here
  • Click to restore the default configuration to prevent accidents
    insert image description here
    insert image description here
    insert image description here
  • Select the following configuration
    insert image description here
  • NAT settings [ remember the gateway IP (192.168.165.2) ], which will be used later
    insert image description here
  • DHCP settings, IP intervals are automatically obtained
    insert image description here
  • Here we can see our starting ip address and ending ip address, that is, when we set a fixed ip address later, it must be within this range

6.2. Virtual machine configuration

  • set NAT mode
    insert image description here
  • After entering the virtual machine, view the default IP address
    insert image description here
  • Make sure you can connect to the Internet, and you can access Baidu normally, which means that the network is connected.
    insert image description here
  • View the existing ens33 network configuration by command
cat /etc/sysconfig/network-scripts/ifcfg-ens33
  • Add the following content after the file
#设置静态模式
BOOTPROTO=static
ONBOOT=yes
#ip地址【DHCP中的范围内的】
IPADDR=192.168.165.130
#子网掩码
NETMASK=255.255.255.0
#网关【刚刚我们在NAT设置中配置的网关IP】
GATEWAY=192.168.165.2
DNS1=223.5.5.5

insert image description here

  • Execute the command to restart the network card:service network restart
    insert image description here
  • Check the existing IP again and determine whether it can pass through the external network
    insert image description here
  • Determine whether the network is normal through the host
    insert image description here

7. End

If you need help in the construction, you can also private message me, if you are unsuccessful, you will teach.

Guess you like

Origin blog.csdn.net/u010800804/article/details/131386338