Solve the problem that the CentOS7 virtual machine cannot access the Internet and set up the CentOS7 virtual machine to use a static IP to access the Internet

Solve the problem that the CentOS7 virtual machine cannot access the Internet and set up the CentOS7 virtual machine to use a static IP to access the Internet

I was playing with CentOS in a VMware virtual machine recently, and after installing it I found that I couldn't access the Internet. After a lot of hard work, I finally found a solution to the problem. The final effect is that whether pinging the internal network IP or the external network IP, it can be pinged normally. Four-step method:

The first step is to go to the /etc/sysconfig/network-scripts directory and check if there is a file like ifcfg-XXX in the directory:

If you cannot see files starting with ifcfg- (except ifcfg-lo), it means that the network card device is not correctly identified. It may be that the CentOS image version you downloaded is inconsistent with the CentOS version you selected when installing CentOS. For example, the CentOS image is 64-bit, but it is installed as 32-bit. this. . Reinstall it, at least I didn't find a good way

Next, proceed to the second step:

In VMware, click "Edit" - "Virtual Network Editor" in sequence. As shown below, I chose NAT mode:

In order to use a static IP, do not check the option "Use local DHCP service to assign IP to virtual machine". Then configure the subnet IP. The subnet IP and the host IP must not be in the same address range. Otherwise, even if the virtual machine can access the Internet, the network will be slow and unstable. The IP segment of my host is 192.168.115.xxx, so I configured 192.168.10.xxx to avoid the IP segment of the host. Anyway, as long as the third digit of the IP is between 0 and 254 and not 115, it will be fine. Nat mode is equivalent to configuring a sub-router. Friends who have set up multiple levels of routing should have some experience with this. Please configure a subnet IP reasonably based on the IP of your own machine.

In this interface, click "NAT Settings" to check the gateway of the virtual machine. This gateway will be used in the third step. My gateway here is 192.168.10.2.

Step 3:

Edit the file /etc/sysconfig/network-scripts/ifcfg-eno16777736 with root privileges. The effect is as follows:

TYPE=Ethernet
BOOTPROTO=static #Set static IP
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=4f40dedc-031b-4b72-ad4d-ef4721947439
DEVICE=eno16777736
ONBOOT=yes #If it is no, change it to yes, which means the network card device will start automatically. PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no

 
GATEWAY=192.168.10.2 #The gateway address here is the gateway address obtained in the second step IPADDR=192.168.10.150 #Configure IP. In the second step, the IP has been set in the range of 192.168.10.xxx. I just set it to 150, as long as it is not the same as the gateway NETMASK=255.255.255.0 #Subnet mask DNS1=202.96.128.86 #DNS server 1, fill in the DNS server address available on your network DNS2=223.5.5.5 #DNS server 2

I have marked the key parameters with colored shading, and keep the others as default. After confirming that everything is correct, save and exit.

Step 4: Restart the network card service, execute service network restart, and then you can finally access the Internet:

Ping Baidu's domain name

Open the browser and find that the webpage opens in seconds.

Finally, I won’t post the diagram of the communication effect between the virtual machine and the intranet IP, which goes without saying. My personal expression is not very good, please bear with me, I hope it can help you.

2019/09/17 Addendum: If the host cannot ping the virtual machine, you can set the IP of the network connection VMware Virtual Ethernet Adapter for VMnet8 in the host to the same network segment as the virtual machine IP, and leave the default gateway blank:

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:
  • CentOS7 network configuration under VMware virtual machine (host wireless Internet access)
  • Solution to the problem of not being able to access the Internet when installing centos7 with VmWare
  • CentOS 7 cannot access the Internet after modifying the network card

<<:  Detailed explanation of MySQL row locks when encountering composite primary keys and multi-column indexes

>>:  Element sample code to implement dynamic table

Recommend

Django uses pillow to simply set up verification code function (python)

1. Import the module and define a validation stat...

HTML Basics: HTML Content Details

Let's start with the body: When viewing a web ...

Hello dialog box design experience sharing

"What's wrong?" Unless you are accus...

In-depth understanding of mathematical expressions in CSS calc()

The mathematical expression calc() is a function ...

Detailed tutorial on installing Docker on Windows

Since my local MySQL version is relatively low, I...

Tutorial on installing MySQL with Docker and implementing remote connection

Pull the image docker pull mysql View the complet...

Vue + element dynamic multiple headers and dynamic slots

Table of contents 1. Demand 2. Effect 3. All code...

Summary of Docker common commands and tips

Installation Script Ubuntu / CentOS There seems t...

js learning notes: class, super and extends keywords

Table of contents Preface 1. Create objects befor...

Share the pitfalls of MySQL's current_timestamp and their solutions

Table of contents MySQL's current_timestamp p...

Good website copywriting and good user experience

Looking at a website is actually like evaluating a...

Methods of adaptive web design (good access experience on mobile phones)

1. Add the viewport tag to the HTML header. At th...

Set an icon for the website to be displayed on the far left of the browser tab

What is the purpose of this sentence? Copy code Th...

Briefly talk about mysql left join inner join

Preface I have been busy developing a cold chain ...