Linux---Virtual machine configuration fixed IP

1. IP address

Every computer connected to the Internet will have an address that is used to communicate with other computers.

There are two main versions of IP addresses , V4 version and V6 version ( V6 is rarely used and will not be covered in the course)

The address format of the IPv4 version is: abcd , where abcd represents a number from 0 to 255 , such as 192.168.88.101 is a standard

IP address.

You can use the command: ifconfig to check the IP address of this machine .

If you cannot use the ifconfig command, you can install it: yum -y install net-tools.

In addition to standard IP addresses, there are several special IP addresses:

127.0.0.1, this IP address is used to refer to this machine;

0.0.0.0, a special IP address, can be used to refer to the local machine. It can be used to determine the binding relationship in port binding. It is also used in some IP addresses .

In the restriction, it means all IPs . For example, if the release rule is set to 0.0.0.0 , it means that access from any IP is allowed .

2. Host name

In addition to its external contact address ( IP address), each computer can also have a name, which is called a host name.

Whether it is a Windows or Linux system, you can set the host name for the system.

You can use the command: hostname  to view the host name

You can use the command: hostnamectl set-hostname hostname to modify the hostname ( root required )

Log in to FinalShell again and you will see that the host name is displayed correctly.

3. Domain name resolution

The IP address of the corresponding computer can be found through the host name , which is host name mapping (domain name resolution).

For example, visit www.baidu.com:

First check the records of this machine (private address book);

Windows view: C:\Windows\System32\drivers\etc\hosts

Linux view:/etc/hosts

Then go online and ask the DNS server (such as 114.114.114.114 , 8.8.8.8, etc.);

Configure hostname mapping:

Configure records in the Windows system: C:\Windows\System32\drivers\etc \hosts file.

 

4. Configure a fixed IP for the virtual machine 

The Linux operating system of the virtual machine has its IP address obtained through the DHCP service.

DHCP : Obtain the IP address dynamically, that is, it will be obtained every time the device is restarted, which may cause the IP address to change frequently.

Reasons for fixed IP addresses:

When connecting to a Linux system remotely, if the IP address changes frequently, it will be troublesome to frequently modify the adaptation;

After configuring the mapping between the virtual machine IP address and the host name, if the IP changes frequently, the mapping relationship needs to be updated frequently.

Steps to configure fixed IP in VMware Workstation :

①: Configure the IP address gateway and network segment ( range of IP addresses) in VMware Workstation (or Fusion )

②: Modify fixed IP in Linux system 

Use vim to edit the / etc / sysconfig /network-scripts/ifcfg-ens33 file and fill in the following content

Execute: systemctl restart network to restart the network card. Ifconfig is executed , you can see that the IP address is fixed at 192.168.88.130.

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_43961909/article/details/131219913