How to set a fixed IP address in CentOS7 virtual machine

How to set a fixed IP address in CentOS7 virtual machine

Since my development environment is to install CentOS in a VMWare virtual machine, and then set up interception in the host file, I can directly jump to the CentOS of the virtual machine, but the IP address of the virtual machine will always change, so I have to modify the host file at any time, which is very troublesome. I decided to use a fixed IP for the virtual machine and recorded the steps for future reference. I hope it can help other friends.

Environment: Host is Windows 10 VMWare 12 Centos 7.5

1. Set up the network connection mode of the virtual machine

Click on the virtual machine name -> right click -> settings

Modify the network adapter. The network connection mode can be selected as "NAT mode" or "Custom"

2. Edit->Virtual Network Editor

Select VMNet8 and click "Change Settings"

Uncheck "Use local DHCP service to assign IP addresses to virtual machines" Set the subnet IP segment and subnet mask. Try to make the subnet IP segment different from the host IP segment.

Click "NAT Settings"

Set the gateway. It cannot be the same as the IP address of the virtual machine. Remember this gateway, which will be used in the third step. It corresponds to GATEWAY

3. Modify the CentOS configuration file in the virtual machine

cd /etc/sysconfig/network-scripts Enter the configuration directory

Modify the configuration file vim ifcfg-eno16777736 [the system is different, the name of the network card is also different]

BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.8.123 #The IP segment to be set is the same as NETMASK=255.255.255.0
GATEWAY=192.168.8.2 #Needs to be consistent with the gateway set by the virtual network card in the second step DNS1=8.8.8.8 #This must be set, otherwise it will result in being able to ping the external IP but not the domain name

After the modification is completed, save and exit.

Restart network services

systemctl restart network.service 

Check that the IP address is the IP address you want to set

Ping www.baidu.com can access the external network

Let's expand here and save some exit commands:

:w save the file but do not exit vi
:w file Save the changes to file without exiting vi
:w! Force save, do not exit vi
:wq save the file and exit vi
:wq! Force save the file and exit vi
q: Exit vi without saving the file
:q! Do not save the file and force exit vi
:e! Abandon all changes and start editing from the last time the file was saved

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to build Jenkins+Maven+Git continuous integration environment on CentOS7
  • Install centos7 virtual machine on win10
  • Centos7 installation of Nginx integrated Lua sample code
  • How to use yum to configure lnmp environment in CentOS7.6 system
  • MySQL 8.0.13 installation and configuration tutorial under CentOS7.3
  • Rsync+crontab regular synchronization backup under centos7
  • Solve the problem of regular automatic file deletion by crontab+shell script under Centos7
  • Compile and install php7 on centos7 to connect to apache in php-fpm mode
  • Detailed tutorial on installing mysql 8.0.13 (rpm) on Centos7
  • Three methods to modify the hostname of Centos7

<<:  Detailed explanation of Vue configuration request multiple server solutions

>>:  Quickly install MySQL5.7 compressed package on Windows

Recommend

Steps to build a file server using Apache under Linux

1. About the file server In a project, if you wan...

Solution to transparent font problem after turning on ClearType in IE

The solution to the transparent font problem after...

How can MySQL effectively prevent database deletion and running away?

Table of contents Safe Mode Settings test 1. Upda...

MySQL database operation and maintenance data recovery method

The previous three articles introduced common bac...

How to use time as a judgment condition in MySQL

Background: During the development process, we of...

Mysql 5.7.18 Using MySQL proxies_priv to implement similar user group management

Use MySQL proxies_priv (simulated role) to implem...

Solution to 1449 and 1045 exceptions when connecting to MySQL

Solution to 1449 and 1045 exceptions when connect...

Steps to install MySQL 5.7 in binary mode and optimize the system under Linux

This article mainly introduces the installation/st...

How to implement the singleton pattern in Javascript

Table of contents Overview Code Implementation Si...

Solution to the problem that the mysql8.0.11 client cannot log in

This article shares with you the solution to the ...

Two ways to clear table data in MySQL and their differences

There are two ways to delete data in MySQL: Trunc...

How to use CSS to display multiple images horizontally in the center

Let me first talk about the implementation steps:...

Alibaba Cloud Server Ubuntu Configuration Tutorial

Since Alibaba Cloud's import of custom Ubuntu...

In-depth explanation of JavaScript this keyword

Table of contents 1. Introduction 2. Understand t...